comptime: compile-time evaluation (Zig-style)
`comptime "<source>"` runs catscript inside the compiler, in an embedded
VM created lazily and shared for the whole compilation:
- expression position: the result value is baked into the program as a
constant (`local x = comptime "return 6 * 7"` -> x is 42).
- statement position: runs for side effects (compile-time globals) and
the value is discarded.
- errors raised at compile time surface as normal compile errors
("line N: comptime: boom").
- the embedded VM is freed at the end of compilation.
This reuses the existing interpreter, which is why it is cheap: the
language already has a VM to embed. tests/comptime.cat + suite block.
Suite 141 -> 144.
This commit is contained in:
1 parent
96e8f516cc
commit
95f3823acf
5 files changed
+100
-1
No files matched your search
@@ -30,6 +30,7 @@ enum CAT_LEXER_Kind {
|
||||
CAT_LEXER_TOK_RAISE, CAT_LEXER_TOK_USE, CAT_LEXER_TOK_CLASS,
|
||||
CAT_LEXER_TOK_EXTENDS, CAT_LEXER_TOK_INTERFACE, CAT_LEXER_TOK_IMPLEMENTS,
|
||||
CAT_LEXER_TOK_IS,
|
||||
CAT_LEXER_TOK_COMPTIME,
|
||||
/* symbols */
|
||||
CAT_LEXER_TOK_PLUS, CAT_LEXER_TOK_MINUS, CAT_LEXER_TOK_STAR,
|
||||
CAT_LEXER_TOK_SLASH, CAT_LEXER_TOK_PERCENT, CAT_LEXER_TOK_CARET,
|
||||
|
||||
Reference in new issue
Block a user