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

[Tolk] Support syntax tensorVar.0 and tupleVar.0

It works both for reading and writing:
> var t = (1, 2);
> t.0;      // 1
> t.0 = 5;
> t;        // (5, 2)

It also works for typed/untyped tuples, producing INDEX and SETINDEX.

Global tensors and tuples works. Nesting `t.0.1.2` works. `mutate` works.
Even mixing tuples inside tensors inside a global for writing works.
This commit is contained in:
tolk-vm 2025-01-27 10:29:17 +03:00
parent 565bc59735
commit 7a1602f591
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
42 changed files with 1119 additions and 338 deletions

View file

@ -78,6 +78,17 @@ fun testStartBalanceCodegen2() {
return first;
}
global cur: [int, int, int];
global next: [int, int, int];
@method_id(95)
fun test95() {
cur = [1, 2, 3];
next = [2, 3, 4];
(cur, next) = (next, [3, 4, 5]);
return (cur, next);
}
/**
method_id | in | out
@testcase | 0 | 101 15 | 100 1
@ -90,6 +101,7 @@ fun testStartBalanceCodegen2() {
@testcase | 89 | 4 | 1 4 1 4
@testcase | 91 | | 10
@testcase | 92 | | 10 32
@testcase | 95 | | [ 2 3 4 ] [ 3 4 5 ]
@fif_codegen
"""
@ -104,9 +116,9 @@ fun testStartBalanceCodegen2() {
testDumpDontPolluteStack PROC:<{
...
DUMPSTK
x{6d79} PUSHSLICE // f s _5
x{6d79} PUSHSLICE // f s '5
STRDUMP DROP
SBITS // f _6
SBITS // f '6
}>
"""
@ -127,4 +139,20 @@ fun testStartBalanceCodegen2() {
FIRST // first
}>
"""
@fif_codegen
"""
test95 PROC:<{
...
next GETGLOB // '10
3 PUSHINT // '10 '12=3
4 PUSHINT // '10 '12=3 '13=4
5 PUSHINT // '10 '12=3 '13=4 '14=5
TRIPLE // '15 '16
next SETGLOB
cur SETGLOB
cur GETGLOB // '17
next GETGLOB // '17 '18
}>
"""
*/

View file

