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

[FunC] Drop a folder crypto/func/test, it's unused

This commit is contained in:
Aleksandr Kirsanov 2024-05-22 11:52:34 +03:00
parent 2da85a646c
commit 49a0d32c1b
No known key found for this signature in database
GPG key ID: B758BBAA01FFB3D3
52 changed files with 0 additions and 1482 deletions

View file

@ -1,9 +0,0 @@
_ f(int a, int x) {
int y = 0;
int z = 0;
while ((y = x * x) > a) {
x -= 1;
z = 1;
}
return (y, z);
}

View file

@ -1,28 +0,0 @@
_ f(slice ds, int total_weight, int elect_at, cell frozen, int total_stakes, int cnt, cell credits, cell vdict, int elect) {
return (ds, elect, credits);
}
_ g(slice ds, int total_weight, int elect_at, cell frozen, int total_stakes, int cnt, cell credits, int elect) {
return (ds, elect, credits);
}
_ h(slice ds, int total_weight, int elect_at, cell frozen, int total_stakes, cell credits, int elect) {
return (ds, elect, credits);
}
_ h2(slice ds, int total_weight, int elect_at, cell frozen, int total_stakes, cell credits, int elect) {
return (ds, credits, elect);
}
_ h3(int pubkey, int adnl_addr, int stake, int tot_weight, tuple vinfo) {
return (pubkey, tot_weight, stake, vinfo);
}
_ z(int a, int b) {
return (b, 0, a);
}
_ z2(int a, int b) {
return (0, a, b);
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o) {
return (a, i, o, j, e, f, g, h, k, l, m, d, b, c, n);
;; optimal code is 6-byte: s11 s12 XCHG2 2 5 BLKSWAP s13 s13 s11 XCHG3
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
return (f, j, a, b, i, g, d, e, h, c); ;; optimal code is 3 ops, 6 bytes
;; s6 s0 s4 XCHG3 s4 s8 s9 XCHG3 8 0 REVERSE
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
return (f, d, j, a, i, g, b, e, h, c); ;; optimal code is 4 ops, 6 bytes
;; s1 s8 XCHG s1 s6 XCHG 7 3 BLKSWAP s9 s4 XCHG2
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k) {
return (e, h, d, a, c, g, f, b, i, j, k); ;; optimal code is 4 ops, 8 bytes
;; s9 s9 XCHG2 s6 s6 s8 XCHG3 s10 s7 s3 XCHG3 10 0 REVERSE
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k) {
return (b, a, c, e, g, d, f, k, i, j, h); ;; optimal code is 4 ops, 8 bytes
;; s5 s0 s8 XCHG3 2 9 BLKSWAP s8 s9 s10 XCHG3 s7 s0 s5 XCHG3
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k) {
return (c, g, d, k, a, f, e, h, i, j, b); ;; optimal code is 6 ops, 6 bytes
;; s0 s7 XCHG s0 s8 XCHG s0 s10 XCHG s0 s6 XCHG s0 s4 XCHG s0 s9 XCHG
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k) {
return (h, e, d, j, k, f, i, a, b, c, g); ;; optimal code is 3 ops, 6 bytes
;; s3 s10 XCHG s6 s7 s6 XCHG3 s9 s8 s4 XCHG3
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p) {
return (m, f, l, j, b, e, a, d, p, k, c, n, g, i, h, o); ;; optimal code is 6 ops, 11 bytes
;; s12 s0 s14 XCHG3 s0 s5 XCHG 6 8 BLKSWAP s3 s3 s9 XCHG3 s10 s14 s15 XCHG3 s13 s9 s9 XCHG3
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p) {
return (l, i, o, h, a, m, j, d, p, g, n, b, k, e, c, f); ;; optimal code is 5 ops, 10 bytes
;; 8 0 REVERSE s3 s9 s14 XCHG3 s15 s6 s4 XCHG3 s8 s12 XCHG s11 s13 s10 XCHG3
}

View file

@ -1,4 +0,0 @@
_ f(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p) {
return (g, j, n, f, o, i, e, l, d, h, b, k, m, c, p, a); ;; optimal code is 5 ops, 10 bytes
;; s7 s5 s14 XCHG3 s10 s4 s5 XCHG3 s12 s8 s11 XCHG3 s7 s6 s9 XCHG3 s13 s14 s15 XCHG3
}

View file

