Mercurial > repos > tabletprog
comparison 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 |
comparison
equal
deleted
inserted
replaced
47:cd41f7c22fcd | 48:18ab96287c3a |
---|---|
1 function indent(str) | 1 function indent(str) |
2 { | 2 { |
3 return str.split('\n').join('\n\t'); | 3 return str.split('\n').join('\n\t'); |
4 } | 4 } |
5 | 5 |
6 function modulefile(path, file) | |
7 { | |
8 this.path = path; | |
9 this.file = file; | |
10 } | |
11 | |
6 var toplevel = new topsymbols(); | 12 var toplevel = new topsymbols(); |
7 function topsymbols() | 13 function topsymbols(moduledirs) |
8 { | 14 { |
9 this.names = null; | 15 this.names = null; |
16 this.used = {}; | |
10 var self = this; | 17 var self = this; |
11 if (typeof window === "object") { | 18 if (typeof window === "object") { |
12 get('/src/', function(data) { | 19 get('/src/', function(data) { |
13 self.names = {}; | 20 self.names = {}; |
14 var fakeEl = newEl("div", { | 21 var fakeEl = newEl("div", { |
21 } | 28 } |
22 }); | 29 }); |
23 }); | 30 }); |
24 } else { | 31 } else { |
25 this.names = {}; | 32 this.names = {}; |
33 for (var dirnum in moduledirs) { | |
34 var results = os.system("ls", [moduledirs[dirnum]]).split('\n'); | |
35 for (var i in results) { | |
36 var tpidx = results[i].indexOf('.tp') | |
37 if (tpidx > -1) { | |
38 this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]); | |
39 } | |
40 } | |
41 } | |
26 } | 42 } |
27 } | 43 } |
28 topsymbols.prototype.find = function(name) { | 44 topsymbols.prototype.find = function(name) { |
29 if (!this.names) { | 45 if (!this.names) { |
30 throw new Error('data not ready'); | 46 throw new Error('data not ready'); |
31 } | 47 } |
32 if (name in this.names) { | 48 if (name in this.names) { |
49 this.used[name] = true; | |
33 return { | 50 return { |
34 type: 'toplevel', | 51 type: 'toplevel', |
35 def: null | 52 def: this.names[name] |
36 }; | 53 }; |
37 } | 54 } |
38 return null; | 55 return null; |
39 } | 56 } |
40 topsymbols.prototype.getEnvType = function() { | 57 topsymbols.prototype.getEnvType = function() { |