@ -7,7 +7,7 @@ fun main(a: int, b: int, c: int, d: int, e: int, f: int): (int, int) {
@method_id(101)
fun testDivMod(x: int, y: int) {
return [divMod(x, y), modDiv(x, y), mulDivMod(x, y, 10)];
return (divMod(x, y), modDiv(x, y), mulDivMod(x, y, 10));
}
/**
@ -18,5 +18,5 @@ fun testDivMod(x: int, y: int) {
@testcase | 0 | 448 -433 -444 792 150012 -356232 | -218 -572
@testcase | 0 | -40 -821 433 -734 -721629 -741724 | -206 889
@testcase | 0 | -261 -98 -494 868 -166153 733738 | 263 995
@testcase | 101 | 112 3 | [ 37 1 1 37 33 6 ]
@testcase | 101 | 112 3 | 37 1 1 37 33 6
*/

View file

@ -89,12 +89,14 @@ fun test_if_else(x: int): (int, int, int, int, int) {
@method_id(21)
fun test_assign_with_inner(x: int) {
return (x, x += 10, [(x, x += 20, eq(x -= 50), x)], eq2((x, x *= eq(x /= 2))));
var result = (x, x += 10, [x, x += 20, eq(x -= 50), x], eq2((x, x *= eq(x /= 2))));
return result;
}
@method_id(22)
fun test_assign_with_mutate(x: int) {
return (x, mul2(mutate x, x += 5), x.`~inc`(mul2(mutate x, x)), x);
var (result, _) = ((x, mul2(mutate x, x += 5), x.`~inc`(mul2(mutate x, x)), x), 0);
return result;
}
@method_id(23)
@ -138,5 +140,12 @@ fun main() {
inc CALLDICT // self newY
}>
"""
@fif_codegen
"""
test_assign_tensor_global PROC:<{
// x.0 x.1
"""
@code_hash 7627024945492125068389905298530400936797031708759561372406088054030801992712
*/

View file

@ -127,10 +127,10 @@ fun testBoolCompareOptimized(x: bool) {
"""
boolWithBitwiseConst PROC:<{
//
0 PUSHINT // _3
-1 PUSHINT // _3 _5
0 PUSHINT // _3 _5 _7
-1 PUSHINT // _3 _5 _7 _8
0 PUSHINT // '3
-1 PUSHINT // '3 '5
0 PUSHINT // '3 '5 '7
-1 PUSHINT // '3 '5 '7 '8
}>
"""
@ -142,22 +142,22 @@ fun testBoolCompareOptimized(x: bool) {
UNTIL:<{
INC // i n cnt
s2 PUSH // i n cnt i
NOT // i n cnt _6
NOT // i n cnt '6
}> // i n cnt
UNTIL:<{
INC // i n cnt
s2 PUSH // i n cnt i
NOT // i n cnt _9
NOT // i n cnt '9
}> // i n cnt
UNTIL:<{
INC // i n cnt
OVER // i n cnt n
0 EQINT // i n cnt _12
0 EQINT // i n cnt '12
}> // i n cnt
s0 s2 XCHG // cnt n i
NOT // cnt n _13
SWAP // cnt _13 n
0 EQINT // cnt _13 _14
NOT // cnt n '13
SWAP // cnt '13 n
0 EQINT // cnt '13 '14
}>
"""
@ -165,12 +165,12 @@ fun testBoolCompareOptimized(x: bool) {
"""
testConstNegateCodegen PROC:<{
//
TRUE // _0
FALSE // _0 _1
FALSE // _0 _1 _2
TRUE // _0 _1 _2 _3
TRUE // _0 _1 _2 _3 _4
FALSE // _0 _1 _2 _3 _4 _5
TRUE // '0
FALSE // '0 '1
FALSE // '0 '1 '2
TRUE // '0 '1 '2 '3
TRUE // '0 '1 '2 '3 '4
FALSE // '0 '1 '2 '3 '4 '5
}>
"""
@ -179,11 +179,11 @@ fun testBoolCompareOptimized(x: bool) {
testBoolNegateOptimized PROC:<{
// x
DUP // x x
NOT // x _1
OVER // x _1 x
NOT // x _1 _2
NOT // x '1
OVER // x '1 x
NOT // x '1 '2
s2 s(-1) PUXC
TRUE // x _1 x _2 _3
TRUE // x '1 x '2 '3
}>
"""
@ -192,13 +192,13 @@ fun testBoolCompareOptimized(x: bool) {
testBoolCompareOptimized PROC:<{
// x
DUP // x x
NOT // x _1
OVER // x _1 x
eqX CALLDICT // x _1 _2
NOT // x _1 _3
s2 PUSH // x _1 _3 x
eqX CALLDICT // x _1 _3 _4
s3 PUSH // x _1 _3 _4 x
NOT // x '1
OVER // x '1 x
eqX CALLDICT // x '1 '2
NOT // x '1 '3
s2 PUSH // x '1 '3 x
eqX CALLDICT // x '1 '3 '4
s3 PUSH // x '1 '3 '4 x
}>
"""
*/

View file

@ -216,16 +216,16 @@ Note, that since 'compute-asm-ltr' became on be default, chaining methods codege
"""
test6 PROC:<{
//
NEWC // _0
1 PUSHINT // _0 _1=1
SWAP // _1=1 _0
32 STU // _0
2 PUSHINT // _0 _4=2
SWAP // _4=2 _0
32 STU // _0
3 PUSHINT // _0 _7=3
SWAP // _7=3 _0
32 STU // _0
NEWC // '0
1 PUSHINT // '0 '1=1
SWAP // '1=1 '0
32 STU // '0
2 PUSHINT // '0 '4=2
SWAP // '4=2 '0
32 STU // '0
3 PUSHINT // '0 '7=3
SWAP // '7=3 '0
32 STU // '0
}>
"""
*/

View file

@ -35,7 +35,7 @@ Below, I just give examples of @fif_codegen tag:
"""
main PROC:<{
// s
17 PUSHINT // s _1=17
17 PUSHINT // s '1=17
OVER // s z=17 t
WHILE:<{
...
@ -63,7 +63,7 @@ main PROC:<{
@fif_codegen
"""
OVER
0 GTINT // s z t _5
0 GTINT // s z t '5
"""
@fif_codegen
@ -83,7 +83,7 @@ FALSE
}>
"""
@fif_codegen NOT // _8
@fif_codegen NOT // '8
@fif_codegen main PROC:<{
@fif_codegen_avoid PROCINLINE

View file

@ -14,13 +14,19 @@ fun getTwo<X>(): X { return 2 as X; }
fun takeInt(a: int) { return a; }
@method_id(102)
fun test102(): (int, int, int, [(int, int)]) {
fun test102(): (int, int, int, [int, int]) {
var a: int = getTwo();
var _: int = getTwo();
var b = getTwo() as int;
var c: int = 1 ? getTwo() : getTwo();
var c redef = getTwo();
return (eq1<int>(a), eq2<int>(b), takeInt(getTwo()), [(getTwo(), getTwo())]);
var ab_tens = (0, (1, 2));
ab_tens.0 = getTwo();
ab_tens.1.1 = getTwo();
var ab_tup = [0, [1, 2]];
ab_tup.0 = getTwo();
ab_tup.1.1 = getTwo();
return (eq1<int>(a), eq2<int>(b), takeInt(getTwo()), [getTwo(), ab_tens.1.1]);
}
@method_id(103)
@ -43,9 +49,9 @@ fun manyEq<T1, T2, T3>(a: T1, b: T2, c: T3): [T1, T2, T3] {
fun test104(f: int) {
var result = (
manyEq(1 ? 1 : 1, f ? 0 : null, !f ? getTwo() as int : null),
manyEq((f ? null as int : eq2(2), beginCell().storeBool(true).endCell().beginParse().loadBool()), 0, eq4(f))
manyEq(f ? null as int : eq2(2), beginCell().storeBool(true).endCell().beginParse().loadBool(), eq4(f))
);
__expect_type(result, "([int, int, int], [(int, bool), int, int])");
__expect_type(result, "([int, int, int], [int, bool, int])");
return result;
}
@ -74,7 +80,8 @@ fun test106() {
return [
abstractTransform(cellToSlice, calcLoad32, c),
abstractTransform(calcYPlus1<int>, calcYPlus1<int>, 0),
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2))
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2)).0,
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2)).1
];
}
@ -135,7 +142,7 @@ fun main(x: int): (int, [[int, int]]) {
@testcase | 101 | 0 | 0 0 0 [ 0 0 ] 0 0 0 [ 0 0 ] 0 0 0 []
@testcase | 102 | | 2 2 2 [ 2 2 ]
@testcase | 103 | 0 | 0 100 100
@testcase | 104 | 0 | [ 1 (null) 2 ] [ 2 -1 0 0 ]
@testcase | 104 | 0 | [ 1 (null) 2 ] [ 2 -1 0 ]
@testcase | 105 | | 3
@testcase | 106 | | [ 106 2 6 6 ]
@testcase | 107 | | 6 6 1 1 6 6

View file

@ -54,13 +54,13 @@ fun main() {
test3 PROC:<{
// x
DUP // x x
20 NEQINT // x _2
20 NEQINT // x '2
IFNOTJMP:<{ // x
DROP //
20 PUSHINT // _3=20
20 PUSHINT // '3=20
}> // x
DUP // x x
50 EQINT // x _5
50 EQINT // x '5
IFNOTJMP:<{ // x
"""
*/

View file

@ -0,0 +1,287 @@
fun increment(mutate self: int) {
self += 1;
}
fun increment2(mutate a: int, mutate b: int) {
a += 1;
b += 1;
}
fun assign1020(mutate a: int, mutate b: int) {
a = 10;
b = 20;
}
fun plus(mutate self: int, y: int): int {
val newVals = (self + y, y * 10);
self = newVals.0;
return newVals.1;
}
fun eq<X>(v: X): X { return v; }
@method_id(101)
fun test101() {
var t = (1, (2, 3), [4, 5, [6, 7]], 8);
(t.0, t.1.0, t.2.0) = (2, 3, 5);
t.3.increment();
t.2.1 += (t.1.1 += 1) - t.1.1 + 1;
increment2(mutate t.2.2.0, mutate t.2.2.1);
return t;
}
global t102: (int, (int, int), [int, int, [int, int]], int);
@method_id(102)
fun test102() {
t102 = (1, (2, 3), [4, 5, [6, 7]], 8);
(t102.0, t102.1.0, t102.2.0) = (2, 3, 5);
t102.3.increment();
t102.2.1 += (t102.1.1 += 1) - t102.1.1 + 1;
increment2(mutate t102.2.2.0, mutate t102.2.2.1);
return t102;
}
global t103: (int, int);
@method_id(103)
fun test103() {
t103 = (5, 5);
assign1020(mutate t103.0, mutate t103.1);
var t = (5, 5);
assign1020(mutate t.0, mutate t.1);
return (t103, t);
}
global t104: [[int, int]];
@method_id(104)
fun test104() {
var m = [[5, 5]];
(m.0.0, m.0.1) = (10, 20);
t104 = [[5, 5]];
(t104.0.0, t104.0.1) = (10, 20);
return (t104, m);
}
@method_id(105)
fun test105(x: int, y: int): (tuple, int, (int, int), int, int) {
var ab = (createEmptyTuple(), (x, y), tupleSize);
ab.0.tuplePush(1);
tuplePush(mutate ab.0, 2);
ab.1.0 = null;
ab.1.1 += 10;
var cb = ab.2;
return (ab.0, ab.0.1, ab.1, cb(ab.0), ab.2(ab.0));
}
@method_id(106)
fun test106(x: int, y: int) {
var ab = [createEmptyTuple(), [x, y], tupleSize];
ab.0.tuplePush(1);
tuplePush(mutate ab.0, 2);
ab.1.0 = null;
ab.1.1 += 10;
var cb = ab.2;
return (ab.0, ab.1, cb(ab.0), ab.2(ab.0));
}
@method_id(107)
fun test107() {
var ab = createEmptyTuple();
ab.tuplePush(1);
ab.tuplePush(beginCell().storeInt(1, 32));
return (ab.0 as int, getBuilderBitsCount(ab.1));
}
global t108: [int, [int, [int]]];
@method_id(108)
fun test108(last: int) {
t108 = [1, [2, [last]]];
t108.1.1.0.increment();
var t = [1, [2, [last]]];
t.1.1.0.increment();
return (t108, t);
}
@method_id(109)
fun test109(x: (int, int)): (int, int, int, int, int, int, int) {
return (x.1, x.1.plus(x.1 / 20), x.1, x.1 = x.1 * 2, x.1, x.1 += 1, x.1);
}
@method_id(110)
fun test110(f: int, s: int) {
var x = [f, s];
return (x, x.1, x.1.plus(x.1 / 20), x.1, x.1 = x.1 * 2, x.1, x.1 += 1, x.1, x);
}
global xx: (int, int);
@method_id(111)
fun test111(x: (int, int)) {
xx = x;
return (x, xx.1, xx.1.plus(xx.1 / 20), eq(xx.1 += (x.1 *= 0)), xx.1 = xx.1 * 2, xx.1, xx.1 += 1, xx.1, x);
}
global yy: [int, int];
@method_id(112)
fun test112(f: int, s: int) {
yy = [f, s];
return (yy, yy.1, yy.1.plus(yy.1 / 20), eq(yy.1 += (yy.1 *= 0)), yy.1 = yy.1 * 2, yy.1, yy.1 += 1, yy.1, yy);
}
@pure
fun getConstTuple() {
return [1,2];
}
fun testCodegenNoPureIndexedAccess() {
(getConstTuple().1, getConstTuple().0) = (3, 4);
return 0;
}
@method_id(113)
fun test113() {
var x = [[1, 2]];
return (x, x.0, plus(mutate x.0.0, 10), x.0, x, x.0 = [10, 20], x);
}
@method_id(114)
fun test114(f: int, s: int) {
var x = ((), (f, s), ());
return (x, x.1, plus(mutate x.1.0, 10), x.1, x, x.1 = (10, 20), x);
}
@method_id(115)
fun test115() {
var y = [[[[true]]]];
return (y, y.0.0.0.0 = !y.0.0.0.0, y.0);
}
@method_id(116)
fun test116() {
var t = createEmptyTuple();
t.tuplePush(1);
try {
return t.100500 as int;
} catch(excNo) {
return excNo;
}
}
@method_id(117)
fun test117() {
var t = createEmptyTuple();
t.tuplePush(1);
try {
return (t.0 as tuple).0 as int;
} catch(excNo) {
return excNo;
}
}
@method_id(118)
fun testCodegenIndexPostfix1(x: (int, int)) {
var ab = (x.1, x.0);
return ab;
}
@method_id(119)
fun testCodegenIndexPostfix2(x: (int, (int, int), int)) {
var y = x;
return (y.2, y.0, y.1.1);
}
fun getT() { return (1, 2); }
@method_id(120)
fun test120() {
return (getT().0 = 3, getT().0 = 4, [getT().0 = 5, getT().0 = 6]);
}
@method_id(121)
fun test121(zero: int) {
var t = createEmptyTuple();
t.tuplePush(-100);
t.tupleSetAt(0, zero);
(t.0 as int).increment();
(((t.0) as int) as int).increment();
increment(mutate t.0 as int);
return t;
}
fun main(){}
/**
@testcase | 101 | | 2 3 4 [ 5 6 [ 7 8 ] ] 9
@testcase | 102 | | 2 3 4 [ 5 6 [ 7 8 ] ] 9
@testcase | 103 | | 10 20 10 20
@testcase | 104 | | [ [ 10 20 ] ] [ [ 10 20 ] ]
@testcase | 105 | 5 6 | [ 1 2 ] 2 (null) 16 2 2
@testcase | 106 | 5 6 | [ 1 2 ] [ (null) 16 ] 2 2
@testcase | 107 | | 1 32
@testcase | 108 | 3 | [ 1 [ 2 [ 4 ] ] ] [ 1 [ 2 [ 4 ] ] ]
@testcase | 109 | 0 100 | 100 50 105 210 210 211 211
@testcase | 110 | 0 100 | [ 0 100 ] 100 50 105 210 210 211 211 [ 0 211 ]
@testcase | 111 | 0 100 | 0 100 100 50 105 210 210 211 211 0 0
@testcase | 112 | 0 100 | [ 0 100 ] 100 50 105 210 210 211 211 [ 0 211 ]
@testcase | 113 | | [ [ 1 2 ] ] [ 1 2 ] 100 [ 11 2 ] [ [ 11 2 ] ] [ 10 20 ] [ [ 10 20 ] ]
@testcase | 114 | 1 2 | 1 2 1 2 100 11 2 11 2 10 20 10 20
@testcase | 115 | | [ [ [ [ -1 ] ] ] ] 0 [ [ [ 0 ] ] ]
@testcase | 116 | | 5
@testcase | 117 | | 7
@testcase | 118 | 1 2 | 2 1
@testcase | 119 | 1 2 3 4 | 4 1 3
@testcase | 120 | | 3 4 [ 5 6 ]
@testcase | 121 | 0 | [ 3 ]
@fif_codegen
"""
testCodegenNoPureIndexedAccess PROC:<{
//
0 PUSHINT // '8=0
}>
"""
@fif_codegen
"""
test104 PROC:<{
//
5 PUSHINT // '2=5
DUP // '2=5 '3=5
PAIR // '1
SINGLE // m
10 PUSHINT // m '5=10
20 PUSHINT // m '5=10 '6=20
s2 PUSH // m '5=10 '6=20 m
0 INDEX // m '10=10 '12=20 '8
SWAP // m '10=10 '8 '12=20
1 SETINDEX // m '10=10 '8
SWAP // m '8 '10=10
0 SETINDEX // m '8
0 SETINDEX // m
...
"""
@fif_codegen
"""
testCodegenIndexPostfix1 PROC:<{
// x.0 x.1
// ab.1 ab.0
SWAP // ab.0 ab.1
}>
"""
@fif_codegen
"""
testCodegenIndexPostfix2 PROC:<{
// x.0 x.1.0 x.1.1 x.2
s2 POP // y.0 y.2 y.1.1
s1 s2 XCHG // y.2 y.0 y.1.1
}>
"""
*/

View file

@ -0,0 +1,9 @@
fun main() {
var c = 1;
(c, c) = (2, 3);
}
/**
@compilation_should_fail
@stderr one variable modified twice inside the same expression
*/

View file

@ -0,0 +1,11 @@
fun incThree(mutate a: int, mutate b: int, mutate c: int) {}
fun main() {
var c = [[[1, 2]]];
incThree(mutate c.0.0.0, mutate c.0.0.1, mutate c.0.0.0);
}
/**
@compilation_should_fail
@stderr one variable modified twice inside the same expression
*/

View file

@ -0,0 +1,10 @@
global gg: (int, int);
fun main() {
[gg.0, gg.1, gg.0] = [0, 1, 0];
}
/**
@compilation_should_fail
@stderr one variable modified twice inside the same expression
*/

View file

@ -0,0 +1,10 @@
global gg: (int, [int, int]);
fun main() {
(gg.1.0, gg.1, gg.1.1) = (0, [1, 2], 3);
}
/**
@compilation_should_fail
@stderr one variable both modified and read inside the same expression
*/

View file

@ -0,0 +1,9 @@
fun main() {
var ab = (1, 2);
(ab, ab.1) = ((2, 3), 4);
}
/**
@compilation_should_fail
@stderr one variable both modified and read inside the same expression
*/

View file

@ -0,0 +1,9 @@
fun main() {
var t = createEmptyTuple();
t.0 = (1, 2);
}
/**
@compilation_should_fail
@stderr can not put `(int, int)` into a tuple, because it occupies 2 stack slots in TVM, not 1
*/

View file

@ -0,0 +1,8 @@
fun main(cs: slice) {
var cb = cs.tupleSize;
}
/**
@compilation_should_fail
@stderr referencing a method for `tuple` with object of type `slice`
*/

View file

@ -6,5 +6,5 @@ fun main(x: int) {
/**
@compilation_should_fail
@stderr calling a non-function
@stderr non-existing method `asdf` of type `int`
*/

View file

@ -0,0 +1,11 @@
fun takeInvalidTuple(t: [int, (int, builder), int]) {
}
fun main() {
takeInvalidTuple([1, (2, beginCell()), 0]);
}
/**
@compilation_should_fail
@stderr can not put `(int, builder)` into a tuple, because it occupies 2 stack slots in TVM, not 1
*/

View file

@ -0,0 +1,11 @@
fun main() {
var functions = (beginCell, beginCell);
var b = functions.1(); // ok
var c = functions.2(); // error
}
/**
@compilation_should_fail
@stderr invalid tensor index, expected 0..1
@stderr functions.2()
*/

View file

@ -9,6 +9,6 @@ fun main() {
/**
@compilation_should_fail
@stderr undefined symbol `storeUnexisting`
@stderr non-existing method `storeUnexisting` of type `builder`
@stderr .storeUnexisting()
*/

View file

@ -1,8 +1,10 @@
fun get_incoming_value() { return 3; }
fun main() {
var incoming_ton: int = get_incoming_value().3();
}
/**
@compilation_should_fail
@stderr expected method name, got `3`
@stderr type `int` is not indexable
*/

View file

@ -0,0 +1,15 @@
fun getTwo<X>(): X { return 2; }
fun cantDeduceNonArgumentGeneric() {
var t1: [int] = [0];
t1.0 = getTwo(); // ok
var t2 = createEmptyTuple();
t2.tuplePush(0);
t2.0 = getTwo(); // error, can't decude X
}
/**
@compilation_should_fail
@stderr can not deduce X for generic function `getTwo<X>`
@stderr t2.0 = getTwo();
*/

View file

@ -0,0 +1,9 @@
fun failAssignToInvalidTupleIndex() {
var ab = [1, 2];
ab.100500 = 5;
}
/**
@compilation_should_fail
@stderr invalid tuple index, expected 0..1
*/

View file

@ -1,27 +0,0 @@
fun increment(mutate x: int): int {
x = x + 1;
return x;
}
@method_id(101)
fun bugWithModifyingMethodInsideSameExpression() {
/*
The same bug existed in FunC:
#pragma allow-post-modification;
(int, int) ~increment(int x) { x = x + 5; return (x, x); }
int main() { int x = 0; x += x~increment(); return x; }
It's related to using a variable modified by ~method inside the same expression.
*/
var x = 0;
x = x + increment(mutate x);
return x;
}
fun main() {
}
/**
// correct: 2
@testcase | 101 | | 1
*/

View file

@ -210,15 +210,15 @@ fun main() {
compileTimeEval1 PROC:<{
// x
DUP // x x
0 EQINT // x _1
FALSE // x _1 _4
TRUE // x _1 _4 _7
FALSE // x _1 _4 _7 _11
s0 s4 XCHG // _11 _1 _4 _7 x
0 EQINT // _11 _1 _4 _7 _12
-10 EQINT // _11 _1 _4 _7 _14
0 EQINT // x '1
FALSE // x '1 '4
TRUE // x '1 '4 '7
FALSE // x '1 '4 '7 '11
s0 s4 XCHG // '11 '1 '4 '7 x
0 EQINT // '11 '1 '4 '7 '12
-10 EQINT // '11 '1 '4 '7 '14
s3 s4 XCHG
s1 s3 s0 XCHG3 // _1 _4 _7 _11 _14
s1 s3 s0 XCHG3 // '1 '4 '7 '11 '14
}>
"""
@ -230,15 +230,15 @@ fun main() {
OVER // x y x
IFNOTJMP:<{ // x y
2DROP //
10 PUSHINT // _2=10
10 PUSHINT // '2=10
}> // x y
DUP // x y y
IFNOTJMP:<{ // x y
2DROP //
20 PUSHINT // _3=20
20 PUSHINT // '3=20
RETALT
}> // x y
ADD // _4
ADD // '4
}>
"""
@ -297,10 +297,10 @@ These are moments of future optimizations. For now, it's more than enough.
// a b
SWAP // b a
IF:<{ // b
0 NEQINT // _2
0 NEQINT // '2
}>ELSE<{ // b
DROP //
0 PUSHINT // _2=0
0 PUSHINT // '2=0
}>
}>
"""
@ -310,13 +310,13 @@ These are moments of future optimizations. For now, it's more than enough.
testOrSimpleCodegen PROC:<{
// a b
SWAP // b a
0 GTINT // b _3
0 GTINT // b '3
IF:<{ // b
DROP //
-1 PUSHINT // _4=-1
-1 PUSHINT // '4=-1
}>ELSE<{ // b
0 GTINT // _7
0 NEQINT // _4
0 GTINT // '7
0 NEQINT // '4
}>
}>
"""
@ -332,15 +332,15 @@ These are moments of future optimizations. For now, it's more than enough.
DUP // x x
IFNOTJMP:<{ // x
DROP //
1 PUSHINT // _5=1
1 PUSHINT // '5=1
}> // x
DUP // x x
IFNOTJMP:<{ // x
DROP //
1 PUSHINT // _6=1
1 PUSHINT // '6=1
}> // x
100 THROWIFNOT
-4 PUSHINT // _9=-4
-4 PUSHINT // '9=-4
}>
"""

View file

@ -307,7 +307,7 @@ fun main(){}
...
incrementTwoInPlace CALLDICT // x y sum1
-ROT
10 PUSHINT // sum1 x y _10=10
10 PUSHINT // sum1 x y '10=10
incrementTwoInPlace CALLDICT // sum1 x y sum2
s1 s3 s0 XCHG3 // x y sum1 sum2
}>
@ -317,8 +317,8 @@ fun main(){}
"""
load_next PROC:<{
// cs
32 LDI // _4 cs
SWAP // cs _4
32 LDI // '4 cs
SWAP // cs '4
}>
"""
@ -326,7 +326,7 @@ fun main(){}
"""
testStoreUintPureUnusedResult PROC:<{
//
0 PUSHINT // _11=0
0 PUSHINT // '11=0
}>
"""
@ -335,9 +335,9 @@ fun main(){}
testStoreUintImpureUnusedResult PROC:<{
//
NEWC // b
STIX // _2
STIX // '2
DROP //
0 PUSHINT // _11=0
0 PUSHINT // '11=0
}>
"""

View file

@ -104,10 +104,10 @@ fun`main`(){}
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
add3 CALLDICT // fst1=-1 snd1=-1 trd1=2 '13
3 -ROLL // '13 fst1=-1 snd1=-1 trd1=2
add3 CALLDICT // '13 '14
PAIR // '12
}>
"""

View file

@ -99,21 +99,21 @@ fun main() {
test1 PROC:<{
//
PUSHNULL // numbers
1 PUSHINT // numbers _2=1
SWAP // _2=1 numbers
1 PUSHINT // numbers '2=1
SWAP // '2=1 numbers
CONS // numbers
2 PUSHINT // numbers _4=2
SWAP // _4=2 numbers
2 PUSHINT // numbers '4=2
SWAP // '4=2 numbers
CONS // numbers
3 PUSHINT // numbers _6=3
SWAP // _6=3 numbers
3 PUSHINT // numbers '6=3
SWAP // '6=3 numbers
CONS // numbers
4 PUSHINT // numbers _8=4
SWAP // _8=4 numbers
4 PUSHINT // numbers '8=4
SWAP // '8=4 numbers
CONS // numbers
UNCONS // h numbers
DUP // h numbers numbers
CAR // h numbers _13
CAR // h numbers '13
"""
@fif_codegen
@ -121,11 +121,11 @@ fun main() {
main PROC:<{
//
PUSHNULL // i
ISNULL // _2
ISNULL // '2
IFJMP:<{ //
1 PUSHINT // _3=1
1 PUSHINT // '3=1
}> //
10 PUSHINT // _4=10
10 PUSHINT // '4=10
}>
"""
@ -133,14 +133,14 @@ fun main() {
"""
test7 PROC:<{
...
LDOPTREF // b _8 _7
LDOPTREF // b '8 '7
DROP // b c
ISNULL // b _11
10 MULCONST // b _13
SWAP // _13 b
ISNULL // _13 _14
NOT // _13 _15
ADD // _16
ISNULL // b '11
10 MULCONST // b '13
SWAP // '13 b
ISNULL // '13 '14
NOT // '13 '15
ADD // '16
}>
"""
*/

View file

@ -95,26 +95,26 @@ fun main() {
unary_minus_1 PROC:<{
// a b c
-ROT // c a b
ADD // c _3
NEGATE // c _4
SWAP // _4 c
MUL // _5
ADD // c '3
NEGATE // c '4
SWAP // '4 c
MUL // '5
}>
unary_minus_2 PROC:<{
// a b c
-ROT // c a b
ADD // c _3
NEGATE // c _4
SWAP // _4 c
MUL // _5
ADD // c '3
NEGATE // c '4
SWAP // '4 c
MUL // '5
}>
unary_minus_3 PROC:<{
// a b c
-ROT // c a b
ADD // c _3
SWAP // _3 c
MUL // _4
NEGATE // _5
ADD // c '3
SWAP // '3 c
MUL // '4
NEGATE // '5
}>
"""

View file

@ -43,7 +43,7 @@ const demo_20: int = 20;
"""
test1 PROC:<{
//
30 PUSHINT // _10
30 PUSHINT // '10
}>
"""
*/

View file

@ -129,6 +129,15 @@ fun testVarApply3() {
return (getIntAt(t, 0), getTupleFirstInt(t), getTupleLastTuple(t), getTupleLastGetter<tuple>()(t));
}
@method_id(107)
fun testIndexedAccessApply() {
var functions1 = (beginCell, endCell);
var functions2 = [beginParse];
var b = functions1.0().storeInt(1, 16);
b.storeInt(1, 16);
return functions2.0(functions1.1(b)).loadInt(32);
}
fun main() {}
/**
@ -138,4 +147,5 @@ fun main() {}
@testcase | 104 | | 240
@testcase | 105 | | 1
@testcase | 106 | | 1 1 [ 2 ] [ 2 ]
@testcase | 107 | | 65537
*/