1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[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
This commit is contained in:
tolk-vm 2024-12-16 21:19:45 +03:00
parent ea0dc16163
commit 3540424aa1
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
71 changed files with 4270 additions and 3060 deletions

View file

@ -118,12 +118,19 @@ fun updateTwoItems(mutate self: (int, int), byValue: int) {
self = (first + byValue, second + byValue);
}
global t107_1: int;
global t107_2: int;
@method_id(107)
fun testMutableTensor() {
var t = (40, 50);
t.updateTwoItems(10);
updateTwoItems(mutate t, 10);
return t;
t107_1 = 1;
t107_2 = 2;
(t107_1, t107_2).updateTwoItems(10);
updateTwoItems(mutate (t107_1, t107_2), 10);
return (t, t107_1, t107_2);
}
@pure
@ -278,7 +285,7 @@ fun main(){}
@testcase | 104 | | 1 2 3
@testcase | 105 | | 5 5 110
@testcase | 106 | | 160 110
@testcase | 107 | | 60 70
@testcase | 107 | | 60 70 21 22
@testcase | 110 | | 320
@testcase | 111 | | 55 55
@testcase | 112 | | [ 1 13 3 23 33 ]
@ -300,7 +307,7 @@ fun main(){}
...
incrementTwoInPlace CALLDICT // x y sum1
-ROT
10 PUSHINT // sum1 x y _9=10
10 PUSHINT // sum1 x y _8=10
incrementTwoInPlace CALLDICT // sum1 x y sum2
s1 s3 s0 XCHG3 // x y sum1 sum2
}>
@ -310,8 +317,8 @@ fun main(){}
"""
load_next PROC:<{
// cs
32 LDI // _1 cs
SWAP // cs _1
32 LDI // _3 cs
SWAP // cs _3
}>
"""
@ -319,7 +326,7 @@ fun main(){}
"""
testStoreUintPureUnusedResult PROC:<{
//
0 PUSHINT // _12=0
0 PUSHINT // _11=0
}>
"""
@ -330,7 +337,7 @@ fun main(){}
NEWC // b
STIX // _2
DROP //
0 PUSHINT // _12=0
0 PUSHINT // _11=0
}>
"""