Mercurial > repos > tabletprog
comparison compiler.js @ 31:668f533e5284
Add initial version of C backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 07 Jul 2012 16:48:36 -0700 |
parents | 608eb70fe261 |
children | a10f1b049193 |
comparison
equal
deleted
inserted
replaced
30:608eb70fe261 | 31:668f533e5284 |
---|---|
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 var toplevel = new topsymbols(); | |
6 function topsymbols() | 7 function topsymbols() |
7 { | 8 { |
8 this.names = null; | 9 this.names = null; |
10 var self = this; | |
11 get('/src/', function(data) { | |
12 console.log(data); | |
13 self.names = {}; | |
14 var fakeEl = newEl("div", { | |
15 innerHTML: data.response | |
16 }); | |
17 console.log(fakeEl); | |
18 each(qall('a', fakeEl), function(idx, a) { | |
19 var tpidx = a.textContent.indexOf('.tp'); | |
20 if (tpidx > -1) { | |
21 self.names[a.textContent.substr(0, tpidx)] = true; | |
22 } | |
23 }); | |
24 }); | |
9 } | 25 } |
10 topsymbols.prototype.find = function(name) { | 26 topsymbols.prototype.find = function(name) { |
27 console.log(this.names); | |
11 if (!this.names) { | 28 if (!this.names) { |
12 | 29 throw new Error('data not ready'); |
13 } | 30 } |
31 console.log('toplevel', name); | |
14 if (name in this.names) { | 32 if (name in this.names) { |
15 return { | 33 return { |
16 type: 'toplevel', | 34 type: 'toplevel', |
17 def: null | 35 def: null |
18 }; | 36 }; |
96 type: 'local', | 114 type: 'local', |
97 def: this.names[name] | 115 def: this.names[name] |
98 }; | 116 }; |
99 } else if(this.parent) { | 117 } else if(this.parent) { |
100 var ret = this.parent.find(name); | 118 var ret = this.parent.find(name); |
101 if (ret && ret.type == 'local') { | 119 if (ret) { |
102 ret.type = 'upvar'; | 120 if (ret.type == 'local') { |
121 ret.type = 'upvar'; | |
122 ret.depth = 1; | |
123 } else if (ret.type == 'upvar') { | |
124 ret.depth++; | |
125 } | |
103 } | 126 } |
104 return ret; | 127 return ret; |
105 } | 128 } |
106 return null; | 129 return null; |
107 }; | 130 }; |