adjusting the generated code so it waits until the runtime is ready.
This commit is contained in:
parent
5238d2b389
commit
837fdf480d
3
Makefile
3
Makefile
|
@ -9,6 +9,9 @@ test-all:
|
|||
raco make -v --disable-inline tests/test-all.rkt
|
||||
racket tests/test-all.rkt
|
||||
|
||||
test-browser-evaluate:
|
||||
raco make -v --disable-inline tests/test-browser-evaluate.rkt
|
||||
racket tests/test-browser-evaluate.rkt
|
||||
|
||||
test-compiler:
|
||||
raco make -v --disable-inline tests/test-compiler.rkt
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
[(EnvPrefixReference? target)
|
||||
(assemble-prefix-reference target)]
|
||||
[(PrimitivesReference? target)
|
||||
(format "MACHINE.primitives[~s]" (symbol->string (PrimitivesReference-name target)))]
|
||||
(format "RUNTIME.Primitives[~s]" (symbol->string (PrimitivesReference-name target)))]
|
||||
[(ControlFrameTemporary? target)
|
||||
(assemble-control-frame-temporary target)]
|
||||
[(ModulePrefixTarget? target)
|
||||
|
|
|
@ -1278,7 +1278,44 @@
|
|||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
(function(scope) {
|
||||
scope.ready = function(f) {
|
||||
if (runtimeIsReady) {
|
||||
notifyWaiter(f);
|
||||
} else {
|
||||
readyWaiters.push(f);
|
||||
}
|
||||
};
|
||||
scope.setReadyTrue = function() {
|
||||
var i;
|
||||
runtimeIsReady = true;
|
||||
for (i = 0; i < readyWaiters.length; i++) {
|
||||
notifyWaiter(readyWaiters[i]);
|
||||
}
|
||||
readyWaiters = [];
|
||||
};
|
||||
|
||||
var runtimeIsReady = false;
|
||||
var readyWaiters = [];
|
||||
var notifyWaiter = function(w) {
|
||||
setTimeout(w, 0);
|
||||
};
|
||||
})(this);
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
// Exports
|
||||
exports['Primitives'] = Primitives;
|
||||
|
||||
exports['ready'] = ready;
|
||||
// Private: the runtime library will set this flag to true when
|
||||
// the library has finished loading.
|
||||
exports['setReadyTrue'] = setReadyTrue;
|
||||
|
||||
|
||||
exports['Machine'] = Machine;
|
||||
exports['Frame'] = Frame;
|
||||
exports['CallFrame'] = CallFrame;
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
"quote-cdata.rkt"
|
||||
"../make.rkt"
|
||||
"../make-structs.rkt"
|
||||
"get-runtime.rkt"
|
||||
(prefix-in runtime: "get-runtime.rkt")
|
||||
(prefix-in racket: racket/base))
|
||||
|
||||
|
||||
|
||||
(provide package
|
||||
package-anonymous
|
||||
package-standalone-xhtml)
|
||||
package-standalone-xhtml
|
||||
get-code
|
||||
get-runtime)
|
||||
|
||||
;; Packager: produce single .js files to be included to execute a
|
||||
;; program. Follows module dependencies.
|
||||
|
@ -36,7 +38,7 @@
|
|||
;; indicates whether we should continue following module paths.
|
||||
;;
|
||||
;; The generated output defines a function called 'invoke' with
|
||||
;; four arguments (MACHINE, SUCCESS, FAIL, PARAMS). When called, it'll
|
||||
;; four arguments (MACHINE, SUCCESS, FAIL, PARAMS). When called, it will
|
||||
;; execute the code to either run standalone expressions or
|
||||
;; load in modules.
|
||||
(define (package source-code
|
||||
|
@ -62,13 +64,15 @@
|
|||
|
||||
|
||||
(fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {")
|
||||
(make (cons only-bootstrapped-code
|
||||
(list (make-MainModuleSource source-code)))
|
||||
(fprintf op " plt.runtime.ready(function() {")
|
||||
(make (list (make-MainModuleSource source-code))
|
||||
packaging-configuration)
|
||||
(fprintf op " });");
|
||||
(fprintf op "});\n"))
|
||||
|
||||
|
||||
|
||||
|
||||
;; package-standalone-xhtml: X output-port -> void
|
||||
(define (package-standalone-xhtml source-code op)
|
||||
(display *header* op)
|
||||
|
@ -78,6 +82,35 @@
|
|||
|
||||
|
||||
|
||||
;; get-runtime: -> string
|
||||
(define (get-runtime)
|
||||
(let* ([buffer (open-output-string)]
|
||||
[packaging-configuration
|
||||
(make-Configuration
|
||||
;; should-follow?
|
||||
(lambda (p) #t)
|
||||
;; on
|
||||
(lambda (ast stmts)
|
||||
(assemble/write-invoke stmts buffer)
|
||||
(fprintf buffer "(MACHINE, function() { "))
|
||||
|
||||
;; after
|
||||
(lambda (ast stmts)
|
||||
(fprintf buffer " }, FAIL, PARAMS);"))
|
||||
|
||||
;; last
|
||||
(lambda ()
|
||||
(fprintf buffer "SUCCESS();")))])
|
||||
|
||||
(display (runtime:get-runtime) buffer)
|
||||
|
||||
(fprintf buffer "(function(MACHINE, SUCCESS, FAIL, PARAMS) {")
|
||||
(make (list only-bootstrapped-code) packaging-configuration)
|
||||
(fprintf buffer "})(new plt.runtime.Machine(), function(){ plt.runtime.setReadyTrue(); }, function(){}, {});\n")
|
||||
(get-output-string buffer)))
|
||||
|
||||
|
||||
|
||||
|
||||
(define *header*
|
||||
#<<EOF
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#lang racket
|
||||
(require "browser-evaluate.rkt"
|
||||
"../js-assembler/get-runtime.rkt"
|
||||
"../js-assembler/package.rkt"
|
||||
"../make-structs.rkt")
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#lang racket
|
||||
(require "browser-evaluate.rkt"
|
||||
"../js-assembler/package.rkt"
|
||||
"../js-assembler/get-runtime.rkt"
|
||||
"../make-structs.rkt"
|
||||
racket/port
|
||||
racket/runtime-path)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#lang racket
|
||||
(require "browser-evaluate.rkt"
|
||||
"../js-assembler/package.rkt"
|
||||
"../js-assembler/get-runtime.rkt"
|
||||
"../make-structs.rkt"
|
||||
racket/port
|
||||
racket/runtime-path
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
racket/string
|
||||
racket/path
|
||||
"make-structs.rkt"
|
||||
"js-assembler/package.rkt"
|
||||
"js-assembler/get-runtime.rkt")
|
||||
"js-assembler/package.rkt")
|
||||
|
||||
|
||||
;; Usage:
|
||||
|
@ -20,14 +19,25 @@
|
|||
;; * Print out the runtime library to standard output.
|
||||
;;
|
||||
;; $ whalesong get-runtime
|
||||
;;
|
||||
;;
|
||||
;; * Print out the JavaScript for the program.
|
||||
;;
|
||||
;; $ whalesong get-javascript main-module-name.rkt
|
||||
|
||||
|
||||
|
||||
;; TODO: error trapping
|
||||
(define commands `((build
|
||||
,(lambda (args)
|
||||
(do-the-build args)))
|
||||
(get-runtime
|
||||
,(lambda (args)
|
||||
(print-the-runtime)))))
|
||||
(print-the-runtime)))
|
||||
(get-javascript
|
||||
,(lambda (args)
|
||||
(get-javascript-code (first args))))))
|
||||
|
||||
|
||||
;; listof string
|
||||
(define command-names (map (lambda (x) (symbol->string (car x)))
|
||||
|
@ -78,6 +88,11 @@
|
|||
(define (print-the-runtime)
|
||||
(display (get-runtime)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (get-javascript-code filename)
|
||||
(display (get-code (make-ModuleSource (build-path filename)))))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user