[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 33/99: Change program type representation
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 33/99: Change program type representation |
Date: |
Sun, 10 Oct 2021 21:50:51 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit a7b2dfa5810a8e027dfc149c1c173b3023dcc0ec
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Sat Jun 20 22:41:24 2015 +0100
Change program type representation
---
module/language/cps/compile-js.scm | 25 +++++++++++++------------
module/language/js-il.scm | 9 ++++++---
module/language/js-il/compile-javascript.scm | 14 +++++++++++---
module/language/js-il/inlining.scm | 24 ++++++++++++------------
4 files changed, 42 insertions(+), 30 deletions(-)
diff --git a/module/language/cps/compile-js.scm
b/module/language/cps/compile-js.scm
index 69cb91c..c1de2bc 100644
--- a/module/language/cps/compile-js.scm
+++ b/module/language/cps/compile-js.scm
@@ -18,32 +18,33 @@
(set! exp (reify-primitives exp))
(set! exp (renumber exp))
(match exp
- (($ $program funs)
+ (($ $program (($ $cont ks funs) ...))
;; TODO: I should special case the compilation for the initial fun,
;; as this is the entry point for the program, and shouldn't get a
;; "self" argument, for now, I add "undefined" as the first
;; argument in the call to it.
;; see compile-exp in (language js-il compile-javascript)
- (values (make-program (compile-fun (car funs))
- (map compile-fun (cdr funs)))
+ (values (make-program
+ (map (lambda (k fun)
+ (cons (make-kid k) (compile-fun fun)))
+ ks
+ funs))
env
env))))
(define (compile-fun fun)
(match fun
- (($ $cont k ($ $kfun _ _ self ($ $cont tail ($ $ktail)) clause))
+ (($ $kfun _ _ self ($ $cont tail ($ $ktail)) clause)
(call-with-values
(lambda ()
(extract-clauses self clause))
(lambda (jump-table clauses)
- (make-var
- (make-kid k)
- (make-function
- (make-id self) (make-kid tail)
- (make-local (map (lambda (clause)
- (compile-clause clause self tail))
- clauses)
- (make-jump-table jump-table)))))))))
+ (make-function
+ (make-id self) (make-kid tail)
+ (make-local (map (lambda (clause)
+ (compile-clause clause self tail))
+ clauses)
+ (make-jump-table jump-table))))))))
(define (extract-clauses self clause)
(define (make-params* self req opts rest kw allow-other-keys?)
diff --git a/module/language/js-il.scm b/module/language/js-il.scm
index 31b4749..8eb26a3 100644
--- a/module/language/js-il.scm
+++ b/module/language/js-il.scm
@@ -51,7 +51,7 @@
(define (print-js exp port)
(format port "#<js-il ~S>" (unparse-js exp)))
-(define-js-type program entry body)
+(define-js-type program body)
(define-js-type function self tail body)
(define-js-type jump-table spec)
(define-js-type params self req opt rest kw allow-other-keys?)
@@ -71,8 +71,11 @@
(define (unparse-js exp)
(match exp
- (($ program entry body)
- `(program ,(unparse-js entry) . ,(map unparse-js body)))
+ (($ program body)
+ `(program . ,(map (match-lambda
+ ((($ kid k) . fun)
+ (cons k (unparse-js fun))))
+ body)))
(($ continuation params body)
`(continuation ,(map unparse-js params) ,(unparse-js body)))
(($ function self tail body)
diff --git a/module/language/js-il/compile-javascript.scm
b/module/language/js-il/compile-javascript.scm
index 44384c6..7d9140d 100644
--- a/module/language/js-il/compile-javascript.scm
+++ b/module/language/js-il/compile-javascript.scm
@@ -118,15 +118,23 @@
(define (compile-exp exp)
;; TODO: handle ids for js
(match exp
- (($ il:program (and entry ($ il:var name _)) body)
+ (($ il:program ((name . fun) (names . funs) ...))
(let ((entry-call
(make-return
(make-call (compile-id name)
(list
(make-id "undefined")
(make-refine *scheme* (make-const
"initial_cont")))))))
- (make-call (make-function '() (append (map compile-exp body)
- (list (compile-exp entry)
entry-call)))
+ (make-call (make-function
+ '()
+ (append
+ (map (lambda (id f)
+ (make-var (rename-id id)
+ (compile-exp f)))
+ (cons name names)
+ (cons fun funs))
+
+ (list entry-call)))
'())))
(($ il:continuation params body)
diff --git a/module/language/js-il/inlining.scm
b/module/language/js-il/inlining.scm
index f042966..14e25bd 100644
--- a/module/language/js-il/inlining.scm
+++ b/module/language/js-il/inlining.scm
@@ -20,9 +20,8 @@
arg-list))
(define (analyse exp)
(match exp
- (($ program entry body)
- (analyse entry)
- (for-each analyse body))
+ (($ program ((ids . funs) ...))
+ (for-each analyse funs))
(($ function self tail body)
(analyse body))
@@ -192,14 +191,15 @@
(make-var id (make-continuation params (inline body '()))))))
bindings))
(match fun
- (($ var id ($ function self tail ($ local bindings ($ jump-table spec))))
- (make-var id
- (make-function self
- tail
- (make-local (handle-bindings bindings)
- (make-jump-table spec)))))))
+ (($ function self tail ($ local bindings ($ jump-table spec)))
+ (make-function self
+ tail
+ (make-local (handle-bindings bindings)
+ (make-jump-table spec))))))
(match exp
- (($ program entry body)
- (make-program (handle-function entry)
- (map handle-function body)))))
+ (($ program ((ids . funs) ...))
+ (make-program (map (lambda (id fun)
+ (cons id (handle-function fun)))
+ ids
+ funs)))))
- [Guile-commits] 16/99: Remove superfluous space, (continued)
- [Guile-commits] 16/99: Remove superfluous space, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 20/99: Implement keyword argument parsing, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 12/99: Compile string constants, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 13/99: Mangle js identifiers, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 15/99: Handle case-lambda via a jump table, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 19/99: Simplify output Javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 21/99: Primitives should return Scheme Booleans, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 23/99: Compile cps $prompt form to javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 26/99: abort-to-prompt takes multiple arguments, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 34/99: Change function type representation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 33/99: Change program type representation,
Christopher Allan Webber <=
- [Guile-commits] 31/99: Different types for Continuation and Variable identifiers, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 29/99: Use scheme.frame.Prompt objects for prompts on dynstack, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 30/99: Implement fluid primitives, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 36/99: Handle more identifier characters, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 47/99: Add some primitives to runtime.js, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 50/99: Add more variables to no-values-primitives, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 55/99: Implement immediate version of vector primitives., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 62/99: scm_struct_init skips hidden fields., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 59/99: Implement built-in string procedures., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 60/99: Implement struct built-ins., Christopher Allan Webber, 2021/10/10