@ -1,89 +0,0 @@
(int, int) f(int a, int b, int c, int d, int e, int f) {
;; solve a 2x2 linear equation
int D = a * d - b * c;
int Dx = e * d - b * f;
int Dy = a * f - e * c;
return (Dx / D, Dy / D);
}
int calc_phi() {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
(p, q) = (q, p + q);
} until (q > n);
return muldivr(p, n, q);
}
int calc_sqrt2() {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
var t = p + q;
(p, q) = (q, t + q);
} until (q > n);
return muldivr(p, n, q);
}
var calc_root(m) {
int base = 1;
repeat(70) { base *= 10; }
var (a, b, c) = (1, 0, - m);
var (p1, q1, p2, q2) = (1, 0, 0, 1);
do {
int k = -1;
var (a1, b1, c1) = (0, 0, 0);
do {
k += 1;
(a1, b1, c1) = (a, b, c);
c += b;
c += b += a;
} until (c > 0);
(a, b, c) = (- c1, - b1, - a1);
(p1, q1) = (k * p1 + q1, p1);
(p2, q2) = (k * p2 + q2, p2);
} until (p1 > base);
return (p1, q1, p2, q2);
}
{-
operator _/%_ infix 20;
(int, int) ((int x) /% (int y)) {
return (x / y, x % y);
}
(int, int) _/%_ (int x, int y) {
return (x / y, x % y);
}
-}
forall A, B, C ->
(B, C, A) rot (A x, B y, C z) {
return (y, z, x);
}
int ataninv(int base, int q) { ;; computes base*atan(1/q)
base ~/= q;
q *= - q;
int sum = 0;
int n = 1;
do {
sum += base ~/ n;
base ~/= q;
n += 2;
} until base == 0;
return sum;
}
int calc_pi() {
int base = 64;
repeat (70) { base *= 10; }
return (ataninv(base << 2, 5) - ataninv(base, 239)) ~>> 4;
}
int main() {
return calc_pi();
}

View file

@ -1,75 +0,0 @@
f(int a, int b, int c, int d, int e, int f) : (int, int) {
var D = a * d - b * c;
var Dx : int = e * d - b * f;
var Dy : int = a * f - e * c;
return (Dx / D, Dy / D);
}
calc_phi() : int = {
var n : int = 1;
repeat (10) {
n *= 10;
}
var p = var q = 1;
do {
(p, q) = (q, p + q);
} until q > n;
return muldivr(p, n, q);
}
calc_sqrt2() : int = {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
var t = p + q;
(p, q) = (q, t + q);
} until q > n;
return muldivr(p, n, q);
}
calc_phi() : int = {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
(p, q) = (q, p + q);
} until q > n;
return muldivr(p, n, q);
}
operator _/%_ infix 20;
(x : int) /% (y : int) : (int, int) = {
return (x / y, x % y);
}
{-
_/%_ (int x, int y) : (int, int) = {
return (x / y, x % y);
}
-}
rot < A : type, B : type, C : type >
(x : A, y : B, z : C) : (B, C, A) {
return (y, z, x);
}
ataninv(base : int, q : int) : int { ;; computes base*atan(1/q)
base /~= q;
q *= - q;
var sum : int = 0;
var n = 1;
do {
sum += base /~ n;
base /~= q;
n += 2;
} while base;
return sum;
}
calc_pi() : int {
var base = 64;
repeat (70) { base *= 10; }
return (ataninv(base << 2, 5) - ataninv(base, 239)) >>~ 4;
}

View file

@ -1,6 +0,0 @@
(int, int) f(int a, int b, int c, int d, int e, int f) {
int D = a * d - b * c;
int Dx = e * d - b * f;
int Dy = a * f - e * c;
return (Dx / D, Dy / D);
}

View file

@ -1,130 +0,0 @@
var f(a, b, c, d, e, f) {
var D = a * d - b * c;
var Dx = e * d - b * f;
var Dy = a * f - e * c;
return (Dx / D, Dy / D);
}
var test8() {
return -4;
}
var test3(a) {
int x = a * 10;
a += 1;
int x = x + 3;
{
int y = x + 2;
x = y + a;
}
int z = 5;
return x * (z + a);
}
var test2(a) {
(var x, var y) = a /% 10;
return x + y;
}
var test2a(a) {
var (x, y) = a /% 10;
return x + y;
}
var test2b(a) {
var z = a /% 10;
return _+_ z;
}
var test2c(a) {
return _+_ (a /% 10);
}
var twice(f, x) {
return f (f x);
}
var test() {
return f(1, 2, 3, 4, 7, 17);
}
var rot(a, b, c) {
return (b, c, a);
}
var rot_int(int a, int b, int c) {
return (b, c, a);
}
(int, _) dup_int(x) {
return (x, x);
}
var calc_phi() {
var n = 10;
n *= n;
n *= n;
n *= n;
n *= n;
n *= n;
n *= n;
var p = var q = 1;
(p, q) = (q, p + q);
(p, q) = (q, p + q);
(p, q) = (q, p + q);
(p, q) = (q, p + q);
(p, q) = (q, p + q);
(p, q) = (q, p + q);
(p, q) = (q, p + q);
return muldivr(p, n, q);
}
var t0() {
var x = 1;
return x;
}
var t1() {
return 2;
}
var t2(int x) {
return 2;
return x += 1;
}
var t3(int x, var y) {
int z = (x + y) * (x - y);
}
var t3b(int x, var y) {
int z = (x + y) * (x - y);
return z;
}
var t4((int, int, int) z) {
var (_, u, _) = z;
return u;
}
int foo(int t);
var t5(x) {
var f = t2;
return twice(f, x) * f(x);
}
var proj1(a, b) { return a; }
var proj1a(a, b) { var c = a; return c; }
var proj1b(a, b) { int c = a; return c; }
var proj1c(a, b) { var c = a + 2; return c; }
var proj1d(a, b) { return a + 2; }
var proj1e(int a, _) { return a; }
int proj1f(_ a, int) { return a; }
int proj1g(int, a) { return a; }
var test1(a) {
a = a + 1;
return a;
}

View file

