fixup makefile, fix parse_cur_token

This commit is contained in:
janis 2026-07-05 05:15:46 +02:00
parent 26c219a2f7
commit dd8d005e5a
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8
2 changed files with 33 additions and 23 deletions

View file

@ -1,20 +1,23 @@
test.bin: lisp.rs lisp.o # test.bin: lisp.rs lisp.o
rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp.o --edition=2024 --test -g $< -o $@ # rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp.o --edition=2024 --test -g $< -o $@
lisp.o: lisp.asm # lisp.o: lisp.asm
nasm -g -f elf64 -o lisp.o lisp.asm # nasm -g -f elf64 -o lisp.o lisp.asm
test: test.bin # test: test.bin
./test.bin # ./test.bin
test1.bin: test.rs lisp1.o test.bin: test.rs lisp1.o
rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp1.o --edition=2024 --test -g $< -o $@ rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp1.o --edition=2024 --test -g $< -o $@
lisp1.o: lisp1.asm lisp1.o: lisp1.asm
nasm -g -f elf64 -o lisp1.o lisp1.asm nasm -g -f elf64 -o lisp1.o lisp1.asm
test1: test1.bin test: test.bin
./test1.bin --nocapture --test-threads=1 ./test.bin --nocapture --test-threads=1
lisp1: lisp1.o
ld -m elf_x86_64 -e _interp_entry -o lisp1 lisp1.o
clean: clean:
rm -f lisp.o test.bin lisp1.o test1.bin rm -f lisp.o test.bin lisp1.o test1.bin lisp1

View file

@ -682,6 +682,7 @@ global parse_next_token
parse_next_token: parse_next_token:
call next_token call next_token
parse_cur_token: parse_cur_token:
mov al, byte [rel buf]
cmp al, `(` cmp al, `(`
je parse_list je parse_list
cmp al, `'` cmp al, `'`
@ -794,6 +795,7 @@ parse_num:
.done: .done:
cmp byte [r12], 0 cmp byte [r12], 0
setz al setz al
movzx eax, al
lea rcx, [rel buf] lea rcx, [rel buf]
sub r12, rcx ; r12 = length of the number string sub r12, rcx ; r12 = length of the number string
mul r12 mul r12
@ -803,20 +805,24 @@ parse_num:
ret ret
parse_atom: parse_atom:
call parse_num sub rsp, 8
test al, al
jz .not_num
mov rdi, rdx
call make_num
ret
.not_num:
lea rdi, [rel buf] lea rdi, [rel buf]
call strlen call strlen
push rax mov qword [rsp], rax
mov rdi, rax
call parse_num
cmp qword [rsp], rax
jne .not_num
mov rdi, rdx
call make_num
add rsp, 8
ret
.not_num:
mov rdi, qword [rsp] ; len
mov rsi, 1 mov rsi, 1
call heap_alloc call heap_alloc
pop rdx ; len mov rdx, qword [rsp] ; len
push rax ; data push rax ; data
push rdx ; len push rdx ; len
lea rdi, [rel buf] lea rdi, [rel buf]
@ -827,6 +833,7 @@ parse_atom:
pop rsi ; len pop rsi ; len
pop rdi ; data pop rdi ; data
call make_atom call make_atom
add rsp, 8
ret ret
@ -3346,7 +3353,7 @@ _interp_entry:
lea rbx, [rsp + 8] lea rbx, [rsp + 8]
mov edi, 1 mov edi, 1
cmp eax, 2 cmp eax, 2
jle .init_ifile jl .init_ifile
mov rdi, qword [rbx + 8] ; argv[1] mov rdi, qword [rbx + 8] ; argv[1]
call open_file call open_file
mov edi, eax ; fd mov edi, eax ; fd
@ -3355,14 +3362,14 @@ _interp_entry:
call init_env call init_env
sub rsp, 8 sub rsp, 8
mov qword [rsp], rsi ; env mov qword [rsp], rax ; env
.loop: .loop:
call parse_next_token call parse_next_token
test eax, eax test eax, eax
jz .done jz .done
mov rdi, rax mov rdi, rax
mov rsp, qword [rsp] ; env mov rsi, qword [rsp] ; env
call eval call eval
jmp .loop jmp .loop
.done: .done: