Mercurial > repos > tabletprog
view compiler.js @ 15:a5ef5af3df0f
Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 23 Mar 2012 18:06:53 -0700 |
parents | 04ae32e91598 |
children | 59e83296e331 |
line wrap: on
line source
function indent(str) { return str.split('\n').join('\n\t'); } function osymbols(parent) { this.parent = parent; this.names = {}; this.lastname = null; } osymbols.prototype.find = function(name) { if (name in this.names) { if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { return { type: 'foreign', def: this.names[name] }; } return { type: 'self', def: this.names[name], }; } else if(this.parent) { var ret = this.parent.find(name); if (ret) { if(ret.type == 'self') { ret.type = 'parent'; ret.depth = 1; } else if(ret.type == 'parent') { ret.depth++; } } return ret; } return null; }; osymbols.prototype.defineMsg = function(name, def) { this.lastname = name; this.names[name] = def; } osymbols.prototype.parentObject = function() { if (!this.parent) { return 'null'; } return 'this'; } function lsymbols(parent) { this.parent = parent; this.names = {}; this.lastname = null; this.needsSelfVar = false; } lsymbols.prototype.find = function(name) { if (name in this.names) { if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { return { type: 'foreign', def: this.names[name] }; } return { type: 'local', def: this.names[name] }; } else if(this.parent) { var ret = this.parent.find(name); if (ret && ret.type == 'local') { ret.type = 'upvar'; } return ret; } return null; }; lsymbols.prototype.defineVar = function(name, def) { this.lastname = name; this.names[name] = def; }; lsymbols.prototype.selfVar = function() { if (this.parent && this.parent instanceof lsymbols) { this.parent.needsSelf(); return 'self'; } else { return 'this'; } }; lsymbols.prototype.needsSelf = function() { if (this.parent && this.parent instanceof lsymbols) { this.parent.needsSelf(); } else { this.needsSelfVar = true; } };