@ -1,22 +0,0 @@
forall A, B, C ->
(B, C, A) rot(A x, B y, C z) {
return (y, z, x);
}
forall A, B, C ->
_ rot2(A x, B y, C z) {
return rot(rot(x, y, z));
}
_ test() {
return rot2(2, 3, 9);
}
_ test2(cell x, slice y, tuple z) {
return rot2(x, y, z);
}
forall A ->
_ test3(cell x, A y, int z) {
return rot2(x, y, z);
}

View file

@ -1,20 +0,0 @@
var calc_root(m) {
int base = 1;
repeat(70) { base *= 10; }
var (a, b, c) = (1, 0, - m);
var (p1, q1, p2, q2) = (1, 0, 0, 1);
do {
int k = -1;
var (a1, b1, c1) = (0, 0, 0);
do {
k += 1;
(a1, b1, c1) = (a, b, c);
c += b;
c += b += a;
} until (c > 0);
(a, b, c) = (- c1, - b1, - a1);
(p1, q1) = (k * p1 + q1, p1);
(p2, q2) = (k * p2 + q2, p2);
} until (p1 > base);
return (p1, q1, p2, q2);
}

View file

@ -1,20 +0,0 @@
var twice(f, x) {
return f (f x);
}
_ sqr(x) {
return x * x;
}
var main(x) {
var f = sqr;
return twice(f, x) * f(x);
}
var pow6(x) {
return twice(sqr, x) * sqr(x);
}
_ q() {
return false;
}

View file

@ -1,12 +0,0 @@
int steps(int x) {
var n = 0;
while (x > 1) {
n += 1;
if (x & 1) {
x = 3 * x + 1;
} else {
x >>= 1;
}
}
return n;
}

View file

@ -1,28 +0,0 @@
int A(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(d, e, f);
}
int B(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(b, d, e) + f;
}
int C(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(b, d, c) + muldiv(d, d, f);
}
int D(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(b, d, c) + muldiv(e, e, f);
}
int E(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(c, d, e) + muldiv(c, c, f);
}
int F(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(a, d, c) + muldiv(f, f, e);
}
int G(int a, int b, int c, int d, int e, int f) {
return muldiv(a, b, c) + muldiv(b, c, d) + muldiv(b, c, e) + f;
}

View file

@ -1,23 +0,0 @@
int f(int x) {
if (2 * x + 1 == 7) {
return x + 17;
} else {
return 239;
}
}
int f2(int x) {
return 2 * x + 1 == 6 ? x + 17 : 239;
}
int g(int x) {
return x & 1 ? 3 * x + 1 : x / 2;
}
_ H(int x, int y) {
return (x < y, x <= y, x == y, x >= y, x > y, x != y, x <=> y);
}
int q() {
return 4;
}

View file

@ -1,28 +0,0 @@
_ F(int x) {
x = 2;
return x + 1;
}
_ G(x) {
var y = x + 1;
x = 2;
return (x - 1, y);
}
_ H(x) {
var y = x + 1;
x = 2;
return (x * y, y);
}
_ I(x) {
int y = 17;
int z = x - y;
return (z, y);
}
_ J(x) {
int y = 239;
int z = x - y;
return (z, y);
}

View file

@ -1,63 +0,0 @@
int now() pure asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond)
;; asm "THROWARGIF";
cell get_data() pure asm "c4 PUSH";
() set_data(cell c) asm "c4 POP";
() accept_message() asm "ACCEPT";
slice begin_parse(cell c) pure asm "CTOS";
() end_parse(slice s) asm "ENDS";
(cell, slice) load_ref(slice s) pure asm "LDREF";
(int, slice) zload_int(slice s, int len) pure asm "LDIX";
(int, slice) zload_uint(slice s, int len) pure asm "LDUX";
int zpreload_int(slice s, int len) pure asm "PLDIX";
int zpreload_uint(slice s, int len) pure asm "PLDUX";
(slice, slice) load_bits(slice s, int len) pure asm "LDSLICEX";
slice preload_bits(slice s, int len) pure asm "PLDSLICEX";
cell set_idict_ref(cell value, int index, cell dict, int key_len) pure asm "DICTISETREF";
builder begin_cell() pure asm "NEWC";
builder store_ref(cell c, builder b) pure asm "STREF";
builder zstore_uint(int x, builder b, int len) pure asm "STUX";
builder zstore_int(int x, builder b, int len) pure asm "STIX";
cell end_cell(builder b) pure asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) {
;; do nothing for internal messages
}
() recv_external(cell in_msg) {
var (signature, cs0) = load_bits(begin_parse(in_msg), 512);
var (msg_seqno, cs) = zload_uint(cs0, 32);
(var valid_until, cs) = zload_uint(cs, 32);
throw_if(35, valid_until < now());
var (cfg_dict, cs2) = load_ref(begin_parse(get_data()));
(var stored_seqno, cs2) = zload_uint(cs2, 32);
(var public_key, cs2) = zload_uint(cs2, 256);
end_parse(cs2);
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
(var param_index, cs) = zload_uint(cs, 32);
(var param_value, cs) = load_ref(cs);
end_parse(cs);
;; cfg_dict = set_idict_ref(param_value, param_index, cfg_dict, 32);
;; var cb = begin_cell();
;; cb = store_ref(cfg_dict, cb);
var cb = store_ref(set_idict_ref(param_value, param_index, cfg_dict, 32), begin_cell());
cb = zstore_uint(stored_seqno + 1, cb, 32);
cb = zstore_uint(public_key, cb, 256);
set_data(end_cell(cb));
}

