From 91c2460a23f3428d54f842ccdc8058cf75f09560 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 8 Jul 2011 13:20:29 -0400 Subject: [PATCH] in the middle of fixing require for js-implemented modules --- ...le-world-program.rkt => image-program.rkt} | 2 +- js-assembler/package.rkt | 62 ++++++++++++++----- js-assembler/runtime-src/runtime.js | 1 + make/make-structs.rkt | 3 +- make/make.rkt | 42 +++++++------ tests/test-all.rkt | 2 +- 6 files changed, 76 insertions(+), 36 deletions(-) rename examples/{simple-world-program.rkt => image-program.rkt} (65%) diff --git a/examples/simple-world-program.rkt b/examples/image-program.rkt similarity index 65% rename from examples/simple-world-program.rkt rename to examples/image-program.rkt index 3405f84..38bc50d 100644 --- a/examples/simple-world-program.rkt +++ b/examples/image-program.rkt @@ -1,5 +1,5 @@ #lang planet dyoo/whalesong -(require (planet dyoo/whalesong/world)) +(require (planet dyoo/whalesong/image)) (display "hello again") (newline) diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index ab4a3f0..8abe816 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -10,6 +10,7 @@ "../parser/path-rewriter.rkt" "../parser/parse-bytecode.rkt" racket/match + racket/list (prefix-in query: "../lang/js/query.rkt") (planet dyoo/closure-compile:1:1) (prefix-in runtime: "get-runtime.rkt") @@ -106,32 +107,65 @@ (log-debug "~a requires ~a" (ModuleSource-path src) module-requires) + (let ([module-body-text + (format " + if(--MACHINE.callsBeforeTrampoline<0) { throw arguments.callee; } + var modrec = MACHINE.modules[~s]; + var exports = {}; + modrec.isInvoked = true; + (function(MACHINE, RUNTIME, EXPORTS){~a})(MACHINE, plt.runtime, exports); + ~a + return MACHINE.control.pop().label(MACHINE);" + (symbol->string name) + text + (get-provided-name-code bytecode))]) + (make-UninterpretedSource (format " MACHINE.modules[~s] = new plt.runtime.ModuleRecord(~s, function(MACHINE) { - if(--MACHINE.callsBeforeTrampoline<0) { throw arguments.callee; } - var modrec = MACHINE.modules[~s]; - var exports = {}; - modrec.isInvoked = true; - (function(MACHINE, RUNTIME, EXPORTS){~a})(MACHINE, plt.runtime, exports); - // FIXME: we need to inject the namespace with the values defined in exports. - ~a - return MACHINE.control.pop().label(MACHINE); + ~a }); " - (symbol->string name) - (symbol->string name) - (symbol->string name) - text - (get-provided-name-code bytecode))))] + (symbol->string name) + (symbol->string name) + (assemble-modinvokes module-requires module-body-text)) + + (map make-ModuleSource module-requires))))] + + [(SexpSource? src) (error 'get-javascript-implementation)] [(UninterpretedSource? src) (error 'get-javascript-implementation)])) - + +(define (assemble-modinvokes paths after) + (cond + [(empty? paths) + after] + [else + (assemble-modinvoke (first paths) + (assemble-modinvokes (rest paths) after))])) + + +(define (assemble-modinvoke path after) + (format "if (! MACHINE.modules[~s].isInvoked) { + MACHINE.modules[~s].invoke(MACHINE, + function() { + ~a + }, + MACHINE.params.currentErrorHandler); + } else { + ~a + } + " + path + path + after + after)) + diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index bae32c4..89ffe38 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -223,6 +223,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } } }; + // External invokation of a module. ModuleRecord.prototype.invoke = function(MACHINE, succ, fail) { MACHINE = MACHINE || plt.runtime.currentMachine; diff --git a/make/make-structs.rkt b/make/make-structs.rkt index 41e8d1a..94a9604 100644 --- a/make/make-structs.rkt +++ b/make/make-structs.rkt @@ -25,7 +25,8 @@ #:transparent) (define-struct: SexpSource ([sexp : Any]) #:transparent) -(define-struct: UninterpretedSource ([datum : String]) +(define-struct: UninterpretedSource ([datum : String] + [neighbors : (Listof Source)]) #:transparent) diff --git a/make/make.rkt b/make/make.rkt index 77b50bb..02ad72f 100644 --- a/make/make.rkt +++ b/make/make.rkt @@ -132,26 +132,30 @@ (Source (U False Expression) -> (Listof Source))) (define (collect-new-dependencies this-source ast) (cond - [(eq? ast #f) - empty] - [(not (should-follow-children? this-source)) - empty] + [(UninterpretedSource? this-source) + (UninterpretedSource-neighbors this-source)] [else - (let* ([dependent-module-names (get-dependencies ast)] - [paths - (foldl (lambda: ([mp : ModuleLocator] - [acc : (Listof Source)]) - (let ([rp [ModuleLocator-real-path mp]]) - (cond [((current-kernel-module-locator?) - mp) - acc] - [(path? rp) - (cons (make-ModuleSource rp) acc)] - [else - acc]))) - '() - dependent-module-names)]) - paths)])) + (cond + [(eq? ast #f) + empty] + [(not (should-follow-children? this-source)) + empty] + [else + (let* ([dependent-module-names (get-dependencies ast)] + [paths + (foldl (lambda: ([mp : ModuleLocator] + [acc : (Listof Source)]) + (let ([rp [ModuleLocator-real-path mp]]) + (cond [((current-kernel-module-locator?) + mp) + acc] + [(path? rp) + (cons (make-ModuleSource rp) acc)] + [else + acc]))) + '() + dependent-module-names)]) + paths)])])) (let: loop : Void ([sources : (Listof Source) sources]) (cond diff --git a/tests/test-all.rkt b/tests/test-all.rkt index 52c684e..7295652 100644 --- a/tests/test-all.rkt +++ b/tests/test-all.rkt @@ -11,7 +11,7 @@ "test-conform-browser.rkt" "test-earley-browser.rkt" "test-get-dependencies.rkt" - "more-tests/run-more-tests.rkt") + "run-more-tests.rkt") ;; This test takes a bit too much time.