assigning the external names

This commit is contained in:
Danny Yoo 2013-03-06 16:26:06 -07:00
parent 6a35aae56e
commit b01447626c
7 changed files with 30 additions and 13 deletions

View File

@ -4,7 +4,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].getNamespace(); var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].getExternalNamespace();
var colorStruct = colorNamespace.get('struct:color'); var colorStruct = colorNamespace.get('struct:color');
var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); }; var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };
var isColor = colorStruct.predicate; var isColor = colorStruct.predicate;

View File

@ -192,7 +192,7 @@
[(FinalizeModuleInvokation!? op) [(FinalizeModuleInvokation!? op)
(define modname (symbol->string (ModuleLocator-name (FinalizeModuleInvokation!-path op)))) (define modname (symbol->string (ModuleLocator-name (FinalizeModuleInvokation!-path op))))
(string-append (string-append
"(function (selfMod,ns,prefix) {" "(function (selfMod,ns,extNs,prefix) {"
(string-join (for/list: : (Listof String) ([a-provide : ModuleProvide (FinalizeModuleInvokation!-provides op)]) (string-join (for/list: : (Listof String) ([a-provide : ModuleProvide (FinalizeModuleInvokation!-provides op)])
(cond [(kernel-module-name? (ModuleProvide-source a-provide)) (cond [(kernel-module-name? (ModuleProvide-source a-provide))
(format "ns.set(~s, M.primitives[~s]);" (format "ns.set(~s, M.primitives[~s]);"
@ -200,13 +200,18 @@
(symbol->string (ModuleProvide-internal-name a-provide)))] (symbol->string (ModuleProvide-internal-name a-provide)))]
[(equal? (ModuleLocator-name (ModuleProvide-source a-provide)) [(equal? (ModuleLocator-name (ModuleProvide-source a-provide))
(ModuleLocator-name (FinalizeModuleInvokation!-path op))) (ModuleLocator-name (FinalizeModuleInvokation!-path op)))
(format "ns.set(~s, prefix[selfMod.getPrefixOffset(~s)]);" (string-append (format "ns.set(~s, prefix[selfMod.getPrefixOffset(~s)]);"
(symbol->string (ModuleProvide-internal-name a-provide)) (symbol->string (ModuleProvide-internal-name a-provide))
(symbol->string (ModuleProvide-internal-name a-provide)))] (symbol->string (ModuleProvide-internal-name a-provide)))
;; For JS-derived code, it might be inconvenient to get the bindings by internal
;; name. We assign a separate mapping here to make it easier to access.
(format "extNs.set(~s, prefix[selfMod.getPrefixOffset(~s)]);"
(symbol->string (ModuleProvide-external-name a-provide))
(symbol->string (ModuleProvide-internal-name a-provide))))]
[else [else
(format "ns.set(~s, M.modules[~s].getNamespace().get(~s));" (format "ns.set(~s, M.modules[~s].getNamespace().get(~s));"
(symbol->string (ModuleProvide-external-name a-provide)) (symbol->string (ModuleProvide-external-name a-provide))
(symbol->string (ModuleLocator-name (ModuleProvide-source a-provide))) (symbol->string (ModuleLocator-name (ModuleProvide-source a-provide)))
(symbol->string (ModuleProvide-internal-name a-provide)))])) (symbol->string (ModuleProvide-internal-name a-provide)))]))
"") "")
(format "}(M.modules[~s],M.modules[~s].getNamespace(),M.modules[~s].prefix));" modname modname modname))])) (format "}(M.modules[~s],M.modules[~s].getNamespace(),M.modules[~s].getExternalNamespace(),M.modules[~s].prefix));" modname modname modname modname))]))

View File

