comparison interp.js @ 221:218b11ec8fa2

Better handling for weird values being inserted into AST due to quoting
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 13:07:10 -0800
parents b70be565d54c
children 97c3e33cd3f4
comparison
equal deleted inserted replaced
220:a1a80af71b05 221:218b11ec8fa2
228 return new symbol('true'); 228 return new symbol('true');
229 } 229 }
230 if (val == tpfalse) { 230 if (val == tpfalse) {
231 return new symbol('false'); 231 return new symbol('false');
232 } 232 }
233 return val; 233 if ('makeHygienic' in val) {
234 return val;
235 }
236 return null;
234 } 237 }
235 238
236 op.prototype.eval = function(env) { 239 op.prototype.eval = function(env) {
237 var l = this.left.eval(env); 240 var l = this.left.eval(env);
238 var name = this.op; 241 var name = this.op;
304 307
305 symbol.prototype.quote = function(env) { 308 symbol.prototype.quote = function(env) {
306 var val = env.find(this.name); 309 var val = env.find(this.name);
307 if (val !== null) { 310 if (val !== null) {
308 var newnode = makeASTNode(val); 311 var newnode = makeASTNode(val);
312 if (!newnode) {
313 throw new Error(this.name + ' contains a value ' + val + ' that could not be converted to an AST node');
314 }
309 return newnode; 315 return newnode;
310 } else { 316 } else {
311 this.dirty = true; 317 this.dirty = true;
312 return this; 318 return this;
313 } 319 }
834 var val = env.find(name); 840 var val = env.find(name);
835 var dirty = true; 841 var dirty = true;
836 if (val) { 842 if (val) {
837 var node = makeASTNode(val); 843 var node = makeASTNode(val);
838 if (!(node instanceof symbol)) { 844 if (!(node instanceof symbol)) {
839 throw new Error('Left hand side of assignment expression must be a symbol!'); 845 throw new Error('Left hand side of assignment expression must be a symbol not a '+ node.constructor.name + ' '+(typeof node) + ', old name was ' + name);
840 } 846 }
841 name = node.cleanName(); 847 name = node.cleanName();
842 dirty = node.dirty; 848 dirty = node.dirty;
843 } 849 }
844 env.syms[name] = null; 850 env.syms[name] = null;