From dd8d005e5a5845278c72cd454e358e3599cf7f7a Mon Sep 17 00:00:00 2001 From: janis Date: Sun, 5 Jul 2026 05:15:46 +0200 Subject: [PATCH] fixup makefile, fix parse_cur_token --- stages/lisp0/Makefile | 23 +++++++++++++---------- stages/lisp0/lisp1.asm | 33 ++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/stages/lisp0/Makefile b/stages/lisp0/Makefile index 216c00f..a5b3d31 100644 --- a/stages/lisp0/Makefile +++ b/stages/lisp0/Makefile @@ -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 diff --git a/stages/lisp0/lisp1.asm b/stages/lisp0/lisp1.asm index a7851db..be73194 100644 --- a/stages/lisp0/lisp1.asm +++ b/stages/lisp0/lisp1.asm @@ -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: