right in the middle of fixing namespace bugs.

This commit is contained in:
Danny Yoo 2013-03-06 15:55:08 -07:00
parent ee86bce394
commit d8fd834442
4 changed files with 24 additions and 64 deletions

View File

@ -192,19 +192,21 @@
[(FinalizeModuleInvokation!? op)
(define modname (symbol->string (ModuleLocator-name (FinalizeModuleInvokation!-path op))))
(string-append
(format "M.modules[~s].finalizeModuleInvokation();"
modname)
"(function (ns) {"
"(function (selfMod,ns,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]);"
(symbol->string (ModuleProvide-external-name a-provide))
(symbol->string (ModuleProvide-internal-name a-provide)))]
(format "ns.set(~s, M.primitives[~s]);"
(symbol->string (ModuleProvide-external-name a-provide))
(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)))]
[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].getNamespace()));" modname))]))
(format "}(M.modules[~s],M.modules[~s].getNamespace(),M.modules[~s].prefix));" modname modname modname))]))

View File

@ -173,12 +173,13 @@
(for/list ([modprovide (get-provided-names bytecode)]
[i (in-naturals)])
(string-append
; (format "modrec.getNamespace().set(~s,exports[~s]);\n"
; (symbol->string (ModuleProvide-internal-name modprovide))
; (symbol->string (ModuleProvide-external-name modprovide)))
(format "modrec.prefix[~a]=exports[~s];\n"
i
(symbol->string (ModuleProvide-external-name modprovide)))))))
(format "modrec.getNamespace().set(~s,exports[~s]);\n"
(symbol->string (ModuleProvide-external-name modprovide))
(symbol->string (ModuleProvide-internal-name modprovide)))
;(format "modrec.prefix[~a]=exports[~s];\n"
; i
; (symbol->string (ModuleProvide-external-name modprovide))))
))))
(define (get-prefix-code bytecode)
(format "modrec.prefix=[~a];modrec.prefix.names=[~a];modrec.prefix.internalNames=[~a];"
@ -220,7 +221,6 @@
(function(MACHINE, EXPORTS){~a})(M, exports);
~a
modrec.privateExports = exports;
modrec.finalizeModuleInvokation();
return M.c.pop().label(M);"
(symbol->string name)
(get-prefix-code bytecode)

View File

@ -10,36 +10,13 @@
var Namespace = function(modrec) {
this.modrec = modrec;
// string -> integer
// Returns the position within the prefix that we should be looking.
// Returns the key/value pairs of the prefix.
// mapping: string -> value
this.mapping = {};
this.prefix = void(0);
this.extra = {};
};
Namespace.prototype.get = function(name) {
if (this.mapping.hasOwnProperty(name)) {
return this.prefix[this.mapping[name]];
}
if (this.extra.hasOwnProperty(name)) {
return this.extra[name];
}
return void(0);
};
Namespace.prototype.refreshPrefixMapping = function() {
var prefix = this.modrec.prefix;
var name;
var i;
for (i = 0; i < prefix.length; i++) {
name = prefix.names[i];
this.mapping[name] = i;
if (this.extra.hasOwnProperty(name)) {
prefix[i] = this.extra[name];
delete this.extra[name];
}
}
this.prefix = prefix;
return this.mapping[name];
};
Namespace.prototype.hasKey = function(name) {
@ -47,16 +24,7 @@
};
Namespace.prototype.set = function(name, value) {
if (this.mapping.hasOwnProperty(name)) {
this.prefix[this.mapping[name]] = value;
return;
};
if (this.extra.hasOwnProperty(name)) {
this.extra[name] = value;
return;
}
this.extra[name] = value;
return;
this.mapping[name] = value;
};
var ModuleRecord = function (name, label) {
@ -85,12 +53,7 @@
// Returns access to the names defined in the module.
ModuleRecord.prototype.getNamespace = function () {
return this.namespace;
};
ModuleRecord.prototype.finalizeModuleInvokation = function () {
this.namespace.refreshPrefixMapping();
};
};
// External invokation of a module.
ModuleRecord.prototype.invoke = function (MACHINE, succ, fail) {
@ -148,4 +111,4 @@
exports.ModuleRecord = ModuleRecord;
}(this.plt.baselib, this.plt));
}(this.plt.baselib, this.plt));

View File

@ -14,11 +14,6 @@
"../js-assembler/package.rkt"
"../parser/parse-bytecode.rkt"
"../compiler/compiler.rkt"
"../compiler/expression-structs.rkt"
"../compiler/il-structs.rkt"
"../compiler/lexical-structs.rkt"
"../compiler/compiler-structs.rkt"
"../compiler/optimize-il.rkt"
"../js-assembler/assemble.rkt"
"write-runtime.rkt"
(for-syntax racket/base))
@ -79,7 +74,7 @@
(define op (open-output-bytes))
(write raw-bytecode op)
(define whalesong-bytecode (parse-bytecode (open-input-bytes (get-output-bytes op))))
#;(pretty-print whalesong-bytecode)
(pretty-print whalesong-bytecode)
(define compiled-bytecode (compile-for-repl whalesong-bytecode))
#;(pretty-print compiled-bytecode)
(define assembled-op (open-output-string))