lasp/lasp.S

81 lines
1.4 KiB
ArmAsm
Raw Normal View History

2024-05-03 12:24:03 -05:00
; r12 will be the char of the value of the current ptr
li64 r12, 0
; r13 will be the offset into the lisp_expr label
li64 r13, 0
;; r253 will be the offset from the stack pointer specified by the spec to be r254
li64 r253, 0
ldr r12, r13, lisp, 1
loop:
; zero r15
li64 r15, 0
; Check if the char is a (
li64 r15, 0x28
; if equal jump to open_paren
jeq r12, r15, open_paren
; check if the char is )
li64 r15, 0x29
; if equal jump to closed_paren
jeq r12, r15, closed_paren
; move the char into r2
cp r2, r12
; push the char onto the stack
jmp push_u64_stack
jmp loop
tx
;; push r2 into the stack
push_u64_stack:
;; store r2 -> r254 + r253 with size 8
st r2, r254, r253, 8
li64 r252, 8
add64 r253, r253, r252
jmp inc_ptr_ld_char
;; pop the head of the stack into r2
pop_u64_stack:
;; load r2 <- r254 + r253 with size 8
ld r2, r254, r253, 8
li64 r252, 8
sub64 r253, r253, r252
; jmp inc_ptr_ld_char
inc_ptr_ld_char:
; inc ptr
addi64 r13, r13, 1
; load next char
ldr r12, r13, lisp, 1
jmp loop
open_paren:
jmp inc_ptr_ld_char
closed_paren:
un
eval_stack:
jmp pop_u64_stack
jmp panic
panic:
tx
lisp:
.db "(+ 1 2 3 4 5 6 7 8 9 10)"
.db "(define a (λ () (+ 1 2 3)))"
.db "(a)"
builtin_lambda:
.db "λ"
builtin_quote:
.db "'"