2024-10-31 07:18:54 +00:00
|
|
|
const op_increase = 0x123;
|
|
|
|
|
|
|
|
fun inc(mutate x: int): int {
|
|
|
|
x += 10;
|
|
|
|
return x + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fun cantCallMutatingFunctionWithImmutable() {
|
|
|
|
return inc(mutate op_increase);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@compilation_should_fail
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
@stderr modifying immutable constant
|
2024-10-31 07:18:54 +00:00
|
|
|
@stderr inc(mutate op_increase)
|
|
|
|
*/
|