kludging the call/cc code in
This commit is contained in:
parent
b01bb3bc85
commit
dfe91d23e6
|
@ -38,7 +38,14 @@ EOF
|
|||
;; fracture: (listof stmt) -> (listof basic-block)
|
||||
(: fracture ((Listof Statement) -> (Listof BasicBlock)))
|
||||
(define (fracture stmts)
|
||||
(let* ([first-block-label (make-label 'start)]
|
||||
(let* ([first-block-label (if (and (not (empty? stmts))
|
||||
(symbol? (first stmts)))
|
||||
(first stmts)
|
||||
(make-label 'start))]
|
||||
[stmts (if (and (not (empty? stmts))
|
||||
(symbol? (first stmts)))
|
||||
(rest stmts)
|
||||
stmts)]
|
||||
[jump-targets
|
||||
(cons first-block-label (collect-general-jump-targets stmts))])
|
||||
(let: loop : (Listof BasicBlock)
|
||||
|
|
11
package.rkt
11
package.rkt
|
@ -16,10 +16,21 @@
|
|||
|
||||
;; package: s-expression output-port -> void
|
||||
(define (package source-code op)
|
||||
|
||||
;; The support code for call/cc
|
||||
(for-each (lambda (code)
|
||||
(displayln code op))
|
||||
(map assemble-basic-block
|
||||
(fracture (statements
|
||||
(make-call/cc-code)))))
|
||||
|
||||
;; The runtime code
|
||||
(call-with-input-file* runtime.js
|
||||
(lambda (ip)
|
||||
(copy-port ip op)))
|
||||
|
||||
(newline op)
|
||||
|
||||
(fprintf op "var invoke = ")
|
||||
(assemble/write-invoke (compile (parse source-code)
|
||||
'val
|
||||
|
|
42
runtime.js
42
runtime.js
|
@ -10,6 +10,24 @@
|
|||
|
||||
// No error trapping at the moment.
|
||||
|
||||
|
||||
var Frame = function(label, proc) {
|
||||
this.label = label;
|
||||
this.proc = proc;
|
||||
};
|
||||
|
||||
|
||||
// A closure consists of its free variables as well as a label
|
||||
// into its text segment.
|
||||
var Closure = function(label, arity, closedVals, displayName) {
|
||||
this.label = label;
|
||||
this.arity = arity;
|
||||
this.closedVals = closedVals;
|
||||
this.displayName = displayName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
var Primitives = (function() {
|
||||
var NULL = [];
|
||||
return {
|
||||
|
@ -128,30 +146,16 @@ var Primitives = (function() {
|
|||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||
return firstArg - 1;
|
||||
}
|
||||
// ,
|
||||
// 'call/cc': new Closure(callCCEntry,
|
||||
// 1,
|
||||
// [],
|
||||
// "call/cc")
|
||||
,
|
||||
'call/cc': new Closure(callCCEntry,
|
||||
1,
|
||||
[],
|
||||
"call/cc")
|
||||
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
var Frame = function(label, proc) {
|
||||
this.label = label;
|
||||
this.proc = proc;
|
||||
};
|
||||
|
||||
|
||||
// A closure consists of its free variables as well as a label
|
||||
// into its text segment.
|
||||
var Closure = function(label, arity, closedVals, displayName) {
|
||||
this.label = label;
|
||||
this.arity = arity;
|
||||
this.closedVals = closedVals;
|
||||
this.displayName = displayName;
|
||||
};
|
||||
|
||||
|
||||
// // adaptToJs: closure -> (array (X -> void) -> void)
|
||||
|
|
|
@ -5,5 +5,4 @@
|
|||
"test-compiler.rkt"
|
||||
"test-assemble.rkt"
|
||||
"test-browser-evaluate.rkt"
|
||||
"test-package.rkt"
|
||||
)
|
||||
"test-package.rkt")
|
|
@ -4,6 +4,7 @@
|
|||
"browser-evaluate.rkt"
|
||||
"parse.rkt"
|
||||
"il-structs.rkt"
|
||||
"compile.rkt"
|
||||
racket/port
|
||||
racket/promise
|
||||
racket/runtime-path)
|
||||
|
@ -41,7 +42,16 @@
|
|||
[code
|
||||
(string-append
|
||||
"(function() { "
|
||||
|
||||
;; The support code for call/cc
|
||||
(string-join (map assemble-basic-block
|
||||
(fracture (statements
|
||||
(make-call/cc-code))))
|
||||
"\n")
|
||||
|
||||
runtime
|
||||
|
||||
|
||||
"return function(success, fail, params){" snippet
|
||||
(format "success(String(~a)); };" inspector)
|
||||
"});")])
|
||||
|
@ -57,6 +67,14 @@
|
|||
[inspector (cdr a-statement+inspector)])
|
||||
|
||||
(display "(function() { " op)
|
||||
|
||||
(display
|
||||
(string-join (map assemble-basic-block
|
||||
(fracture (statements
|
||||
(make-call/cc-code))))
|
||||
"\n")
|
||||
op)
|
||||
|
||||
(display runtime op)
|
||||
|
||||
(display "var myInvoke = " op)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
(require "package.rkt")
|
||||
|
||||
(define (test s-exp)
|
||||
(package s-exp (current-output-port)))
|
||||
(package s-exp (open-output-string) #;(current-output-port)))
|
||||
|
||||
|
||||
(test '(define (factorial n)
|
||||
|
|
Loading…
Reference in New Issue
Block a user