Mercurial > repos > tabletprog
comparison compiler.js @ 34:a10f1b049193
Working closures, but need to rethink method call strategy
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 09 Jul 2012 08:57:50 -0700 |
parents | 668f533e5284 |
children | bf5e88f6419d |
comparison
equal
deleted
inserted
replaced
33:96e21f525b78 | 34:a10f1b049193 |
---|---|
35 def: null | 35 def: null |
36 }; | 36 }; |
37 } | 37 } |
38 return null; | 38 return null; |
39 } | 39 } |
40 topsymbols.prototype.getEnvType = function() { | |
41 return 'void'; | |
42 } | |
40 | 43 |
41 function osymbols(parent) | 44 function osymbols(parent) |
42 { | 45 { |
43 this.parent = parent; | 46 this.parent = parent; |
44 this.names = {}; | 47 this.names = {}; |
93 if (this.parent) { | 96 if (this.parent) { |
94 return this.parent.allSymbols(curlist, cursyms); | 97 return this.parent.allSymbols(curlist, cursyms); |
95 } | 98 } |
96 return curlist; | 99 return curlist; |
97 } | 100 } |
101 osymbols.prototype.getEnvType = function() { | |
102 console.log('osymbol parent', this.parent); | |
103 return this.parent.getEnvType(); | |
104 } | |
98 | 105 |
99 function lsymbols(parent) | 106 function lsymbols(parent) |
100 { | 107 { |
101 this.parent = parent; | 108 this.parent = parent; |
102 this.names = {}; | 109 this.names = {}; |
110 this.closedover = {}; | |
103 this.needsSelfVar = false; | 111 this.needsSelfVar = false; |
104 } | 112 this.passthruenv = false; |
105 lsymbols.prototype.find = function(name) { | 113 this.envtype = 'void'; |
114 } | |
115 lsymbols.prototype.find = function(name, nestedcall) { | |
116 console.log('find', name, nestedcall); | |
106 if (name in this.names) { | 117 if (name in this.names) { |
107 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { | 118 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { |
108 return { | 119 return { |
109 type: 'foreign', | 120 type: 'foreign', |
110 def: this.names[name] | 121 def: this.names[name] |
111 }; | 122 }; |
112 } | 123 } |
124 if (nestedcall) { | |
125 console.log('closedover', name); | |
126 this.closedover[name] = true; | |
127 } | |
128 if (name in this.closedover) { | |
129 return { | |
130 type: 'closedover', | |
131 def: this.names[name] | |
132 }; | |
133 } | |
113 return { | 134 return { |
114 type: 'local', | 135 type: 'local', |
115 def: this.names[name] | 136 def: this.names[name] |
116 }; | 137 }; |
117 } else if(this.parent) { | 138 } else if(this.parent) { |
118 var ret = this.parent.find(name); | 139 var ret = this.parent.find(name, true); |
119 if (ret) { | 140 if (ret) { |
120 if (ret.type == 'local') { | 141 if (ret.type == 'closedover') { |
121 ret.type = 'upvar'; | 142 ret.type = 'upvar'; |
122 ret.depth = 1; | 143 ret.depth = 1; |
123 } else if (ret.type == 'upvar') { | 144 } else if (ret.type == 'upvar') { |
124 ret.depth++; | 145 if (Object(this.closedover).keys.length) { |
146 ret.depth++; | |
147 } else { | |
148 this.passthruenv = true; | |
149 } | |
125 } | 150 } |
126 } | 151 } |
127 return ret; | 152 return ret; |
128 } | 153 } |
129 return null; | 154 return null; |
145 } else { | 170 } else { |
146 this.needsSelfVar = true; | 171 this.needsSelfVar = true; |
147 } | 172 } |
148 }; | 173 }; |
149 lsymbols.prototype.allSymbols = osymbols.prototype.allSymbols; | 174 lsymbols.prototype.allSymbols = osymbols.prototype.allSymbols; |
175 lsymbols.prototype.parentEnvType = function() { | |
176 if (!this.parent) { | |
177 return 'void'; | |
178 } | |
179 return this.parent.getEnvType(); | |
180 }; | |
181 lsymbols.prototype.getEnvType = function() { | |
182 if (this.passthruenv) { | |
183 console.log('lsymbol parent', this.parent); | |
184 return this.parent.getEnvType(); | |
185 } else { | |
186 return this.envtype; | |
187 } | |
188 } | |
150 | 189 |
151 var mainModule; | 190 var mainModule; |
152 | 191 |
153 function toobj(val) | 192 function toobj(val) |
154 { | 193 { |
171 this.right.populateSymbols(symbols); | 210 this.right.populateSymbols(symbols); |
172 }; | 211 }; |
173 | 212 |
174 symbol.prototype.populateSymbols = function(symbols) { | 213 symbol.prototype.populateSymbols = function(symbols) { |
175 this.symbols = symbols; | 214 this.symbols = symbols; |
215 symbols.find(this.cleanName()); | |
176 } | 216 } |
177 | 217 |
178 intlit.prototype.populateSymbols = function(symbols) { | 218 intlit.prototype.populateSymbols = function(symbols) { |
179 } | 219 } |
180 | 220 |