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
|
|
|
|
|
2024-05-03 13:48:10 -05:00
|
|
|
; Load first char
|
2024-05-03 12:24:03 -05:00
|
|
|
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
|
|
|
|
|
2024-05-03 13:48:10 -05:00
|
|
|
; loop :skull:
|
2024-05-03 12:24:03 -05:00
|
|
|
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:
|
2024-05-03 12:43:04 -05:00
|
|
|
jmp log_lisp_error
|
2024-05-03 12:24:03 -05:00
|
|
|
|
|
|
|
eval_stack:
|
2024-05-03 12:43:04 -05:00
|
|
|
jmp log_lisp_error
|
2024-05-03 12:24:03 -05:00
|
|
|
|
|
|
|
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:
|
2024-05-03 12:43:04 -05:00
|
|
|
.db "'"
|
|
|
|
|
|
|
|
log_lisp_error:
|
|
|
|
li64 r1, 3
|
|
|
|
li64 r2, 1
|
|
|
|
lra16 r3, r0, lisp_error
|
|
|
|
li64 r4, 32
|
|
|
|
eca
|
|
|
|
tx
|
|
|
|
|
|
|
|
lisp_error:
|
|
|
|
.db "Some sort of error has occured."
|
|
|
|
.db 0
|