Skip to content

Commit

Permalink
integrate CPS into compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed May 11, 2012
1 parent f30ae56 commit 8a3f40b
Show file tree
Hide file tree
Showing 11 changed files with 1,626 additions and 421 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
boot
.#*
.#*
prog*
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ backends/js.js: backends/js.ol
test.js: test.ol
$(NODE_MAKE) _current_runtime _with_eval test.ol > test2.js && mv test2.js test.js

cps.js: cps.ol
$(NODE_MAKE) _current_runtime _with_eval cps.ol > cps2.js && mv cps2.js cps.js

runtime.js: runtime.ol
$(NODE_MAKE) _no_runtime runtime.ol > runtime2.js && mv runtime2.js runtime.js

compiler: runtime.js compiler.js reader.js ast.js backends/js.js test.js
compiler: runtime.js compiler.js reader.js ast.js backends/js.js test.js cps.js

test: compiler
node test syntax.ol
Expand Down
262 changes: 136 additions & 126 deletions backends/js.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions backends/js.ol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
(if (not expr?)
(begin
(write (str "; "
"// Line " (ast.node-lineno node)
" Column " (ast.node-colno node))
;; Turn this off while playing with CPS
;; "// Line " (ast.node-lineno node)
;; " Column " (ast.node-colno node)
)
#t)))))

(define (write-number obj expr?)
Expand Down
573 changes: 294 additions & 279 deletions compiler.js

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions compiler.ol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
(require (reader "./reader")
(ast "./ast")
(js "./backends/js")

;; remove this
(fs "fs"))
(cps "./cps"))

(define (self-evaluating? exp)
(or (number? exp)
Expand Down Expand Up @@ -247,7 +245,7 @@
(cons (tco bottom exit)
(cdr rexprs))))
(else
(if (tco? bottom)
(if (and (tco? bottom) #f)
(reverse
(cons `(vector "__tco_call" (lambda () ,bottom))
(cdr rexprs)))
Expand Down Expand Up @@ -296,7 +294,7 @@
;; ,@vars) after it didn't work
,@(list-append
(generate-defs syms forms)
(if (tco-call? name tco-ed)
(if (and (tco-call? name tco-ed) #f)
`((trampoline (,name ,@syms)))
`((,name ,@syms)))))))))))

Expand Down Expand Up @@ -556,13 +554,14 @@
(let ((exp (if (string? src)
(reader.read src)
(sourcify src 0 0))))
(if (and (ast.type? exp 'LIST)
(== (ast.first* exp) 'begin))
;; parse top-level forms individually
(for-each (lambda (e)
(compile (expand e) generator))
(cdr (ast.node-data exp)))
(compile (expand exp) generator))
(let ((src (desourcify (expand exp))))
;; We need to expand again after CPS because it generates a few
;; begin's
(let ((src (expand (sourcify
(list 'cps-trampoline
((cps.cps src) cps-halt))))))
;;(pp (desourcify src))
(compile src generator)))
(generator.get-code)))

(set! module.exports {:read (lambda (e) (desourcify (reader.read e)))
Expand Down
Loading

0 comments on commit 8a3f40b

Please sign in to comment.