Permalink
Browse files

integrate CPS into compiler

  • Loading branch information...
1 parent f30ae56 commit 8a3f40bdf9debdc0843de7ba189438ca6dfb93b8 @jlongster committed May 11, 2012
Showing with 1,626 additions and 421 deletions.
  1. +2 −1 .gitignore
  2. +4 −1 Makefile
  3. +136 −126 backends/js.js
  4. +4 −2 backends/js.ol
  5. +294 −279 compiler.js
  6. +11 −12 compiler.ol
  7. +916 −0 cps.js
  8. +223 −0 cps.ol
  9. +11 −0 runtime-defs.ol
  10. +10 −0 runtime.js
  11. +15 −0 runtime.ol
View
@@ -1,2 +1,3 @@
boot
-.#*
+.#*
+prog*
View
@@ -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
View
Oops, something went wrong.
View
@@ -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?)
View
Oops, something went wrong.
View
@@ -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)
@@ -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)))
@@ -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)))))))))))
@@ -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)))
Oops, something went wrong.

0 comments on commit 8a3f40b

Please sign in to comment.