Johan-Mi / scratch-compiler-2

Yet another language that compiles to Scratch
The Unlicense
2 stars 0 forks source link

THIR to support metaprogramming #10

Open Johan-Mi opened 4 months ago

Johan-Mi commented 4 months ago

I'd like this language to support metaprogramming. That requires compile-time function calls. Currently, this cannot be implemented since we cannot call a function before evaluating its signature, which uses the same compile-time evaluation machinery. The solution is to introduce a Typed High-level Intermediate Representation. The regular HIR would then contain unevaluated function signatures, which would be evaluated as part of the conversion to THIR. This could be done with a depth-first search, so a function signature containing a call would cause the signature of the called function to be evaluated first.

I suspect we would also need to make type-checking and semantic analysis more fine-grained and create a THIR interpreter.

Johan-Mi commented 4 months ago

My work on #11 has unintentionally led to progress on this; we now have access to the ty::Context in more places and type-check function parameter/return types properly.

Johan-Mi commented 3 months ago

I've started implementing THIR but it doesn't do much yet; I'll have to integrate type-checking into it somehow.

Johan-Mi commented 3 months ago

The depth-first search will have to involve global variables as well as functions, see #15.