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
rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp.o --edition=2024 --test -g $< -o $@
# test.bin: lisp.rs lisp.o
# rustc -Clink-arg=-fuse-ld=mold -Clink-arg=lisp.o --edition=2024 --test -g $< -o $@
lisp.o: lisp.asm
nasm -g -f elf64 -o lisp.o lisp.asm
# lisp.o: lisp.asm
# nasm -g -f elf64 -o lisp.o lisp.asm
test: test.bin
./test.bin
# test: 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 $@
lisp1.o: lisp1.asm
nasm -g -f elf64 -o lisp1.o lisp1.asm
test1: test1.bin
./test1.bin --nocapture --test-threads=1
test: test.bin
./test.bin --nocapture --test-threads=1
lisp1: lisp1.o
ld -m elf_x86_64 -e _interp_entry -o lisp1 lisp1.o
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:
call next_token
parse_cur_token:
mov al, byte [rel buf]
cmp al, `(`
je parse_list
cmp al, `'`
@ -794,6 +795,7 @@ parse_num:
.done:
cmp byte [r12], 0
setz al
movzx eax, al
lea rcx, [rel buf]
sub r12, rcx ; r12 = length of the number string
mul r12
@ -803,20 +805,24 @@ parse_num:
ret
parse_atom:
call parse_num
test al, al
jz .not_num
mov rdi, rdx
call make_num
ret
.not_num:
sub rsp, 8
lea rdi, [rel buf]
call strlen
push rax
mov rdi, rax
mov qword [rsp], 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
call heap_alloc
pop rdx ; len
mov rdx, qword [rsp] ; len
push rax ; data
push rdx ; len
lea rdi, [rel buf]
@ -827,6 +833,7 @@ parse_atom:
pop rsi ; len
pop rdi ; data
call make_atom
add rsp, 8
ret
@ -3346,7 +3353,7 @@ _interp_entry:
lea rbx, [rsp + 8]
mov edi, 1
cmp eax, 2
jle .init_ifile
jl .init_ifile
mov rdi, qword [rbx + 8] ; argv[1]
call open_file
mov edi, eax ; fd
@ -3355,14 +3362,14 @@ _interp_entry:
call init_env
sub rsp, 8
mov qword [rsp], rsi ; env
mov qword [rsp], rax ; env
.loop:
call parse_next_token
test eax, eax
jz .done
mov rdi, rax
mov rsp, qword [rsp] ; env
mov rsi, qword [rsp] ; env
call eval
jmp .loop
.done: