diff compiler.js @ 48:18ab96287c3a

Add builtin module os containing some baisc POSIX file IO
author Mike Pavone <pavone@retrodev.com>
date Fri, 13 Jul 2012 10:46:27 -0700
parents 4e983fe32047
children 976a0924e1d4
line wrap: on
line diff
--- a/compiler.js	Fri Jul 13 08:50:10 2012 -0700
+++ b/compiler.js	Fri Jul 13 10:46:27 2012 -0700
@@ -3,10 +3,17 @@
 	return str.split('\n').join('\n\t');
 }
 
+function modulefile(path, file)
+{
+	this.path = path;
+	this.file = file;
+}
+
 var toplevel = new topsymbols();
-function topsymbols()
+function topsymbols(moduledirs)
 {
 	this.names = null;
+	this.used = {};
 	var self = this;
 	if (typeof window === "object") {
 		get('/src/', function(data) {
@@ -23,6 +30,15 @@
 		});
 	} else {
 		this.names = {};
+		for (var dirnum in moduledirs) {
+			var results = os.system("ls", [moduledirs[dirnum]]).split('\n');
+			for (var i in results) {
+				var tpidx = results[i].indexOf('.tp')
+				if (tpidx > -1) {
+					this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]);
+				}
+			}
+		}
 	}
 }
 topsymbols.prototype.find = function(name) {
@@ -30,9 +46,10 @@
 		throw new Error('data not ready');
 	}
 	if (name in this.names) {
+		this.used[name] = true;
 		return {
 			type: 'toplevel',
-			def: null
+			def: this.names[name]
 		};
 	}
 	return null;