comparison jsbackend.js @ 31:668f533e5284

Add initial version of C backend
author Mike Pavone <pavone@retrodev.com>
date Sat, 07 Jul 2012 16:48:36 -0700
parents 608eb70fe261
children 926b65fe92b4
comparison
equal deleted inserted replaced
30:608eb70fe261 31:668f533e5284
1 var mainModule; 1 var mainModule;
2 var modules = {};
2 3
3 function toobj(val) 4 function toobj(val)
4 { 5 {
5 switch(typeof val) 6 switch(typeof val)
6 { 7 {
76 } else if(info.type == 'parent') { 77 } else if(info.type == 'parent') {
77 pre = 'this'; 78 pre = 'this';
78 for (var i = 0; i < funinfo.depth; ++i) { 79 for (var i = 0; i < funinfo.depth; ++i) {
79 pre += '.parent'; 80 pre += '.parent';
80 } 81 }
82 } else if (info.type == 'toplevel') {
83 pre = 'modules.';
84 modules[name] = false;
81 } 85 }
82 return pre + escapeJSName(name); 86 return pre + escapeJSName(name);
83 } 87 }
84 88
85 intlit.prototype.toJS = function() { 89 intlit.prototype.toJS = function() {
207 } 211 }
208 return pre+'{\n\tparent: ' + this.symbols.parentObject() + ',\n\t' + compiled.join(',\n\t') + '\n}'+post; 212 return pre+'{\n\tparent: ' + this.symbols.parentObject() + ',\n\t' + compiled.join(',\n\t') + '\n}'+post;
209 } 213 }
210 214
211 object.prototype.toJSModule = function() { 215 object.prototype.toJSModule = function() {
212 this.populateSymbols(null); 216 this.populateSymbols(toplevel);
213 return '(function () {\n\tvar module = ' + indent(this.toJS()) + ';\n\treturn module;\n})' 217 return '(function () {\n\tvar module = ' + indent(this.toJS()) + ';\n\treturn module;\n})'
214 } 218 }
215 219
216 lambda.prototype.toJS = function() { 220 lambda.prototype.toJS = function() {
217 var args = this.args ? this.args.slice(0, this.args.length) : []; 221 var args = this.args ? this.args.slice(0, this.args.length) : [];
234 exprs[exprs.length-1] = 'return ' + exprs[exprs.length-1] + ';'; 238 exprs[exprs.length-1] = 'return ' + exprs[exprs.length-1] + ';';
235 } 239 }
236 return 'function (' + args.join(', ') + ') {\n\t' + (this.symbols.needsSelfVar ? 'var self = this;\n\t' : '') + exprs.join(';\n\t') + '\n}' 240 return 'function (' + args.join(', ') + ') {\n\t' + (this.symbols.needsSelfVar ? 'var self = this;\n\t' : '') + exprs.join(';\n\t') + '\n}'
237 }; 241 };
238 lambda.prototype.toJSModule = function() { 242 lambda.prototype.toJSModule = function() {
239 this.populateSymbols(null); 243 this.populateSymbols(toplevel);
240 return this.toJS(); 244 return this.toJS();
241 } 245 }
242 246
243 assignment.prototype.toJS = function() { 247 assignment.prototype.toJS = function() {
244 var existing = this.symbols.find(this.symbol.name); 248 var existing = this.symbols.find(this.symbol.name);