1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-15 04:32:21 +00:00
ton/tolk-tester/tests/var-apply.tolk

116 lines
2.2 KiB
Text
Raw Normal View History

fun getBeginCell() {
return beginCell;
}
fun getBeginParse() {
return beginParse;
}
@method_id(101)
fun testVarApply1() {
var (_, f_end_cell) = (0, endCell);
var b: builder = (getBeginCell())().storeInt(1, 32);
b.storeInt(2, 32);
var s = (getBeginParse())(f_end_cell(b));
return (s.loadInt(32), s.loadInt(32));
}
@inline
fun my_throw_always() {
throw 1000;
}
@inline
fun get_raiser() {
return my_throw_always;
}
@method_id(102)
fun testVarApplyWithoutSavingResult() {
try {
var raiser = get_raiser();
raiser(); // `some_var()` is always impure, the compiler has no considerations about its runtime value
return 0;
} catch (code) {
return code;
}
}
@inline
fun sum(a: int, b: int) {
assert(a + b < 24, 1000);
return a + b;
}
@inline
fun mul(a: int, b: int) {
assert(a * b < 24, 1001);
return a * b;
}
fun demo_handler(op: int, query_id: int, a: int, b: int): int {
if (op == 0xF2) {
val func = query_id % 2 == 0 ? sum : mul;
val result = func(a, b);
return 0; // result not used, we test that func is nevertheless called
}
if (op == 0xF4) {
val func = query_id % 2 == 0 ? sum : mul;
val result = func(a, b);
return result;
}
return -1;
}
@method_id(103)
fun testVarApplyInTernary() {
var t: tuple = createEmptyTuple();
try {
t.tuplePush(demo_handler(0xF2, 122, 100, 200));
} catch(code) {
t.tuplePush(code);
}
try {
t.tuplePush(demo_handler(0xF4, 122, 100, 200));
} catch(code) {
t.tuplePush(code);
}
try {
t.tuplePush(demo_handler(0xF2, 122, 10, 10));
} catch(code) {
t.tuplePush(code);
}
try {
t.tuplePush(demo_handler(0xF2, 123, 10, 10));
} catch(code) {
t.tuplePush(code);
}
return t;
}
fun always_throw2(x: int) {
throw 239 + x;
}
global global_f: int -> ();
@method_id(104)
fun testGlobalVarApply() {
try {
global_f = always_throw2;
global_f(1);
return 0;
} catch (code) {
return code;
}
}
fun main() {}
/**
@testcase | 101 | | 1 2
@testcase | 102 | | 1000
@testcase | 103 | | [ 1000 1000 0 1001 ]
@testcase | 104 | | 240
*/