mem helpers and # comment support

This commit is contained in:
IgorCielniak
2025-12-06 17:24:30 +01:00
parent 8e8faf3c91
commit 643a4960c2
3 changed files with 82 additions and 1 deletions

View File

@@ -58,7 +58,13 @@ class Reader:
token_start = 0
token_line = 1
token_column = 0
for char in source:
source_len = len(source)
while index < source_len:
char = source[index]
if char == "#":
while index < source_len and source[index] != "\n":
index += 1
continue
if char.isspace():
if lexeme:
yield Token(

View File

@@ -109,6 +109,50 @@ puts_finish_digits:
}
;
:asm @ {
mov rax, [r12]
mov rax, [rax]
mov [r12], rax
}
;
:asm ! {
mov rax, [r12]
add r12, 8
mov rbx, [r12]
mov [rax], rbx
add r12, 8
}
;
:asm mmap {
mov r9, [r12]
add r12, 8
mov r8, [r12]
add r12, 8
mov r10, [r12]
add r12, 8
mov rdx, [r12]
add r12, 8
mov rsi, [r12]
add r12, 8
mov rdi, [r12]
mov rax, 9
syscall
mov [r12], rax
}
;
:asm munmap {
mov rsi, [r12]
add r12, 8
mov rdi, [r12]
mov rax, 11
syscall
mov [r12], rax
}
;
:asm exit {
mov rdi, [r12]
add r12, 8

31
test.sl
View File

@@ -1,5 +1,12 @@
import stdlib.sl
:asm mem-slot {
lea rax, [rel print_buf]
sub r12, 8
mov [r12], rax
}
;
: test-add
5 7 + puts
;
@@ -32,6 +39,28 @@ import stdlib.sl
2 5 swap - puts
;
: test-store
mem-slot dup
123 swap !
@ puts
;
: test-mmap
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 swap !
dup
@ puts
4096 munmap drop
;
: main
test-add
test-sub
@@ -41,5 +70,7 @@ import stdlib.sl
test-drop
test-dup
test-swap
test-store
test-mmap
0
;