Mercurial > repos > tabletprog
comparison compiler.js @ 38:e7be612fd3ae
Very basic array support
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 10 Jul 2012 23:09:44 -0700 |
parents | 3b0503a67165 |
children | 4e983fe32047 |
comparison
equal
deleted
inserted
replaced
37:a6bf4869fcbe | 38:e7be612fd3ae |
---|---|
105 function lsymbols(parent) | 105 function lsymbols(parent) |
106 { | 106 { |
107 this.parent = parent; | 107 this.parent = parent; |
108 this.names = {}; | 108 this.names = {}; |
109 this.closedover = {}; | 109 this.closedover = {}; |
110 this.declared = {}; | |
110 this.needsSelfVar = false; | 111 this.needsSelfVar = false; |
111 this.passthruenv = false; | 112 this.passthruenv = false; |
112 this.envtype = 'void'; | 113 this.envtype = 'void'; |
113 } | 114 } |
114 lsymbols.prototype.find = function(name, nestedcall) { | 115 lsymbols.prototype.find = function(name, nestedcall) { |
128 def: this.names[name] | 129 def: this.names[name] |
129 }; | 130 }; |
130 } | 131 } |
131 return { | 132 return { |
132 type: 'local', | 133 type: 'local', |
133 def: this.names[name] | 134 def: this.names[name], |
135 isdeclared: (name in this.declared) | |
134 }; | 136 }; |
135 } else if(this.parent) { | 137 } else if(this.parent) { |
136 var ret = this.parent.find(name, true); | 138 var ret = this.parent.find(name, true); |
137 if (ret) { | 139 if (ret) { |
138 if (ret.type == 'closedover') { | 140 if (ret.type == 'closedover') { |
151 return null; | 153 return null; |
152 }; | 154 }; |
153 lsymbols.prototype.defineVar = function(name, def) { | 155 lsymbols.prototype.defineVar = function(name, def) { |
154 this.names[name] = def; | 156 this.names[name] = def; |
155 }; | 157 }; |
158 lsymbols.prototype.declareVar = function(name) { | |
159 this.declared[name] = true; | |
160 } | |
156 lsymbols.prototype.selfVar = function() { | 161 lsymbols.prototype.selfVar = function() { |
157 if (this.parent && this.parent instanceof lsymbols) { | 162 if (this.parent && this.parent instanceof lsymbols) { |
158 this.parent.needsSelf(); | 163 this.parent.needsSelf(); |
159 return 'self'; | 164 return 'self'; |
160 } else { | 165 } else { |
219 | 224 |
220 strlit.prototype.populateSymbols = function(symbols) { | 225 strlit.prototype.populateSymbols = function(symbols) { |
221 } | 226 } |
222 | 227 |
223 listlit.prototype.populateSymbols = function(symbols) { | 228 listlit.prototype.populateSymbols = function(symbols) { |
224 each(this.val, function(i,el) { | 229 for (var i = 0; i < this.val.length; i++) { |
225 el.populateSymbols(symbols); | 230 this.val[i].populateSymbols(symbols); |
226 }); | 231 } |
232 } | |
233 | |
234 arraylit.prototype.populateSymbols = function(symbols) { | |
235 for (var i = 0; i < this.val.length; i++) { | |
236 this.val[i].populateSymbols(symbols); | |
237 } | |
227 } | 238 } |
228 | 239 |
229 funcall.prototype.populateSymbols = function(symbols) { | 240 funcall.prototype.populateSymbols = function(symbols) { |
230 if (this.name == 'foreign:') { | 241 if (this.name == 'foreign:') { |
231 if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object) || (this.args[0] instanceof symbol)) { | 242 if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object) || (this.args[0] instanceof symbol)) { |