View file

@ -1,60 +0,0 @@
int now() pure asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond)
;; asm "THROWARGIF";
cell get_data() pure asm "c4 PUSH";
() set_data(cell c) asm "c4 POP";
() accept_message() asm "ACCEPT";
slice begin_parse(cell c) pure asm "CTOS";
() end_parse(slice s) asm "ENDS";
(slice, cell) load_ref(slice s) pure asm( -> 1 0) "LDREF";
;; (slice, int) load_int(slice s, int len) pure asm(s len -> 1 0) "LDIX";
;; (slice, int) load_uint(slice s, int len) pure asm( -> 1 0) "LDUX";
;; int preload_int(slice s, int len) pure asm "PLDIX";
;; int preload_uint(slice s, int len) pure asm "PLDUX";
(slice, slice) load_bits(slice s, int len) pure asm(s len -> 1 0) "LDSLICEX";
slice preload_bits(slice s, int len) pure asm "PLDSLICEX";
cell set_idict_ref(cell dict, int key_len, int index, cell value) pure asm(value index dict key_len) "DICTISETREF";
builder begin_cell() pure asm "NEWC";
builder store_ref(builder b, cell c) pure asm(c b) "STREF";
;; builder store_uint(builder b, int x, int len) pure asm(x b len) "STUX";
;; builder store_int(builder b, int x, int len) pure asm(x b len) "STIX";
cell end_cell(builder b) pure asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) {
;; do nothing for internal messages
}
() recv_external(cell in_msg) {
var (cs0, signature) = load_bits(begin_parse(in_msg), 512);
var (cs, msg_seqno) = load_uint(cs0, 32);
(cs, var valid_until) = load_uint(cs, 32);
throw_if(35, valid_until < now());
var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
(cs2, var stored_seqno) = load_uint(cs2, 32);
(cs2, var public_key) = load_uint(cs2, 256);
end_parse(cs2);
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
(cs, var param_index) = load_uint(cs, 32);
(cs, var param_value) = load_ref(cs);
end_parse(cs);
var cb = store_ref(begin_cell(), set_idict_ref(cfg_dict, 32, param_index, param_value));
cb = store_uint(cb, stored_seqno + 1, 32);
cb = store_uint(cb, public_key, 256);
set_data(end_cell(cb));
}

View file

@ -1,63 +0,0 @@
int now() pure asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond)
;; asm "THROWARGIF";
cell get_data() pure asm "c4 PUSH";
() set_data(cell c) asm "c4 POP";
() accept_message() asm "ACCEPT";
slice begin_parse(cell c) pure asm "CTOS";
() end_parse(slice s) asm "ENDS";
(slice, cell) load_ref(slice s) pure asm( -> 1 0) "LDREF";
(slice, int) zload_int(slice s, int len) pure asm(s len -> 1 0) "LDIX";
(slice, int) zload_uint(slice s, int len) pure asm( -> 1 0) "LDUX";
int zpreload_int(slice s, int len) pure asm "PLDIX";
int zpreload_uint(slice s, int len) pure asm "PLDUX";
(slice, slice) load_bits(slice s, int len) pure asm(s len -> 1 0) "LDSLICEX";
slice preload_bits(slice s, int len) pure asm "PLDSLICEX";
cell set_idict_ref(cell dict, int key_len, int index, cell value) pure asm(value index dict key_len) "DICTISETREF";
builder begin_cell() pure asm "NEWC";
builder store_ref(builder b, cell c) pure asm(c b) "STREF";
builder zstore_uint(builder b, int x, int len) pure asm(x b len) "STUX";
builder zstore_int(builder b, int x, int len) pure asm(x b len) "STIX";
cell end_cell(builder b) pure asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) {
;; do nothing for internal messages
}
() recv_external(cell in_msg) {
var (cs0, signature) = load_bits(begin_parse(in_msg), 512);
var (cs, msg_seqno) = zload_uint(cs0, 32);
(cs, var valid_until) = zload_uint(cs, 32);
throw_if(35, valid_until < now());
var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
(cs2, var stored_seqno) = zload_uint(cs2, 32);
(cs2, var public_key) = zload_uint(cs2, 256);
end_parse(cs2);
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
(cs, var param_index) = zload_uint(cs, 32);
(cs, var param_value) = load_ref(cs);
end_parse(cs);
;; cfg_dict = set_idict_ref(cfg_dict, 32, param_index, param_value);
;; var cb = begin_cell();
;; cb = store_ref(cb, cfg_dict);
var cb = store_ref(begin_cell(), set_idict_ref(cfg_dict, 32, param_index, param_value));
cb = zstore_uint(cb, stored_seqno + 1, 32);
cb = zstore_uint(cb, public_key, 256);
set_data(end_cell(cb));
}

View file

