comparison interp.js @ 224:97c3e33cd3f4

Support macro expansion inside quoted code
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 14:38:56 -0800
parents 218b11ec8fa2
children 3bfc00e4f5e5
comparison
equal deleted inserted replaced
223:25db1c7c7300 224:97c3e33cd3f4
433 if (name[name.length-1] == ":") { 433 if (name[name.length-1] == ":") {
434 name = name.substr(0, name.length-1); 434 name = name.substr(0, name.length-1);
435 } 435 }
436 if (name == 'quote') { 436 if (name == 'quote') {
437 if (this.receiver) { 437 if (this.receiver) {
438 return this.receiver.quote(env); 438 return this.receiver.quote(env).macroexpand(env);
439 } 439 }
440 if (this.args.length) { 440 if (this.args.length) {
441 var cur = env; 441 var cur = env;
442 return this.args[0].quote(env); 442 return this.args[0].quote(env).macroexpand(env);
443 } 443 }
444 throw new Error('quote takes an argument'); 444 throw new Error('quote takes an argument');
445 } 445 }
446 if (name == 'macro') { 446 if (name == 'macro') {
447 return null; 447 return null;
482 482
483 funcall.prototype.macroexpand = function(env) { 483 funcall.prototype.macroexpand = function(env) {
484 var name = this.name; 484 var name = this.name;
485 if (name[name.length-1] == ":") { 485 if (name[name.length-1] == ":") {
486 name = name.substr(0, name.length-1); 486 name = name.substr(0, name.length-1);
487 }
488 if (name == 'quote') {
489 return this;
487 } 490 }
488 var macro = env.findMacro(name); 491 var macro = env.findMacro(name);
489 if (this.receiver) { 492 if (this.receiver) {
490 this.receiver = this.receiver.macroexpand(env); 493 this.receiver = this.receiver.macroexpand(env);
491 } 494 }