diff compiler.js @ 68:3a169ebb3224

Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 16:14:01 -0700
parents 25b697c91629
children 8a9b96888b7d
line wrap: on
line diff
--- a/compiler.js	Sat Jul 14 13:31:05 2012 -0700
+++ b/compiler.js	Sat Jul 14 16:14:01 2012 -0700
@@ -16,6 +16,7 @@
 {
 	this.names = null;
 	this.used = {};
+	this.nextmodulenum = 0;
 	var self = this;
 	if (typeof window === "object") {
 		get('/src/', function(data) {
@@ -36,7 +37,7 @@
 			var results = os.system("ls", [moduledirs[dirnum]]).split('\n');
 			for (var i in results) {
 				var tpidx = results[i].indexOf('.tp')
-				if (tpidx > -1) {
+				if (tpidx > 0 && tpidx == results[i].length - 3) {
 					this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]);
 				}
 			}
@@ -60,6 +61,18 @@
 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');
+	}
+	if (name == 'true' || name == 'false') {
+		return 'module_' + name;
+	}
+	if (!this.names[name].modulevar) {
+		this.names[name].modulevar = 'module_' + this.nextmodulenum++
+	}
+	return this.names[name].modulevar;
+}
 
 function osymbols(parent)
 {