Files
l2/tests/integration_core.sl

177 lines
2.2 KiB
Plaintext
Raw Normal View History

2026-01-08 13:15:27 +01:00
import ../stdlib/stdlib.sl
import ../stdlib/io.sl
2025-12-06 16:30:58 +01:00
2025-12-06 17:24:30 +01:00
:asm mem-slot {
lea rax, [rel print_buf]
sub r12, 8
mov [r12], rax
}
;
macro square
dup *
;
macro defconst 2
2026-02-18 09:45:13 +01:00
word $0
$1
end
;
macro defadder 3
2026-02-18 09:45:13 +01:00
word $0
$1 $2 +
end
;
defconst MAGIC 99
defadder add13 5 8
2026-01-21 14:26:30 +01:00
struct Point
field x 8
field y 8
2026-01-21 14:26:30 +01:00
end
word test-add
2025-12-19 20:23:26 +01:00
5 7 + puti cr
end
2025-12-06 16:30:58 +01:00
word test-sub
2025-12-19 20:23:26 +01:00
10 3 - puti cr
end
2025-12-06 16:30:58 +01:00
word test-mul
2025-12-19 20:23:26 +01:00
6 7 * puti cr
end
2025-12-06 16:30:58 +01:00
word test-div
2025-12-19 20:23:26 +01:00
84 7 / puti cr
end
2025-12-06 16:30:58 +01:00
word test-mod
2025-12-19 20:23:26 +01:00
85 7 % puti cr
end
2025-12-06 16:30:58 +01:00
word test-drop
2025-12-19 20:23:26 +01:00
10 20 drop puti cr
end
2025-12-06 16:30:58 +01:00
word test-dup
2025-12-19 20:23:26 +01:00
11 dup + puti cr
end
2025-12-06 16:30:58 +01:00
word test-swap
2025-12-19 20:23:26 +01:00
2 5 swap - puti cr
end
2025-12-06 16:30:58 +01:00
word test-store
2025-12-06 17:24:30 +01:00
mem-slot dup
123 !
2025-12-19 20:23:26 +01:00
@ puti cr
end
2025-12-06 17:24:30 +01:00
word test-mmap
2025-12-06 17:24:30 +01:00
0 # addr hint (NULL)
4096 # length (page)
3 # prot (PROT_READ | PROT_WRITE)
34 # flags (MAP_PRIVATE | MAP_ANON)
-1 # fd (ignored for MAP_ANON)
0 # offset
mmap
dup
1337 !
2025-12-06 17:24:30 +01:00
dup
2025-12-19 20:23:26 +01:00
@ puti cr
2025-12-06 17:24:30 +01:00
4096 munmap drop
end
2025-12-06 17:24:30 +01:00
word test-macro
2025-12-19 20:23:26 +01:00
9 square puti cr
MAGIC puti cr
add13 puti cr
end
word test-if
5 5 == if
2025-12-19 20:23:26 +01:00
111 puti cr
else
2025-12-19 20:23:26 +01:00
222 puti cr
2026-01-03 09:04:50 +00:00
end
end
word test-else-if
2
dup 1 == if
2025-12-19 20:23:26 +01:00
50 puti cr
else
dup 2 == if
2025-12-19 20:23:26 +01:00
60 puti cr
else
2025-12-19 20:23:26 +01:00
70 puti cr
2026-01-03 09:04:50 +00:00
end
end
drop
end
word test-for
0
5 for
1 +
2026-01-03 09:04:50 +00:00
end
2025-12-19 20:23:26 +01:00
puti cr
end
word test-for-zero
123
0 for
drop
2026-01-03 09:04:50 +00:00
end
2025-12-19 20:23:26 +01:00
puti cr
end
word test-struct
mem-slot
dup 111 ! # Point.x = 111
dup 8 + 222 ! # Point.y = 222
dup @ puti cr # print Point.x
dup 8 + @ puti cr # print Point.y
2025-12-19 20:23:26 +01:00
Point.size puti cr
end
word test-cmp
2025-12-19 20:23:26 +01:00
5 5 == puti cr
5 4 == puti cr
5 4 != puti cr
4 4 != puti cr
3 5 < puti cr
5 3 < puti cr
5 3 > puti cr
3 5 > puti cr
5 5 <= puti cr
6 5 <= puti cr
5 5 >= puti cr
4 5 >= puti cr
end
word main
2025-12-06 16:30:58 +01:00
test-add
test-sub
test-mul
test-div
test-mod
test-drop
test-dup
test-swap
2025-12-06 17:24:30 +01:00
test-store
test-mmap
test-macro
test-if
test-else-if
test-for
test-for-zero
test-cmp
test-struct
2025-12-06 16:30:58 +01:00
0
end