diff compiler.js @ 251:2557ce4e671f

Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
author Michael Pavone <pavone@retrodev.com>
date Fri, 11 Apr 2014 22:29:32 -0700
parents 60eff5f81d9a
children d6a4c9e7716e
line wrap: on
line diff
--- a/compiler.js	Wed Apr 09 22:55:10 2014 -0700
+++ b/compiler.js	Fri Apr 11 22:29:32 2014 -0700
@@ -13,7 +13,7 @@
 
 modulefile.prototype.populateSymbols = function (toplevel) {
 	if (!this.ast) {
-		this.ast = parseFile(this.path + '/' + this.file).macroexpand(new topenv(toplevel.moduledirs));
+		this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv);
 		this.ast.populateSymbols(toplevel);
 	}
 };
@@ -46,10 +46,14 @@
 	});
 }
 
-var toplevel = new topsymbols([]);
-function topsymbols(moduledirs)
+var toplevel = null;//new topsymbols([]);
+function topsymbols(moduledirs, top)
 {
-  this.moduledirs = moduledirs;
+	if (!top) {
+		top = new topenv(moduledirs);
+	}
+	this.topenv = top;
+	this.moduledirs = moduledirs;
 	this.names = null;
 	this.used = {};
 	this.nextmodulenum = 0;