assigning the external names
This commit is contained in:
parent
6a35aae56e
commit
b01447626c
|
@ -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 makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };
|
||||
var isColor = colorStruct.predicate;
|
||||
|
|
|
@ -192,7 +192,7 @@
|
|||
[(FinalizeModuleInvokation!? op)
|
||||
(define modname (symbol->string (ModuleLocator-name (FinalizeModuleInvokation!-path op))))
|
||||
(string-append
|
||||
"(function (selfMod,ns,prefix) {"
|
||||
"(function (selfMod,ns,extNs,prefix) {"
|
||||
(string-join (for/list: : (Listof String) ([a-provide : ModuleProvide (FinalizeModuleInvokation!-provides op)])
|
||||
(cond [(kernel-module-name? (ModuleProvide-source a-provide))
|
||||
(format "ns.set(~s, M.primitives[~s]);"
|
||||
|
@ -200,13 +200,18 @@
|
|||
(symbol->string (ModuleProvide-internal-name a-provide)))]
|
||||
[(equal? (ModuleLocator-name (ModuleProvide-source a-provide))
|
||||
(ModuleLocator-name (FinalizeModuleInvokation!-path op)))
|
||||
(format "ns.set(~s, prefix[selfMod.getPrefixOffset(~s)]);"
|
||||
(symbol->string (ModuleProvide-internal-name a-provide))
|
||||
(symbol->string (ModuleProvide-internal-name a-provide)))]
|
||||
(string-append (format "ns.set(~s, prefix[selfMod.getPrefixOffset(~s)]);"
|
||||
(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
|
||||
(format "ns.set(~s, M.modules[~s].getNamespace().get(~s));"
|
||||
(symbol->string (ModuleProvide-external-name a-provide))
|
||||
(symbol->string (ModuleLocator-name (ModuleProvide-source 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))]))
|
||||
|
|
|
@ -173,9 +173,12 @@
|
|||
(for/list ([modprovide (get-provided-names bytecode)]
|
||||
[i (in-naturals)])
|
||||
(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-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"
|
||||
i
|
||||
(symbol->string (ModuleProvide-external-name modprovide)))))))
|
||||
|
@ -214,6 +217,8 @@
|
|||
(format "
|
||||
if(--M.cbt<0) { throw arguments.callee; }
|
||||
var modrec = M.modules[~s];
|
||||
var ns = modrec.getNamespace();
|
||||
var extNs = modrec.getExternalNamespace();
|
||||
~a
|
||||
var exports = {};
|
||||
modrec.isInvoked = true;
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
this.isInvoked = false;
|
||||
this.prefix = false;
|
||||
this.namespace = new Namespace(this);
|
||||
this.externalNamespace = new Namespace(this);
|
||||
|
||||
// JavaScript-implemented code will assign privateExports
|
||||
// with all of the exported identifiers.
|
||||
|
@ -50,11 +51,17 @@
|
|||
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 () {
|
||||
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.
|
||||
ModuleRecord.prototype.invoke = function (MACHINE, succ, fail) {
|
||||
this._invoke(false, MACHINE, succ, fail);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
|
||||
|
||||
var resourceStructType =
|
||||
MACHINE.modules['whalesong/resource/structs.rkt'].getNamespace().get('struct:resource');
|
||||
MACHINE.modules['whalesong/resource/structs.rkt'].getExternalNamespace().get('struct:resource');
|
||||
|
||||
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['wrapFunction'] = wrapFunction;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
}());
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue
Block a user