Mercurial > repos > tabletprog
comparison 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 |
comparison
equal
deleted
inserted
replaced
103:182c311a9fed | 104:648659961e0e |
---|---|
16 this.ast = parseFile(this.path + '/' + this.file); | 16 this.ast = parseFile(this.path + '/' + this.file); |
17 this.ast.populateSymbols(toplevel); | 17 this.ast.populateSymbols(toplevel); |
18 } | 18 } |
19 }; | 19 }; |
20 | 20 |
21 modulefile.prototype.popuplateSymbolsAsync = function(toplevel, whenDone) { | |
22 if (!this.ast) { | |
23 var self = this; | |
24 get(this.path + '/' + this.file, function(data) { | |
25 self.ast = parser.parse(data.responseText); | |
26 self.ast.populateSymbols(toplevel); | |
27 whenDone(); | |
28 }); | |
29 } else { | |
30 whenDone(); | |
31 } | |
32 }; | |
33 | |
34 function getfileshtml(path, data, names) | |
35 { | |
36 var fakeEl = newEl("div", { | |
37 innerHTML: data.response | |
38 }); | |
39 each(qall('a', fakeEl), function(idx, a) { | |
40 var tpidx = a.textContent.indexOf('.tp'); | |
41 var modname = a.textContent.substr(0, tpidx); | |
42 if (tpidx > -1) { | |
43 names[modname] = new modulefile(path, modname + '.tp'); | |
44 } | |
45 }); | |
46 } | |
47 | |
21 var toplevel = new topsymbols([]); | 48 var toplevel = new topsymbols([]); |
22 function topsymbols(moduledirs) | 49 function topsymbols(moduledirs) |
23 { | 50 { |
24 this.names = null; | 51 this.names = null; |
25 this.used = {}; | 52 this.used = {}; |
26 this.nextmodulenum = 0; | 53 this.nextmodulenum = 0; |
54 this.onready = null; | |
27 var self = this; | 55 var self = this; |
28 if (typeof window === "object") { | 56 if (typeof window === "object") { |
29 get('/src/', function(data) { | 57 get('/modules/', function(data) { |
30 self.names = {}; | 58 var names = {} |
31 var fakeEl = newEl("div", { | 59 getfileshtml('/modules', data, names); |
32 innerHTML: data.response | 60 get('/src/', function(data) { |
33 }); | 61 getfileshtml('/src', data, names); |
34 each(qall('a', fakeEl), function(idx, a) { | 62 self.names = names; |
35 var tpidx = a.textContent.indexOf('.tp'); | 63 if (self.onready) { |
36 if (tpidx > -1) { | 64 self.onready(); |
37 self.names[a.textContent.substr(0, tpidx)] = true; | |
38 } | 65 } |
39 }); | 66 }); |
40 }); | 67 }); |
41 } else { | 68 } else { |
42 this.names = {}; | 69 this.names = {}; |
62 type: 'toplevel', | 89 type: 'toplevel', |
63 def: this.names[name] | 90 def: this.names[name] |
64 }; | 91 }; |
65 } | 92 } |
66 return null; | 93 return null; |
67 } | 94 }; |
68 topsymbols.prototype.getEnvType = function() { | 95 topsymbols.prototype.getEnvType = function() { |
69 return 'void'; | 96 return 'void'; |
70 } | 97 }; |
71 topsymbols.prototype.moduleVar = function(name) { | 98 topsymbols.prototype.moduleVar = function(name) { |
72 if (!(name in this.names)) { | 99 if (!(name in this.names)) { |
73 throw new Error('symbol ' + name + ' not found at toplevel'); | 100 throw new Error('symbol ' + name + ' not found at toplevel'); |
74 } | 101 } |
75 if (name == 'true' || name == 'false') { | 102 if (name == 'true' || name == 'false') { |
77 } | 104 } |
78 if (!this.names[name].modulevar) { | 105 if (!this.names[name].modulevar) { |
79 this.names[name].modulevar = 'module_' + this.nextmodulenum++ | 106 this.names[name].modulevar = 'module_' + this.nextmodulenum++ |
80 } | 107 } |
81 return this.names[name].modulevar; | 108 return this.names[name].modulevar; |
82 } | 109 }; |
110 topsymbols.prototype.onReady = function(fun) { | |
111 if (this.names) { | |
112 fun(); | |
113 return; | |
114 } | |
115 if (!this.onready) { | |
116 this.onready = fun; | |
117 } else { | |
118 var oldready = this.onready; | |
119 this.onready = function() { | |
120 oldready(); | |
121 fun(); | |
122 }; | |
123 } | |
124 }; | |
83 | 125 |
84 function osymbols(parent) | 126 function osymbols(parent) |
85 { | 127 { |
86 this.parent = parent; | 128 this.parent = parent; |
87 this.names = {}; | 129 this.names = {}; |