Skip to content

Commit

Permalink
Let bindings are technically done, but until lambdas can capture thei…
Browse files Browse the repository at this point in the history
…r environment they will not work
  • Loading branch information
Your Name committed Nov 16, 2020
1 parent c1728b8 commit 037e7ca
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#### `lambda`
- Constructs an anonymous function with two parts: a parameter list and a body. Here's an example: `(lambda (x y) (+ x y))`

#### `let`
- These are a work in progress.

#### `quote`
- Converts a string into a compile-time constant hash that can be used for quick comparisons via `eq?`. The resulting symbol is uninterned and has no print name.

Expand Down
2 changes: 1 addition & 1 deletion src/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def main(infile, outfile, extern):
Working on right now:
- finding a new GC or providing other flags to make it behave differently?
- printing nil from display_list
- let bindings?
- let bindings
Function val error:
(define nums (cons 1 (cons 2 3)))
Expand Down
7 changes: 7 additions & 0 deletions tests/bugs.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
(begin
(display_char #\()
(_display_list x)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Incorrect results:
(define (g a) (let ((b 3) (c 4)) (* a (* b c))))
(display (g 2))
(newline)

(define (f a) ((lambda (b c) (* a (* b c))) 3 4))
(display (f 2)); weird! both are wrong. both are 36 when they should be 24.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 changes: 1 addition & 6 deletions tests/test.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ f:
anonymous_1:
push rbp
mov rbp, rsp
push [rbp + 24] # push argument to *
push [rbp + 16] # push argument to *
call multiply
add rsp, 16 # discard 2 local arguments
push rax # result of *
push [rbp + 16] # push argument to *
call multiply
add rsp, 16 # discard 2 local arguments
Expand All @@ -35,10 +31,9 @@ f:
ret
after_anonymous_1:
lea rax, [anonymous_1 + rip]
push 4 # push argument to rax
push 3 # push argument to rax
call rax
add rsp, 16 # discard 2 local arguments
add rsp, 8 # discard 1 local argument
mov rsp, rbp
pop rbp
ret
Expand Down
15 changes: 11 additions & 4 deletions tests/test.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(define (f a)
(let ((b 3) (c 4))
(* a (* b c))))
(display (f 2)); wrong result! is 36, should be
|
(define (g a) (let ((b 3)) (* a b)))
(display (g 2))
(newline)
|

(define (f a) ((lambda (b) (* a b)) 3))
(display (f 2)); Weird! Both are wrong. Both are 9 when they should be 6.
; For this to work, that lambda has to be able to capture its surrounding environment.
; 1. How would it do that?
; 2. What is making it behave not as expected right now? (or why is it squaring the first argument?)

0 comments on commit 037e7ca

Please sign in to comment.