mirror of
https://github.com/egormanga/Slang.git
synced 2025-07-31 17:06:58 +03:00
Latest changes back from 2021, before starting from scratch.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#| Slang `class' test. |#
|
||||
|
||||
class Test {
|
||||
int a = 1
|
||||
|
||||
@@ -9,29 +11,27 @@ class Test {
|
||||
.a = 5
|
||||
}
|
||||
|
||||
constr (int a) {
|
||||
.a = a
|
||||
}
|
||||
constr (int .a);
|
||||
}
|
||||
|
||||
main {
|
||||
stdio.println(Test.a)
|
||||
stdio.println(Test.a) # 1
|
||||
|
||||
Test t
|
||||
stdio.println(t.a)
|
||||
stdio.println(t.a) # 3
|
||||
t.a = 2
|
||||
stdio.println(t.a)
|
||||
stdio.println(t.a) # 2
|
||||
delete t
|
||||
|
||||
Test t = Test()
|
||||
stdio.println(t.a)
|
||||
stdio.println(t.a) # 5
|
||||
delete t
|
||||
|
||||
Test t = Test(7)
|
||||
stdio.println(t.a)
|
||||
stdio.println(t.a) # 7
|
||||
delete t
|
||||
|
||||
#Test t(10)
|
||||
#stdio.println(t.a)
|
||||
#stdio.println(t.a) # 10
|
||||
#delete t
|
||||
}
|
||||
|
7
tests/colonkw.sl
Normal file
7
tests/colonkw.sl
Normal file
@@ -0,0 +1,7 @@
|
||||
#| Slang `colonkw' test. |#
|
||||
|
||||
int a(int y) = y
|
||||
|
||||
main {
|
||||
a(y: 3)
|
||||
}
|
7
tests/divzero.sl
Normal file
7
tests/divzero.sl
Normal file
@@ -0,0 +1,7 @@
|
||||
#| Slang `divzero' test. |#
|
||||
|
||||
main {
|
||||
u8 a = 1
|
||||
u8 b = 0
|
||||
stdio.println(a/b)
|
||||
}
|
8
tests/each.sl
Normal file
8
tests/each.sl
Normal file
@@ -0,0 +1,8 @@
|
||||
#| Slang `each' test. |#
|
||||
|
||||
main {
|
||||
list l = [int: 1, 2, 3]
|
||||
l.each(stdio.println)
|
||||
|
||||
[int: 4, 5].each(stdio.println)
|
||||
}
|
@@ -2,24 +2,24 @@
|
||||
#| and that is a
|
||||
multiline one. |#
|
||||
|
||||
const u32 n = 123123 # n is of type const u32
|
||||
const i64 m = 10**18 # m is of type const i64
|
||||
const int z = 2**128 # z is of type const int (unsized)
|
||||
const auto q = 2**256 # q is of type const int
|
||||
const u32 n = 123123 # n: const u32 (unsigned 32 bit)
|
||||
const i64 m = 10**18 # m: const i64 (signed 64 bit)
|
||||
const int z = 2**128 # z: const int (signed unsized)
|
||||
const auto q = 2**256 # q: const int (signed unsized)
|
||||
|
||||
char f(str x) { # f() is of type char, x is of type str
|
||||
auto c = x[1] # c is of type char
|
||||
return c
|
||||
char f(str x) { # f(): char, x: str
|
||||
auto c = x[1] # c: char
|
||||
return c # char
|
||||
}
|
||||
|
||||
auto g(str x) { # g() is of type char, x is of type str
|
||||
return x[0] # retval is of type char
|
||||
auto g(str x) { # g(): char, x: str
|
||||
return x[0] # char
|
||||
}
|
||||
|
||||
int h(int x) = x+1 # h() is of type int, x is of type int
|
||||
int h(int x) = x+1 # h(): int, x: int
|
||||
|
||||
main {
|
||||
stdio.println(h(n), \ # comment here too
|
||||
f('123asd') + g('32') + 1) #--> «123124 f»
|
||||
stdio.println(q/z/2**96) #--> «4294967296.0»
|
||||
stdio.println(q/z/2**96) #--> «4294967296.0»
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#| Slang `fib' test. |#
|
||||
|
||||
int fib(int n) {
|
||||
if (n < 2) {return 1}
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#| Slang `for' test. |#
|
||||
|
||||
main {
|
||||
for i in (0 to 5) {
|
||||
stdio.println(i)
|
||||
|
@@ -1,2 +1,4 @@
|
||||
#| Slang `funcdef' test. |#
|
||||
|
||||
void f() {}
|
||||
void f(int a?) {}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#| Slang `list' test. |#
|
||||
|
||||
list l = [int: 1, 2, 3]
|
||||
|
||||
main {
|
||||
@@ -7,4 +9,6 @@ main {
|
||||
stdio.println(i, l[i])
|
||||
#i -=- 1
|
||||
}
|
||||
for i in l stdio.println(i)
|
||||
stdio.println(l, *l)
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#| Slang `map' test. |#
|
||||
|
||||
void f(int x) = stdio.println(x)
|
||||
|
||||
main {
|
5
tests/nestedcomm.sl
Normal file
5
tests/nestedcomm.sl
Normal file
@@ -0,0 +1,5 @@
|
||||
#| Slang `nestedcomm' test. |#
|
||||
|
||||
#| test #| a |#|#
|
||||
main { #a
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
#| Slang `nl' test. |#
|
||||
|
||||
main {
|
||||
stdio.println(1, #|
|
||||
|# 2)
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,16 @@
|
||||
#| Slang `opti' test. |#
|
||||
|
||||
int a = 3
|
||||
|
||||
void f() {a = 5}
|
||||
void g() {a += 2+2}
|
||||
|
||||
main {
|
||||
stdio.println(2**a)
|
||||
stdio.println(a)
|
||||
a = 4
|
||||
stdio.println(a)
|
||||
f()
|
||||
stdio.println(a)
|
||||
g()
|
||||
stdio.println(a)
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
#| Slang `overload' test. |#
|
||||
|
||||
int f(int x) = x+1
|
||||
int f(int x, int y) = x+y+1
|
||||
|
||||
main {
|
||||
stdio.println(f(1))
|
||||
stdio.println(f(1, 2))
|
||||
f()
|
||||
}
|
||||
|
@@ -1,3 +1,8 @@
|
||||
#| Slang `println' test. |#
|
||||
|
||||
main {
|
||||
stdio.println('test')
|
||||
stdio.println(3)
|
||||
}
|
||||
|
||||
stdio.println(5)
|
||||
stdio.println(5)
|
||||
|
5
tests/range.sl
Normal file
5
tests/range.sl
Normal file
@@ -0,0 +1,5 @@
|
||||
#| Slang `range' test. |#
|
||||
|
||||
main {
|
||||
stdio.println(1 to 3)
|
||||
}
|
@@ -1,6 +1,8 @@
|
||||
#| Slang `redefine' test. |#
|
||||
|
||||
main {
|
||||
int a
|
||||
a = 3
|
||||
a, b := (int a, char 'b')
|
||||
stdio.println(a, b)
|
||||
}
|
||||
}
|
||||
|
16
tests/scope.sl
Normal file
16
tests/scope.sl
Normal file
@@ -0,0 +1,16 @@
|
||||
#| Slang `scope' test. |#
|
||||
|
||||
int a = 3
|
||||
|
||||
int g() = 5
|
||||
|
||||
int f() {
|
||||
int a = 4
|
||||
int g = g()
|
||||
return a+g
|
||||
}
|
||||
|
||||
main {
|
||||
int a = f()
|
||||
stdio.println(a)
|
||||
}
|
@@ -1,3 +1,5 @@
|
||||
#| Slang `strcat' test. |#
|
||||
|
||||
str a = "a"
|
||||
str b = "B"
|
||||
str c = a+b
|
||||
|
@@ -1,4 +1,6 @@
|
||||
i8 a = 3
|
||||
i8 b = 5
|
||||
i8 c = a+b
|
||||
#| Slang `sum' test. |#
|
||||
|
||||
i64 a = 97
|
||||
i64 b = 5
|
||||
i64 c = a+b
|
||||
stdio.println(c)
|
||||
|
@@ -1,5 +1,9 @@
|
||||
#| Slang `test' test. |#
|
||||
|
||||
const int a = 3
|
||||
int b = 2; int c = 0; int x = 9
|
||||
int b = 2
|
||||
int c = 0
|
||||
int x = 9
|
||||
|
||||
int sum(int a, int z) = a + z
|
||||
stdio.println(sum(a, b & 3))
|
||||
@@ -8,7 +12,7 @@ stdio.println(1, 2)
|
||||
stdio.println('a')
|
||||
stdio.println(2*(3)+-2*(5+1)/2)
|
||||
stdio.println(-2*x**(2+2)*a*b+10*c)
|
||||
stdio.println(*'a'+'b'*2)
|
||||
stdio.println(*"a"+"b"*2)
|
||||
stdio.println(-2-2-2-2-2-2-2-2)
|
||||
|
||||
main {
|
||||
@@ -20,9 +24,10 @@ main {
|
||||
int test() = 2*2
|
||||
stdio.println(sum(b, test()))
|
||||
|
||||
for i in 0 to 5 stdio.println(i)
|
||||
else stdio.println(0)
|
||||
for i in (0 to 5): stdio.println(i)
|
||||
else: stdio.println(0)
|
||||
|
||||
int i = 5
|
||||
while i {stdio.println(i); i -= 1;} else stdio.println('ВСЁ!')
|
||||
while i: stdio.println(i); i -= 1
|
||||
else: stdio.println('ВСЁ!')
|
||||
}
|
||||
|
6
tests/tuple.sl
Normal file
6
tests/tuple.sl
Normal file
@@ -0,0 +1,6 @@
|
||||
#| Slang `tuple' test. |#
|
||||
|
||||
main {
|
||||
tuple a = (int 1, str "test")
|
||||
stdio.println(a, *a)
|
||||
}
|
@@ -1 +1,3 @@
|
||||
int _a_b_
|
||||
#| Slang `underscore' test. |#
|
||||
|
||||
int _a_b_
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#| Slang `wrongnl' test. |#
|
||||
|
||||
main {
|
||||
stdio.println(1, \ 2,
|
||||
3)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user