diff compiler.js @ 104:648659961e0e

Get editor working again
author Mike Pavone <pavone@retrodev.com>
date Thu, 11 Apr 2013 00:12:21 -0700
parents b58b19c455ec
children d715fb3c39ab
line wrap: on
line diff
--- a/compiler.js	Thu Aug 09 19:26:21 2012 -0700
+++ b/compiler.js	Thu Apr 11 00:12:21 2013 -0700
@@ -18,23 +18,50 @@
 	}
 };
 
+modulefile.prototype.popuplateSymbolsAsync = function(toplevel, whenDone) {
+	if (!this.ast) {
+		var self = this;
+		get(this.path + '/' + this.file, function(data) {
+			self.ast = parser.parse(data.responseText);
+			self.ast.populateSymbols(toplevel);
+			whenDone();
+		});
+	} else {
+		whenDone();
+	}
+};
+
+function getfileshtml(path, data, names)
+{
+	var fakeEl = newEl("div", {
+		innerHTML: data.response
+	});
+	each(qall('a', fakeEl), function(idx, a) {
+		var tpidx = a.textContent.indexOf('.tp');
+		var modname = a.textContent.substr(0, tpidx);
+		if (tpidx > -1) {
+			names[modname] = new modulefile(path, modname + '.tp');
+		}
+	});
+}
+
 var toplevel = new topsymbols([]);
 function topsymbols(moduledirs)
 {
 	this.names = null;
 	this.used = {};
 	this.nextmodulenum = 0;
+	this.onready = null;
 	var self = this;
 	if (typeof window === "object") {
-		get('/src/', function(data) {
-			self.names = {};
-			var fakeEl = newEl("div", {
-				innerHTML: data.response
-			});
-			each(qall('a', fakeEl), function(idx, a) {
-				var tpidx = a.textContent.indexOf('.tp');
-				if (tpidx > -1) {
-					self.names[a.textContent.substr(0, tpidx)] = true;
+		get('/modules/', function(data) {
+			var names = {}
+			getfileshtml('/modules', data, names);
+			get('/src/', function(data) {
+				getfileshtml('/src', data, names);
+				self.names = names;
+				if (self.onready) {
+					self.onready();
 				}
 			});
 		});
@@ -64,10 +91,10 @@
 		};
 	}
 	return null;
-}
+};
 topsymbols.prototype.getEnvType = function() {
 	return 'void';
-}
+};
 topsymbols.prototype.moduleVar = function(name) {
 	if (!(name in this.names)) {
 		throw new Error('symbol ' + name + ' not found at toplevel');
@@ -79,7 +106,22 @@
 		this.names[name].modulevar = 'module_' + this.nextmodulenum++
 	}
 	return this.names[name].modulevar;
-}
+};
+topsymbols.prototype.onReady = function(fun) {
+	if (this.names) {
+		fun();
+		return;
+	}
+	if (!this.onready) {
+		this.onready = fun;
+	} else {
+		var oldready = this.onready;
+		this.onready = function() {
+			oldready();
+			fun();
+		};
+	}
+};
 
 function osymbols(parent)
 {