@ -173,9 +173,12 @@
(for/list ([modprovide (get-provided-names bytecode)] (for/list ([modprovide (get-provided-names bytecode)]
[i (in-naturals)]) [i (in-naturals)])
(string-append (string-append
(format "modrec.getNamespace().set(~s,exports[~s]);\n" (format "ns.set(~s,exports[~s]);\n"
(symbol->string (ModuleProvide-internal-name modprovide)) (symbol->string (ModuleProvide-internal-name modprovide))
(symbol->string (ModuleProvide-external-name modprovide))) (symbol->string (ModuleProvide-external-name modprovide)))
(format "extNs.set(~s,exports[~s]);\n"
(symbol->string (ModuleProvide-external-name modprovide))
(symbol->string (ModuleProvide-external-name modprovide)))
(format "modrec.prefix[~a]=exports[~s];\n" (format "modrec.prefix[~a]=exports[~s];\n"
i i
(symbol->string (ModuleProvide-external-name modprovide))))))) (symbol->string (ModuleProvide-external-name modprovide)))))))
@ -214,6 +217,8 @@
(format " (format "
if(--M.cbt<0) { throw arguments.callee; } if(--M.cbt<0) { throw arguments.callee; }
var modrec = M.modules[~s]; var modrec = M.modules[~s];
var ns = modrec.getNamespace();
var extNs = modrec.getExternalNamespace();
~a ~a
var exports = {}; var exports = {};
modrec.isInvoked = true; modrec.isInvoked = true;

View File

@ -33,6 +33,7 @@
this.isInvoked = false; this.isInvoked = false;
this.prefix = false; this.prefix = false;
this.namespace = new Namespace(this); this.namespace = new Namespace(this);
this.externalNamespace = new Namespace(this);
// JavaScript-implemented code will assign privateExports // JavaScript-implemented code will assign privateExports
// with all of the exported identifiers. // with all of the exported identifiers.
@ -50,11 +51,17 @@
return void(0); return void(0);
}; };
// Returns access to the names defined in the module. // Returns access to the names provided in the module.
// Note that the names are the names internal to the module.
ModuleRecord.prototype.getNamespace = function () { ModuleRecord.prototype.getNamespace = function () {
return this.namespace; return this.namespace;
}; };
// Returns access to the names defined with their external names.
ModuleRecord.prototype.getExternalNamespace = function() {
return this.externalNamespace;
};
// External invokation of a module. // External invokation of a module.
ModuleRecord.prototype.invoke = function (MACHINE, succ, fail) { ModuleRecord.prototype.invoke = function (MACHINE, succ, fail) {
this._invoke(false, MACHINE, succ, fail); this._invoke(false, MACHINE, succ, fail);

View File

@ -1,4 +1,4 @@
var resourceType = MACHINE.modules['whalesong/resource/structs.rkt'].getNamespace().get('struct:resource'); var resourceType = MACHINE.modules['whalesong/resource/structs.rkt'].getExternalNamespace().get('struct:resource');
var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure; var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure;

View File

@ -1,4 +1,4 @@
var resourceType = MACHINE.modules['whalesong/resource/structs.rkt'].getNamespace().get('struct:resource'); var resourceType = MACHINE.modules['whalesong/resource/structs.rkt'].getExternalNamespace().get('struct:resource');
var makeClosure = plt.baselib.functions.makeClosure; var makeClosure = plt.baselib.functions.makeClosure;
var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall; var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;

View File

@ -34,10 +34,10 @@
var resourceStructType = var resourceStructType =
MACHINE.modules['whalesong/resource/structs.rkt'].getNamespace().get('struct:resource'); MACHINE.modules['whalesong/resource/structs.rkt'].getExternalNamespace().get('struct:resource');
var eventStructType = var eventStructType =
MACHINE.modules['whalesong/web-world/event.rkt'].getNamespace().get('struct:event'); MACHINE.modules['whalesong/web-world/event.rkt'].getExternalNamespace().get('struct:event');
@ -2287,4 +2287,4 @@
EXPORTS['EventHandler'] = EventHandler; EXPORTS['EventHandler'] = EventHandler;
EXPORTS['wrapFunction'] = wrapFunction; EXPORTS['wrapFunction'] = wrapFunction;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
}()); }());