@ -1,62 +0,0 @@
int now() pure asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond)
;; asm "THROWARGIF";
cell get_data() pure asm "c4 PUSH";
() set_data(cell c) asm "c4 POP";
() accept_message() asm "ACCEPT";
slice begin_parse(cell c) pure asm "CTOS";
() end_parse(slice s) asm "ENDS";
(slice, cell) load_ref(slice s) pure asm( -> 1 0) "LDREF";
;; (slice, int) ~load_int(slice s, int len) pure asm(s len -> 1 0) "LDIX";
;; (slice, int) ~load_uint(slice s, int len) pure asm( -> 1 0) "LDUX";
;; int preload_int(slice s, int len) pure asm "PLDIX";
;; int preload_uint(slice s, int len) pure asm "PLDUX";
(slice, slice) load_bits(slice s, int len) pure asm(s len -> 1 0) "LDSLICEX";
slice preload_bits(slice s, int len) pure asm "PLDSLICEX";
cell set_idict_ref(cell dict, int key_len, int index, cell value) pure asm(value index dict key_len) "DICTISETREF";
(cell, ()) ~set_idict_ref(cell dict, int key_len, int index, cell value) pure asm(value index dict key_len) "DICTISETREF";
builder begin_cell() pure asm "NEWC";
builder store_ref(builder b, cell c) pure asm(c b) "STREF";
;; builder store_uint(builder b, int x, int len) pure asm(x b len) "STUX";
;; builder store_int(builder b, int x, int len) pure asm(x b len) "STIX";
cell end_cell(builder b) pure asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) {
;; do nothing for internal messages
}
() recv_external(cell in_msg) {
var cs = begin_parse(in_msg);
var signature = cs~load_bits(512);
var cs0 = cs;
int msg_seqno = cs~load_uint(32);
var valid_until = cs~load_uint(32);
throw_if(35, valid_until < now());
var cs2 = begin_parse(get_data());
var cfg_dict = cs2~load_ref();
var stored_seqno = cs2~load_uint(32);
var public_key = cs2~load_uint(256);
cs2.end_parse();
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
var param_index = cs~load_uint(32);
var param_value = cs~load_ref();
cs.end_parse();
cfg_dict~set_idict_ref(32, param_index, param_value);
set_data(begin_cell().store_ref(cfg_dict).store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
}

View file

@ -1,58 +0,0 @@
int now() pure asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond)
;; asm "THROWARGIF";
cell get_data() pure asm "c4 PUSH";
() set_data(cell c) asm "c4 POP";
() accept_message() asm "ACCEPT";
slice begin_parse(cell c) pure asm "CTOS";
() end_parse(slice s) asm "ENDS";
(slice, cell) load_ref(slice s) pure asm( -> 1 0) "LDREF";
;; (slice, int) load_int(slice s, int len) pure asm(s len -> 1 0) "LDIX";
;; (slice, int) load_uint(slice s, int len) pure asm( -> 1 0) "LDUX";
;; int .preload_int(slice s, int len) pure asm "PLDIX";
;; int .preload_uint(slice s, int len) pure asm "PLDUX";
(slice, slice) load_bits(slice s, int len) pure asm(s len -> 1 0) "LDSLICEX";
;; slice .preload_bits(slice s, int len) pure asm "PLDSLICEX";
cell set_idict_ref(cell dict, int key_len, int index, cell value) pure asm(value index dict key_len) "DICTISETREF";
builder begin_cell() pure asm "NEWC";
builder store_ref(builder b, cell c) pure asm(c b) "STREF";
;;builder .store_uint(builder b, int x, int len) pure asm(x b len) "STUX";
;;builder .store_int(builder b, int x, int len) pure asm(x b len) "STIX";
cell .end_cell(builder b) pure asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) {
;; do nothing for internal messages
}
() recv_external(cell in_msg) {
var (cs0, signature) = load_bits(begin_parse(in_msg), 512);
var (cs, msg_seqno) = load_uint(cs0, 32);
(cs, var valid_until) = load_uint(cs, 32);
throw_if(35, valid_until < now());
var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
(cs2, var stored_seqno) = load_uint(cs2, 32);
(cs2, var public_key) = load_uint(cs2, 256);
end_parse(cs2);
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
(cs, var param_index) = load_uint(cs, 32);
(cs, var param_value) = load_ref(cs);
end_parse(cs);
set_data(begin_cell().store_ref(cfg_dict.set_idict_ref(32, param_index, param_value))
.store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
}

View file

@ -1,20 +0,0 @@
;; inline test
_ unpack() inline {
var ds = get_data().begin_parse();
var res = (ds~load_uint(8), ds~load_int(32), ds~load_int(32));
return res;
}
() pack(a, x, y) inline_ref {
set_data(begin_cell()
.store_uint(a, 8)
.store_int(x, 32)
.store_int(y, 32)
.end_cell());
}
() main() {
var (a, x, y) = unpack();
x += y;
pack(a, x, y);
}

View file

@ -1,37 +0,0 @@
global int x, y, z;
global (cell, slice) y;
global ((int, int) -> int) op;
_ get() {
var t = z + 1;
return x;
}
_ pre_next() {
return x + 1;
}
() init() {
;; global x;
x = 0;
}
int next() {
;; global x;
return x += 1;
}
_ set_y(x, w) {
y = (w, x);
}
_ get_y() {
return y;
}
int main(int c) {
init();
c += next();
return c + pre_next();
}

View file

@ -1,10 +0,0 @@
global ((int, int) -> int) op;
int check_assoc(int a, int b, int c) {
return op(op(a, b), c) == op(a, op(b, c));
}
int main() {
op = _+_;
return check_assoc(2, 3, 9);
}

View file

@ -1,7 +0,0 @@
_ check_assoc(op, a, b, c) {
return op(op(a, b), c) == op(a, op(b, c));
}
int main() {
return check_assoc(_+_, 2, 3, 9);
}

View file

@ -1,55 +0,0 @@
const int1 = 1, int2 = 2;
const int int101 = 101;
const int int111 = 111;
const int1r = int1;
const str1 = "const1", str2 = "aabbcc"s;
const slice str2r = str2;
const str1int = 0x636f6e737431;
const str2int = 0xAABBCC;
const int nibbles = 4;
int iget1() { return int1; }
int iget2() { return int2; }
int iget3() { return int1 + int2; }
int iget1r() { return int1r; }
slice sget1() { return str1; }
slice sget2() { return str2; }
slice sget2r() { return str2r; }
const int int240 = ((int1 + int2) * 10) << 3;
int iget240() { return int240; }
builder newc() asm "NEWC";
slice endcs(builder b) asm "ENDC" "CTOS";
int sdeq (slice s1, slice s2) asm "SDEQ";
builder stslicer(builder b, slice s) asm "STSLICER";
_ main() {
int i1 = iget1();
int i2 = iget2();
int i3 = iget3();
throw_unless(int101, i1 == 1);
throw_unless(102, i2 == 2);
throw_unless(103, i3 == 3);
slice s1 = sget1();
slice s2 = sget2();
slice s3 = newc().stslicer(str1).stslicer(str2r).endcs();
throw_unless(int111, sdeq(s1, newc().store_uint(str1int, 12 * nibbles).endcs()));
throw_unless(112, sdeq(s2, newc().store_uint(str2int, 6 * nibbles).endcs()));
throw_unless(113, sdeq(s3, newc().store_uint(0x636f6e737431ABCDEF, 18 * nibbles).endcs()));
int i4 = iget240();
throw_unless(104, i4 == 240);
}

View file

@ -1,15 +0,0 @@
const int x = 5;
const slice s = "abacaba";
const int y = 3;
const slice s = "abacaba";
const int x = 5;
const int z = 4, z = 4;
int sdeq (slice s1, slice s2) asm "SDEQ";
() main() {
throw_unless(101, x == 5);
throw_unless(102, y == 3);
throw_unless(103, z == 4);
throw_unless(104, sdeq(s, "abacaba"));
}

View file

@ -1,24 +0,0 @@
const val1 = 123456789;
const val2 = 987654321;
const val3 = 135792468;
const val4 = 246813579;
const prec_and = val1 & val2;
const prec_or = val1 | val2;
const prec_xor = val1 ^ val2;
const prec_logic = ((val1 & val2) | val3) ^ val4;
const prec_nand = val1 & (~ val2);
int get_and() { return prec_and; }
int get_or() { return prec_or; }
int get_xor() { return prec_xor; }
int get_logic() { return prec_logic; }
int get_nand() { return prec_nand; }
_ main() {
throw_unless(101, get_and() == 39471121);
throw_unless(102, get_or() == 1071639989);
throw_unless(103, get_xor() == 1032168868);
throw_unless(104, get_logic() == 82599134);
throw_unless(105, get_nand() == 83985668);
}

View file

@ -1,16 +0,0 @@
global int i;
#include "i1sub1.fc";
() sub0() { i = 0; }
#include "i1sub2.fc";
() main() {
sub0();
sub1();
sub2();
i = 9;
}
#include "../test/i1sub2.fc";

View file

@ -1,8 +0,0 @@
;; DO NOT COMPILE DIRECTLY!
;; Compile i1.fc
#include "i1sub1.fc";
() sub1() {
i = 1;
}

View file

@ -1,10 +0,0 @@
;; DO NOT COMPILE DIRECTLY!
;; Compile i1.fc
#include "./i1sub1.fc";
() sub2() {
sub1();
sub0();
i = 2;
}

View file

@ -1,53 +0,0 @@
#pragma test-version-set "1.2.3";
;; Positive tests
#pragma version ^1.2.0;
#pragma version ^1.2.3;
#pragma version >1.2.0;
#pragma version >0.9.9;
#pragma version <1.3.0;
#pragma version <2.0.0;
#pragma version >=1.2.0;
#pragma version <=1.3.0;
#pragma version >=1.2.3;
#pragma version <=1.2.3;
#pragma version ^1.2.3;
#pragma version 1.2.3;
#pragma version =1.2.3;
;; Negative tests
#pragma not-version ^1.1.0;
#pragma not-version ^1.0.0;
#pragma not-version ^0.2.3;
#pragma not-version ^2.2.3;
#pragma not-version ^1.3.3;
#pragma not-version >1.2.3;
#pragma not-version <1.2.3;
#pragma not-version ^1.2.4;
#pragma not-version >=1.2.4;
#pragma not-version <=1.2.2;
#pragma not-version 3.2.1;
#pragma not-version =3.2.1;
;; Test incomplete (partial) version
#pragma version ^1.2;
#pragma version >1.2;
#pragma version <1.3;
#pragma version <2;
#pragma version >=1.2;
#pragma version <=1.3;
;; Advanced ^ behaviour (partials)
#pragma version ^1.2;
#pragma version ^1.0;
#pragma version ^1;
#pragma version ^0;
#pragma not-version ^1.0.0;
#pragma not-version ^0.0.0;
#pragma not-version ^0.0;
#pragma not-version ^1.3;
#pragma not-version ^2;
(int) main(int a) {
return a;
}

View file

@ -1,49 +0,0 @@
slice ascii_slice() method_id {
return "string";
}
slice raw_slice() method_id {
return "abcdef"s;
}
slice addr_slice() method_id {
return "Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF"a;
}
int string_hex() method_id {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"u;
}
int string_minihash() method_id {
return "transfer(slice, int)"h;
}
int string_maxihash() method_id {
return "transfer(slice, int)"H;
}
int string_crc32() method_id {
return "transfer(slice, int)"c;
}
builder newc() asm "NEWC";
slice endcs(builder b) asm "ENDC" "CTOS";
int sdeq (slice s1, slice s2) asm "SDEQ";
_ main() {
slice s_ascii = ascii_slice();
slice s_raw = raw_slice();
slice s_addr = addr_slice();
int i_hex = string_hex();
int i_mini = string_minihash();
int i_maxi = string_maxihash();
int i_crc = string_crc32();
throw_unless(101, sdeq(s_ascii, newc().store_uint(0x737472696E67, 12 * 4).endcs()));
throw_unless(102, sdeq(s_raw, newc().store_uint(0xABCDEF, 6 * 4).endcs()));
throw_unless(103, sdeq(s_addr, newc().store_uint(4, 3).store_int(-1, 8)
.store_uint(0x3333333333333333333333333333333333333333333333333333333333333333, 256).endcs()));
throw_unless(104, i_hex == 0x4142434445464748494A4B4C4D4E4F505152535455565758595A303132333435);
throw_unless(105, i_mini == 0x7a62e8a8);
throw_unless(106, i_maxi == 0x7a62e8a8ebac41bd6de16c65e7be363bc2d2cbc6a0873778dead4795c13db979);
throw_unless(107, i_crc == 2235694568);
}

View file

@ -1,26 +0,0 @@
slice test1() asm """
"Test" $>s
PUSHSLICE
""";
slice test2() asm """
"Hello"
" "
"World"
$+ $+ $>s
PUSHSLICE
""";
int sdeq (slice s1, slice s2) asm """SDEQ""";
int sdeq (slice s1, slice s2) asm "SDEQ" "";
int sdeq (slice s1, slice s2) asm "" """
SDEQ
""";
() main() {
slice s = test1();
throw_unless(101, sdeq(s, "Test"));
slice s = test2();
throw_unless(102, sdeq(s, "Hello World"));
}

View file

@ -1,113 +0,0 @@
() test1() {
int i = 3;
repeat (3) {
try {
int j = i;
i *= 2;
throw_unless(500, j <= 10);
} catch (x, e) {
i -= 2;
}
i += i + 1;
}
throw_unless(501, i == 43);
}
int divide_by_ten(int num) {
try {
throw_unless(500, num < 10);
} catch (x, e) {
return divide_by_ten(num - 10) + 1;
}
return 0;
}
() test2() {
int n = divide_by_ten(37);
throw_unless(502, n == 3);
}
(int, int) swap_int(int a, int b) {
try {
a = a * b;
b = a / b;
a = a / b;
return (a, b);
} catch (x, e) {
throw_unless(500, b == 0);
}
return (0, a);
}
() test3() {
int a = 0;
int b = 57;
try {
(a, b) = swap_int(a, b);
} catch (x, e) {
throw_unless(500, a == 0);
a = b;
b = 0;
}
throw_unless(503, (a == 57) & (b == 0));
}
int get_x(int x, int y) {
try {
} catch (x, e) {
return -1;
}
return x;
}
int get_y(int x, int y) {
try {
return -1;
} catch (x, e) {
}
return y;
}
() test4() {
throw_unless(504, get_x(3, 4) == 3);
throw_unless(504, get_y(3, 4) == -1);
}
(int, int, int, int, int) foo(int a, int b, int c, int d, int e) {
try {
throw(11);
} catch (x, y) {
a += 1;
b += 2;
c += 3;
d += 4;
e += 5;
}
return (a, b, c, d, e);
}
() test5() {
var (a, b, c, d, e) = foo(10, 20, 30, 40, 50);
throw_unless(505, (a == 11) & (b == 22) & (c == 33) & (d == 44) & (e == 55));
}
() test6() {
int a = 0;
int b = 0;
int c = 0;
try {
b = 3;
} catch (x, y) {
b = 12;
}
throw_unless(506, (a == 0) & (b == 3) & (c == 0));
}
() main() {
test1();
test2();
test3();
test4();
test5();
test6();
}

View file

@ -1,84 +0,0 @@
forall X -> int cast_to_int(X x) asm "NOP";
forall X -> builder cast_to_builder(X x) asm "NOP";
_ test1_body() {
int a = 3;
builder b = begin_cell();
int c = 1;
try {
c = 3;
throw_arg(b, 100);
} catch (x, y) {
return (a + c + y, cast_to_builder(x));
}
return (0, null());
}
() test1() {
var (x, y) = test1_body();
throw_unless(101, x == 104);
throw_unless(102, y.builder_refs() == y.builder_bits());
}
_ test2_body(int a, int b, int c) {
try {
try {
try {
try {
throw_arg_if(1, 201, a + b + c == 3);
throw_arg_if(2, 201, a == 3);
throw_arg_unless(1, 202, b == 4);
return 1;
} catch (y, x) {
int y = y.cast_to_int();
throw_arg_unless(y, x, x == 202);
throw_arg(y + 1, 200);
}
} catch (y, x) {
int y = y.cast_to_int();
throw_arg_if(y, x, x == 200);
throw_arg_if(y + 2, x, y < 2);
throw_arg_if(y + 3, 203, a + b + c == 4);
throw_arg_unless(y + 4, 204, b == 4);
return 3;
}
} catch (y, x) {
int y = y.cast_to_int();
try {
throw_arg_if(y, x, x == 200);
throw_arg_if(y + 1, 200, x == 201);
throw_arg_if(x - 203, 200, x == 202);
throw_arg_if(y, 200, x == 203);
throw_arg_if(a + 4, 205, a + b + c == 5);
throw_arg(7, 200);
} catch (v, u) {
int v = v.cast_to_int();
throw_arg_unless(v, u, u == 205);
if (c == 0) {
return b + 4;
}
throw_arg(v + 1, 200);
}
}
} catch (y, x) {
throw_unless(x, x == 200);
return y.cast_to_int();
}
return null();
}
() test2() {
throw_unless(201, test2_body(0, 4, 0) == 1);
throw_unless(202, test2_body(0, 5, 0) == 2);
throw_unless(203, test2_body(3, 4, 0) == 3);
throw_unless(204, test2_body(3, 0, 0) == 4);
throw_unless(205, test2_body(3, 1, 0) == 5);
throw_unless(206, test2_body(3, 2, 0) == 6);
throw_unless(207, test2_body(3, 1, 2) == 7);
throw_unless(208, test2_body(3, 1, 1) == 8);
}
() main() {
test1();
test2();
}

View file

@ -1,9 +0,0 @@
(int, int) nested_if(int id) method_id {
dump_stack();
if (id > 0) {
if (id > 10) {
return (2 * id, 3 * id);
}
}
return (5, 6);
}

View file

@ -1,14 +0,0 @@
_ f(cs) {
return (cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8),
cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8),
cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8),
cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8),
cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8));
}
_ main(cs) {
var (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,
x11, x12, x13, x14, x15, x16, x17, x18, x19) = f(cs);
return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
+ x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19;
}

