diff compiler.js @ 329:eef8a5cea812

Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
author Michael Pavone <pavone@retrodev.com>
date Sat, 28 Mar 2015 13:26:03 -0700
parents d4df33596e7d
children
line wrap: on
line diff
--- a/compiler.js	Wed Mar 25 00:16:37 2015 -0700
+++ b/compiler.js	Sat Mar 28 13:26:03 2015 -0700
@@ -5,16 +5,20 @@
 	return str.split('\n').join('\n\t');
 }
 
+var currentModule = null;
 function modulefile(path, file)
 {
 	this.path = path;
 	this.file = file;
+	this.dependencies = {};
 }
 
 modulefile.prototype.populateSymbols = function (toplevel) {
 	if (!this.ast) {
+		currentModule = this;
 		this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv);
 		this.ast.populateSymbols(toplevel);
+		currentModule = null;
 	}
 };
 
@@ -23,8 +27,10 @@
 		var self = this;
 		get(this.path + '/' + this.file, function(data) {
       //TODO: macro expand in the async case
+			currentModule = this;
 			self.ast = parser.parse(data.responseText);
 			self.ast.populateSymbols(toplevel);
+			currentModule = null;
 			whenDone();
 		});
 	} else {
@@ -93,6 +99,9 @@
 		throw new Error('data not ready');
 	}
 	if (name in this.names) {
+		if (currentModule) {
+			currentModule.dependencies[name] = true;
+		}
 		this.used[name] = true;
 		return {
 			type: 'toplevel',