mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] v0.6 syntax: fun
, import
, var
, types on the right, etc.
Lots of changes, actually. Most noticeable are: - traditional //comments - #include -> import - a rule "import what you use" - ~ found -> !found (for -1/0) - null() -> null - is_null?(v) -> v == null - throw is a keyword - catch with swapped arguments - throw_if, throw_unless -> assert - do until -> do while - elseif -> else if - drop ifnot, elseifnot - drop rarely used operators A testing framework also appears here. All tests existed earlier, but due to significant syntax changes, their history is useless.
This commit is contained in:
parent
5a3e3595d6
commit
e2edadba92
133 changed files with 8196 additions and 2605 deletions
117
tolk-tester/tests/no-spaces.tolk
Normal file
117
tolk-tester/tests/no-spaces.tolk
Normal file
|
@ -0,0 +1,117 @@
|
|||
const int10:int=10;
|
||||
|
||||
fun just10(): int { return int10; }
|
||||
fun eq(v: int): int { return`v`; }
|
||||
|
||||
@method_id(101) fun `get_-1` (): int {return-1;}
|
||||
@method_id(102) fun `get_--1` (): int {return--1;}
|
||||
@method_id(103) fun `get_---1`(): int {return---1;}
|
||||
@method_id(104) fun `get_+++1`(): int {return+++1;}
|
||||
@method_id(105) fun `get_+-+1`(): int {return+-+1;}
|
||||
|
||||
global `some()var`:int;
|
||||
|
||||
@method_id(110) fun `some_math`(): int {
|
||||
`some()var`=--6;
|
||||
return 1*-2*-3*-4*just10()*-5+-`some()var`+--`some()var`---`some()var`;
|
||||
}
|
||||
|
||||
@method_id(111) fun `negative_nums`(a:int):int {
|
||||
var m$0:int=1;
|
||||
var m1:int=-(+0x1)*m$0;
|
||||
return `a`*-1*-(1)*---(1)*+just10()+-`just10`()*m1*-m1+-eq(m1)----0x1;
|
||||
}
|
||||
|
||||
@method_id(112) fun `bitwise~ops`(flags:int):[int,int] {
|
||||
return[
|
||||
(just10()-3==just10()-(4)--1)|((2==2)&(eq(eq(10)) -3==just10()--13)),
|
||||
((flags&0xFF)!=0)
|
||||
];
|
||||
}
|
||||
|
||||
@method_id(113)fun`unary+bitwise-constant`():[int,int,int]{
|
||||
// todo spaces are still not allowed before ~
|
||||
return [~-~~+-3, ~+3-~ 9, -(-~+-20-~ 10+3+~ 38&39)];
|
||||
}
|
||||
|
||||
@method_id(114)fun`unary+bitwize-parametrized`(c3:int, c9:int, c20:int, c10:int, c38:int):[int,int,int]{
|
||||
// todo spaces are still not allowed before ~
|
||||
return [~-~~+-c3, ~+c3-~ `c9`, -(-~+-c20-~ c10+c3+~ c38&39)];
|
||||
}
|
||||
|
||||
fun add3(a: int, b: int, c: int) { return a+b+c; }
|
||||
|
||||
@method_id(115) fun unary_const_check(): [int,int] {
|
||||
var fst1: int=-1;
|
||||
var snd1: int=-1;
|
||||
var trd1: int=+2;
|
||||
var (fst2,snd2,trd2)=(-1,-1,+2);
|
||||
return [add3(fst2,snd2,trd2),add3(fst1,snd1,trd1)];
|
||||
}
|
||||
|
||||
fun `load:u32`(cs: slice): (slice, int) {
|
||||
return cs.load_uint(32);
|
||||
}
|
||||
|
||||
@method_id(116) fun `call_~_via_backticks`():[int,int,int,int] {
|
||||
var b:builder = begin_cell().store_uint(1, 32).store_uint(2, 32).store_uint(3, 32).store_uint(4, 32);
|
||||
var `cs`:slice = b.end_cell().begin_parse();
|
||||
var (`cs` redef,one:int) = `cs`.`load_uint`(32);
|
||||
var (two:int,three:int) = (`cs`~`load_uint`(32), cs~`load:u32`());
|
||||
var (cs redef,four:int) = cs.`load:u32`();
|
||||
return [one,two,three,four];
|
||||
}
|
||||
|
||||
fun`main`(){}
|
||||
|
||||
/**
|
||||
method_id | in | out
|
||||
@testcase | 101 | | -1
|
||||
@testcase | 102 | | 1
|
||||
@testcase | 103 | | -1
|
||||
@testcase | 104 | | 1
|
||||
@testcase | 105 | | -1
|
||||
@testcase | 110 | | 1194
|
||||
@testcase | 111 | -1 | 22
|
||||
@testcase | 112 | 0 | [ -1 0 ]
|
||||
@testcase | 113 | | [ -4 6 -4 ]
|
||||
@testcase | 114 | 3 9 20 10 38 | [ -4 6 -4 ]
|
||||
@testcase | 115 | | [ 0 0 ]
|
||||
@testcase | 116 | | [ 1 2 3 4 ]
|
||||
|
||||
@fif_codegen
|
||||
"""
|
||||
get_+-+1 PROC:<{
|
||||
//
|
||||
-1 PUSHINT
|
||||
}>
|
||||
"""
|
||||
|
||||
@fif_codegen
|
||||
"""
|
||||
unary+bitwise-constant PROC:<{
|
||||
//
|
||||
-4 PUSHINT
|
||||
6 PUSHINT
|
||||
-4 PUSHINT
|
||||
TRIPLE
|
||||
}>
|
||||
"""
|
||||
|
||||
@fif_codegen
|
||||
"""
|
||||
unary_const_check PROC:<{
|
||||
//
|
||||
-1 PUSHINT // fst1=-1
|
||||
DUP // fst1=-1 snd1=-1
|
||||
2 PUSHINT // fst1=-1 snd1=-1 trd1=2
|
||||
s1 s1 s0 PUSH3 // fst1=-1 snd1=-1 trd1=2 fst2=-1 snd2=-1 trd2=2
|
||||
add3 CALLDICT // fst1=-1 snd1=-1 trd1=2 _13
|
||||
3 -ROLL // _13 fst1=-1 snd1=-1 trd1=2
|
||||
add3 CALLDICT // _13 _14
|
||||
PAIR // _12
|
||||
}>
|
||||
"""
|
||||
|
||||
*/
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue