1
0
Fork 0
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:
tolk-vm 2024-10-31 11:11:41 +04:00
parent 5a3e3595d6
commit e2edadba92
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
133 changed files with 8196 additions and 2605 deletions

85
tolk-tester/tests/a6.tolk Normal file
View file

@ -0,0 +1,85 @@
fun f(a: int, b: int, c: int, d: int, e: int, f: int): (int, int) {
// solve a 2x2 linear equation
var D: int = a*d - b*c;;;; var Dx: int = e*d-b*f ;;;; var Dy: int = a * f - e * c;
return (Dx/D,Dy/D);
};;;;
fun mulDivR(x: int, y: int, z: int): int { return muldivr(x, y, z); }
fun calc_phi(): int {
var n = 1;
repeat (70) { n*=10; };
var p= 1;
var `q`=1;
do {
(p,q)=(q,p+q);
} while (q <= n); //;;
return mulDivR(p, n, q);
}
fun calc_sqrt2(): int {
var n = 1;
repeat (70) { n *= 10; }
var p = 1;
var q = 1;
do {
var t = p + q;
(p, q) = (q, t + q);
} while (q <= n);
return mulDivR(p, n, q);
}
fun calc_root(m: auto): auto {
var base: int=1;
repeat(70) { base *= 10; }
var (a, b, c) = (1,0,-m);
var (p1, q1, p2, q2) = (1, 0, 0, 1);
do {
var k: int=-1;
var (a1, b1, c1) = (0, 0, 0);
do {
k+=1;
(a1, b1, c1) = (a, b, c);
c+=b;
c += b += a;
} while (c <= 0);
(a, b, c) = (-c1, -b1, -a1);
(p1, q1) = (k * p1+q1, p1);
(p2, q2) = (k * p2+q2, p2);
} while (p1 <= base);
return (p1, q1, p2, q2);
}
fun ataninv(base: int, q: int): int { // computes base*atan(1/q)
base=base~/q;
q*=-q;
var sum: int = 0;
var n: int = 1;
do {
sum += base~/n;
base = base~/q;
n += 2;
} while (base != 0);
return sum;
}
fun arctanInv(base: int, q: int): int { return ataninv(base, q); }
fun calc_pi(): int {
var base: int = 64;
repeat (70) { base *= 10; }
return (arctanInv(base << 2, 5) - arctanInv(base, 239))~>>4;
}
fun calcPi(): int { return calc_pi(); }
fun main(): int {
return calcPi();
}
/**
method_id | in | out
@testcase | 0 | | 31415926535897932384626433832795028841971693993751058209749445923078164
@code_hash 84337043972311674339187056298873613816389434478842780265748859098303774481976
*/