View file

@ -1,13 +0,0 @@
() main(cs) {
int i = 0;
if (cs.slice_refs()) {
do {
i = i + 1;
} until(i > 10);
}
set_data(begin_cell()
.store_uint(1, 32)
.store_uint(2, 32)
.store_uint(i, 32)
.end_cell());
}

View file

@ -1,13 +0,0 @@
_ main(cell dict, int t3) {
int index = -1;
do {
(index, slice value, int found) = dict.udict_get_next?(32, index);
if (found) {
(int temp1, int temp2) = (value~load_uint(16), value~load_uint(32));
if (t3 > temp2) {
dict~udict_delete_get?(32, index);
}
}
} until ( ~ found);
return dict;
}

View file

@ -1,14 +0,0 @@
(cell) recv_external(slice in_msg) {
cell mydict = new_dict();
builder r = begin_cell().store_int(10, 16);
mydict~udict_set_builder(32, 1, r );
int index = -1;
do {
(var index, var value, var found) = mydict.udict_get_next?(32, index);
} until ( ~ found );
return mydict;
}
() recv_internal() {
;; Nothing
}

View file

@ -1,12 +0,0 @@
int test(int x) method_id {
int i = 0;
;; int f = false;
do {
i = i + 1;
if (i > 5) {
return 1;
}
int f = (i * i == 64);
} until (f);
return -1;
}

View file

@ -1,14 +0,0 @@
int test(int y) {
int x = 1;
if (y > 0) {
return 1;
}
return x > 0;
}
int f(int y) {
if (y > 0) {
return 1;
}
return 2;
}

View file

@ -1,22 +0,0 @@
int check_signatures(msg_hash, signatures, signers, bitmask_size) {
var bitmask = 0;
var id = -1;
do {
(id, var signature, var f) = signatures.udict_get_next?(32, id);
if (f){
var sig = signature.preload_bits(512);
var public_key = -1;
do {
(public_key, var cs, var _found) = signers.udict_get_next?(256, public_key);
if (_found){
if (check_signature(msg_hash, sig, public_key)){
var signer_index = cs~load_uint(bitmask_size);
bitmask = bitmask | (1 << (signer_index - 1));
}
}
} until (~ _found);
;; signature~touch();
}
} until (~ f);
return bitmask;
}

View file

@ -1,8 +0,0 @@
_ g(s) {
var (z, t) = (17, s);
while (z > 0) {
t = s;
z -= 1;
}
return ~ t;
}