comparison compiler.js @ 30:608eb70fe261

Fix some compiler bugs and do initial work on module import
author Mike Pavone <pavone@retrodev.com>
date Thu, 19 Apr 2012 19:20:21 -0700
parents 4d87c38404d6
children 668f533e5284
comparison
equal deleted inserted replaced
29:18cec540238a 30:608eb70fe261
1 function indent(str) 1 function indent(str)
2 { 2 {
3 return str.split('\n').join('\n\t'); 3 return str.split('\n').join('\n\t');
4 }
5
6 function topsymbols()
7 {
8 this.names = null;
9 }
10 topsymbols.prototype.find = function(name) {
11 if (!this.names) {
12
13 }
14 if (name in this.names) {
15 return {
16 type: 'toplevel',
17 def: null
18 };
19 }
20 return null;
4 } 21 }
5 22
6 function osymbols(parent) 23 function osymbols(parent)
7 { 24 {
8 this.parent = parent; 25 this.parent = parent;
9 this.names = {}; 26 this.names = {};
10 this.lastname = null;
11 } 27 }
12 osymbols.prototype.find = function(name) { 28 osymbols.prototype.find = function(name) {
13 if (name in this.names) { 29 if (name in this.names) {
14 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { 30 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') {
15 return { 31 return {
34 return ret; 50 return ret;
35 } 51 }
36 return null; 52 return null;
37 }; 53 };
38 osymbols.prototype.defineMsg = function(name, def) { 54 osymbols.prototype.defineMsg = function(name, def) {
39 this.lastname = name;
40 this.names[name] = def; 55 this.names[name] = def;
41 } 56 }
42 osymbols.prototype.parentObject = function() { 57 osymbols.prototype.parentObject = function() {
43 if (!this.parent) { 58 if (!this.parent) {
44 return 'null'; 59 return 'null';
65 80
66 function lsymbols(parent) 81 function lsymbols(parent)
67 { 82 {
68 this.parent = parent; 83 this.parent = parent;
69 this.names = {}; 84 this.names = {};
70 this.lastname = null;
71 this.needsSelfVar = false; 85 this.needsSelfVar = false;
72 } 86 }
73 lsymbols.prototype.find = function(name) { 87 lsymbols.prototype.find = function(name) {
74 if (name in this.names) { 88 if (name in this.names) {
75 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { 89 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') {
90 return ret; 104 return ret;
91 } 105 }
92 return null; 106 return null;
93 }; 107 };
94 lsymbols.prototype.defineVar = function(name, def) { 108 lsymbols.prototype.defineVar = function(name, def) {
95 this.lastname = name;
96 this.names[name] = def; 109 this.names[name] = def;
97 }; 110 };
98 lsymbols.prototype.selfVar = function() { 111 lsymbols.prototype.selfVar = function() {
99 if (this.parent && this.parent instanceof lsymbols) { 112 if (this.parent && this.parent instanceof lsymbols) {
100 this.parent.needsSelf(); 113 this.parent.needsSelf();
208 this.symbol.populateSymbols(symbols); 221 this.symbol.populateSymbols(symbols);
209 this.expression.populateSymbols(symbols); 222 this.expression.populateSymbols(symbols);
210 this.symbols = symbols; 223 this.symbols = symbols;
211 }; 224 };
212 assignment.prototype.populateSymbolsObject = function(symbols) { 225 assignment.prototype.populateSymbolsObject = function(symbols) {
213 symbols.defineMsg(this.symbol.name, this.expression); 226 if (this.expression instanceof lambda || (this.expression instanceof funcall & this.expression.name == 'foreign:')) {
214 if (!(this.expression instanceof lambda) && !(this.expression instanceof funcall && this.expression.name == 'foreign:')) { 227 symbols.defineMsg(this.symbol.name, this.expression);
228 } else {
229 symbols.defineMsg(this.symbol.name, new getter(null));
215 symbols.defineMsg(this.symbol.name + '!', new setter(null)); 230 symbols.defineMsg(this.symbol.name + '!', new setter(null));
216 } 231 }
217 this.symbol.populateSymbols(symbols); 232 this.symbol.populateSymbols(symbols);
218 this.expression.populateSymbols(symbols); 233 this.expression.populateSymbols(symbols);
219 this.symbols = symbols; 234 this.symbols = symbols;
221 236
222 function setter(fun) 237 function setter(fun)
223 { 238 {
224 this.fun = fun; 239 this.fun = fun;
225 } 240 }
226 241 setter.prototype.args = [new symbol('self'), new symbol('newval')];
227 function getter(fun) 242 function getter(fun)
228 { 243 {
229 this.fun = fun; 244 this.fun = fun;
230 } 245 }
231 246 getter.prototype.args = [new symbol('self')];