cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 3b32d180b16c08bfd861879efbc90a7e9d323884
Author: Ian Price <[email protected]>
AuthorDate: Sun Jun 7 16:58:41 2015 +0100
Simple inlining of immediate calls
---
module/language/js-il/compile-javascript.scm | 2 ++
module/language/js-il/direct.scm | 36 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/module/language/js-il/compile-javascript.scm
b/module/language/js-il/compile-javascript.scm
index fb5ed5e..a0427cc 100644
--- a/module/language/js-il/compile-javascript.scm
+++ b/module/language/js-il/compile-javascript.scm
@@ -2,9 +2,11 @@
#:use-module (ice-9 match)
#:use-module ((language js-il) #:renamer (symbol-prefix-proc 'il:))
#:use-module (language javascript)
+ #:use-module (language js-il direct)
#:export (compile-javascript))
(define (compile-javascript exp env opts)
+ (set! exp (remove-immediate-calls exp))
(values (compile-exp exp) env env))
(define *scheme* (make-id "scheme"))
diff --git a/module/language/js-il/direct.scm b/module/language/js-il/direct.scm
new file mode 100644
index 0000000..6e97e3e
--- /dev/null
+++ b/module/language/js-il/direct.scm
@@ -0,0 +1,36 @@
+(define-module (language js-il direct)
+ #:use-module (ice-9 match)
+ #:use-module (language js-il)
+ #:export (remove-immediate-calls))
+
+(define (remove-immediate-calls exp)
+ (match exp
+ (($ program entry body)
+ (make-program (remove-immediate-calls entry)
+ (map remove-immediate-calls body)))
+
+ (($ continuation params body)
+ (make-continuation params (remove-immediate-calls body)))
+
+ (($ function name params body)
+ (make-function name params (remove-immediate-calls body)))
+
+ (($ local
+ (($ var id ($ continuation () body)))
+ ($ continue id ()))
+ (remove-immediate-calls body))
+
+ (($ local
+ (($ var id ($ continuation (arg) body)))
+ ($ continue id (val)))
+ (make-local (list (make-var arg val))
+ (remove-immediate-calls body)))
+
+ (($ local bindings body)
+ (make-local (map remove-immediate-calls bindings)
+ (remove-immediate-calls body)))
+
+ (($ var id exp)
+ (make-var id (remove-immediate-calls exp)))
+
+ (exp exp)))