Skip to content

Commit

Permalink
Work on list endings
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 11, 2020
1 parent b4a71cb commit e7a4d6a
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 6 deletions.
3 changes: 1 addition & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
#### Other:
- `length`, `sum`, `max`, `lat?`
#### Eventual features:
- I'll get to division and floating-point arithmetic sometime soon.
- The same goes for symbols, printing lists, and higher-order functions.
- I'll get to division and floating-point arithmetic, and symbol print names sometime soon.
- If I have time I would like to implement a pattern-matching system and an ability to call C functions.

### Miscellaneous:
Expand Down
1 change: 0 additions & 1 deletion lib/lib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
(begin
(display_char #\()
(_display_list x)))

;;;;;
(define (_length lst counter)
(if (null? lst) counter
Expand Down
159 changes: 157 additions & 2 deletions tests/test.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,168 @@
_main:
call _begin_gc
and rsp, -16 # begin garbage collector
push 1 # push argument to type_exception
call type_exception
push 13 # push argument to cons
push 12 # push argument to cons
call cons
add rsp, 16 # discard 2 local arguments
push rax # result of cons
push 11 # push argument to cons
call cons
add rsp, 16 # discard 2 local arguments
mov [seq + rip], rax
push [seq + rip] # push global variable
jmp after_anonymous_1
anonymous_1:
push rbp
mov rbp, rsp
push [rbp + 16] # push argument to *
push [rbp + 16] # push argument to *
call multiply
add rsp, 16 # discard 2 local arguments
mov rbp, rsp
pop rbp
ret
after_anonymous_1:
lea rax, [anonymous_1 + rip]
push rax
call map
add rsp, 16 # discard 2 local arguments
mov [result + rip], rax
push [result + rip] # push global variable
call display_list
add rsp, 8 # discard 1 local argument
and rsp, -16
call _end_gc # end garbage collector
xor rdi, rdi
mov rax, 0x2000001
syscall
list?:
push rbp
mov rbp, rsp
push [rbp + 16] # push argument to atom?
call atom?
add rsp, 8 # discard 1 local argument
push rax # result of atom?
call bool_not
mov rsp, rbp
pop rbp
ret
_display_list:
push rbp
mov rbp, rsp
push [rbp + 16] # push argument to null?
call null?
add rsp, 8 # discard 1 local argument
cmp rax, 1 # is true?
je true_1 # true branch
jmp false_2 # false branch
true_1:
push '' # push argument to display_char
call display_char
add rsp, 8 # discard 1 local argument
push ')' # push argument to display_char
call display_char
add rsp, 8 # discard 1 local argument
mov rax, 0
jmp end_3
false_2:
push [rbp + 16] # push argument to car
call car
add rsp, 8 # discard 1 local argument
push rax # result of car
call list?
add rsp, 8 # discard 1 local argument
cmp rax, 1 # is true?
je true_4 # true branch
jmp false_5 # false branch
true_4:
push '(' # push argument to display_char
call display_char
add rsp, 8 # discard 1 local argument
push [rbp + 16] # push argument to car
call car
add rsp, 8 # discard 1 local argument
push rax # result of car
call _display_list
add rsp, 8 # discard 1 local argument
push rax # result of _display_list
jmp end_6
false_5:
push [rbp + 16] # push argument to car
call car
add rsp, 8 # discard 1 local argument
push rax # result of car
call display_num
add rsp, 8 # discard 1 local argument
jmp end_6
end_6:
push ' ' # push argument to display_char
call display_char
add rsp, 8 # discard 1 local argument
push [rbp + 16] # push argument to cdr
call cdr
add rsp, 8 # discard 1 local argument
push rax # result of cdr
call _display_list
add rsp, 8 # discard 1 local argument
push rax # result of _display_list
jmp end_3
end_3:
mov rsp, rbp
pop rbp
ret
display_list:
push rbp
mov rbp, rsp
push '(' # push argument to display_char
call display_char
add rsp, 8 # discard 1 local argument
push [rbp + 16] # push argument to _display_list
call _display_list
add rsp, 8 # discard 1 local argument
push rax # result of _display_list
mov rsp, rbp
pop rbp
ret
map:
push rbp
mov rbp, rsp
push [rbp + 24] # push argument to null?
call null?
add rsp, 8 # discard 1 local argument
cmp rax, 1 # is true?
je true_7 # true branch
jmp false_8 # false branch
true_7:
mov rax, [rbp + 24]
jmp end_9
false_8:
push [rbp + 24] # push argument to cdr
call cdr
add rsp, 8 # discard 1 local argument
push rax # result of cdr
push [rbp + 16] # push argument to map
call map
add rsp, 16 # discard 2 local arguments
push rax # result of map
push [rbp + 24] # push argument to car
call car
add rsp, 8 # discard 1 local argument
push rax # result of car
mov rsi, [rbp + 16]
call rsi
add rsp, 8 # discard 1 local argument
push rax # result of [rbp + 16]
call cons
add rsp, 16 # discard 2 local arguments
jmp end_9
end_9:
mov rsp, rbp
pop rbp
ret

.data
seq:
.quad 0
result:
.quad 0
25 changes: 24 additions & 1 deletion tests/test.lisp
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
(type_exception 1)
(define (list? x) (not (atom? x)))

(define (_display_list x)
(if (null? x) (begin (display_char #\backspace) (display_char #\)) 0)
(begin
(if (list? (car x))
(begin (display_char #\() (_display_list (car x)))
(display_num (car x)))
(display_char #\space)
(_display_list (cdr x)))))

(define (display_list x)
(begin
(display_char #\()
(_display_list x)))


(define (map proc lst)
(if (null? lst) lst; what indicates an ending?
(cons (proc (car lst)) (map proc (cdr lst)))))

(define seq (cons 11 (cons 12 13)))
(define result (map (lambda (x) (* x x)) seq))
(display_list result)

0 comments on commit e7a4d6a

Please sign in to comment.