Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
alcinnz
alcinnz
@alcinnz@floss.social  ·  activity timestamp 2 hours ago

The Hare programming language has several syntactic constructs we can lower at compiletime once we've resolved the declared types. So how might our string-centric CPU do so?

For starters the `defer` statement should enqueue their expressions into a block to be pasted immediately before any exits from the current block, since computers are a lot better at remembering to do these things than humans!

Also the `?` or `!` postfix operators branches on the operand to see if its an error.

1/3?

  • Copy link
  • Flag this post
  • Block
alcinnz
alcinnz
@alcinnz@floss.social replied  ·  activity timestamp 2 hours ago

Hare distinguishes error types using a `!`, so it can offer those valuable operators.

Talking about types, array indexing & union/struct properties can be lowered to pointer arithmetic. Once we've computed type sizes & (via a running sum) offsets for each struct property, with caching to aid computing this in the correct order.

In this hypothetical I'd output constant expressions.

Some builtin functions would compile to this computed data, though these builtins deserve their own thread!

2/3!

  • Copy link
  • Flag this comment
  • Block
alcinnz
alcinnz
@alcinnz@floss.social replied  ·  activity timestamp 2 hours ago

Finally upon comparing strings we should synthesize calls to a `strcmp` runtime function, so it compare the integral result to 0.

And at some point in this compilation I'd want to inline simpler functions so our microcontroller APIs can be optimized to single opcodes.

All of this should be doable by our hypothetical Parsing & Output Units, though the results would require a later constant folding optimization.

3/3 Fin for today!

  • Copy link
  • Flag this comment
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-alpha.40 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct