Mercurial > repos > tabletprog
comparison jsbackend.js @ 12:6e4851a204a5
Add ability to load code into editor
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 21 Mar 2012 23:13:51 -0700 |
parents | 02b20292f187 |
children | 132c7756860e |
comparison
equal
deleted
inserted
replaced
11:5447cff52da6 | 12:6e4851a204a5 |
---|---|
60 return '"' + this.val.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + '"'; | 60 return '"' + this.val.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + '"'; |
61 } | 61 } |
62 | 62 |
63 funcall.prototype.toJS = function(symbols) { | 63 funcall.prototype.toJS = function(symbols) { |
64 var name = this.name[this.name.length-1] == ':' ? this.name.substr(0, this.name.length-1) : this.name; | 64 var name = this.name[this.name.length-1] == ':' ? this.name.substr(0, this.name.length-1) : this.name; |
65 if (name == 'foreign') { | |
66 if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object)) { | |
67 return null; | |
68 } else if(this.args[0] instanceof symbol) { | |
69 return this.args[0].name; | |
70 } else { | |
71 throw new Error("Unexpected AST type for foreign:"); | |
72 } | |
73 } | |
65 var args = this.args.slice(0, this.args.length); | 74 var args = this.args.slice(0, this.args.length); |
66 if (this.receiver) { | 75 if (this.receiver) { |
67 args.splice(0, 0, this.receiver); | 76 args.splice(0, 0, this.receiver); |
68 } | 77 } |
69 var funinfo = symbols.find(name); | 78 var funinfo = symbols.find(name); |
169 prefix += 'parent.'; | 178 prefix += 'parent.'; |
170 } | 179 } |
171 break; | 180 break; |
172 } | 181 } |
173 } | 182 } |
174 if (this.expression instanceof funcall && this.expression.name == 'foreign:') { | 183 var val = this.expression.toJS(symbols); |
184 if (val === null) { | |
175 return null; | 185 return null; |
176 } | 186 } |
177 return prefix + this.symbol.toJS(symbols) + ' = ' + this.expression.toJS(symbols); | 187 return prefix + this.symbol.toJS(symbols) + ' = ' + val; |
178 }; | 188 }; |
179 assignment.prototype.toJSObject = function(symbols) { | 189 assignment.prototype.toJSObject = function(symbols) { |
180 symbols.defineMsg(this.symbol.name, this.expression); | 190 symbols.defineMsg(this.symbol.name, this.expression); |
181 if (this.expression instanceof funcall && this.expression.name == 'foreign:') { | 191 var val = this.expression.toJS(symbols); |
192 if (val === null) { | |
182 return null; | 193 return null; |
183 } | 194 } |
184 return this.symbol.toJS(symbols) + ': ' + this.expression.toJS(symbols); | 195 return this.symbol.toJS(symbols) + ': ' + val; |
185 }; | 196 }; |