Mercurial > repos > tabletprog
annotate jsbackend.js @ 64:38127fbf5f9d
Add sample for bug involving accesing a property of a parent object as an initial value for a new object property
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 14 Jul 2012 04:53:31 -0700 |
parents | 668f533e5284 |
children | 926b65fe92b4 |
rev | line source |
---|---|
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 var mainModule; |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
2 var modules = {}; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 function toobj(val) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 switch(typeof val) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 case 'boolean': |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 if(val) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 return mainModule.strue; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 } else { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 return mainModule.sfalse; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 case 'number': |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 return mainModule.snumber(val); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 throw new Error("can't make val into object"); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
20 function importSym(obj, src, key) |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
21 { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
22 if(!(key in src)) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
23 throw new Error(key +' not found in source object for import'); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
24 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
25 if(key in obj) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
26 throw new Error(key +' already exists in target object for import') |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
27 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
28 obj[key] = src[key]; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
29 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
30 |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
31 function doImport(obj, src, symlist) |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
32 { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
33 if (symlist === undefined) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
34 each(src, function(key,val) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
35 if (key != 'parent') { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
36 importSym(obj, src, key); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
37 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
38 }); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
39 } else { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
40 for (var i = 0; i < symlist.length; ++i) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
41 importSym(obj, src, symlist[i]); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
42 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
43 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
44 return obj; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
45 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
46 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
47 op.prototype.toJS = function(isReceiver) { |
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
48 var ret = '(' + this.left.toJS() +' '+ (this.op == '=' ? '==' : this.op) +' '+ this.right.toJS() + ')'; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 if (isReceiver) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 ret = 'toobj' + ret; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 return ret; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 }; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
55 function escapeJSName(name) |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
56 { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 name = name.replace("_", "UN_").replace(":", "CN_").replace("!", "EX_").replace('?', 'QS_').replace('@', 'AT_'); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 var reserved = {'true': true, 'false': true, 'this': true, 'if': true, 'else': true, 'NaN': true}; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 if (name in reserved) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 name = 's' + name; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 return name; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
65 symbol.prototype.toJS = function() { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
66 var name = this.cleanName(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
67 if (name == 'self') { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
68 return this.symbols.selfVar(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
69 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
70 var info = this.symbols.find(name); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
71 if (!info) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
72 throw new Error('symbol ' + name + ' not found'); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
73 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
74 var pre = ''; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
75 if (info.type == 'self') { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
76 pre = this.symbols.selfVar() + '.'; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
77 } else if(info.type == 'parent') { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
78 pre = 'this'; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
79 for (var i = 0; i < funinfo.depth; ++i) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
80 pre += '.parent'; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
81 } |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
82 } else if (info.type == 'toplevel') { |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
83 pre = 'modules.'; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
84 modules[name] = false; |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
85 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
86 return pre + escapeJSName(name); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
87 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
88 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
89 intlit.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 return this.val.toString(); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
93 floatlit.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 return this.val.toString(); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
97 strlit.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 return '"' + this.val.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + '"'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
101 listlit.prototype.toJS = function() { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
102 var ret = '['; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
103 each(this.val, function(idx, el) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
104 ret += (idx ? ', ' : '') + el.toJS(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
105 }); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
106 return ret + ']'; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
107 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
108 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
109 funcall.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 var name = this.name[this.name.length-1] == ':' ? this.name.substr(0, this.name.length-1) : this.name; |
12
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
111 if (name == 'foreign') { |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
112 if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object)) { |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
113 return null; |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
114 } else if(this.args[0] instanceof symbol) { |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
115 return this.args[0].name; |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
116 } else { |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
117 throw new Error("Unexpected AST type for foreign:"); |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
118 } |
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
119 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 var args = this.args.slice(0, this.args.length); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 if (this.receiver) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 args.splice(0, 0, this.receiver); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
124 var funinfo = this.symbols.find(name); |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
125 if (!funinfo || funinfo.def instanceof setter) { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 var receiver = args[0]; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 args.splice(0, 1); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 for (var i in args) { |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
129 args[i] = args[i].toJS(); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
131 var rJS = receiver.toJS(true); |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
132 if ((name[name.length-1] == '!' && args.length == 1) || (funinfo && funinfo.def instanceof setter)) { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
133 return '(' + rJS + '.' + escapeJSName(name.substr(0, name.length-1)) + ' = ' + args[0] + ', ' + rJS + ')'; |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
134 } else { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
135 var callee = rJS + '.' + escapeJSName(name); |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
21
diff
changeset
|
136 var callCode = callee + '(' + args.join(', ') + ')'; |
21
6c8ae6b47ab5
Small improvements to property support and elimination of setP and getP functions as they are no longer needed
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
137 if (args.length == 0) { |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
21
diff
changeset
|
138 return '(' + callee + ' instanceof Function ? ' + callCode + ' : ' + callee + ')'; |
21
6c8ae6b47ab5
Small improvements to property support and elimination of setP and getP functions as they are no longer needed
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
139 } else { |
6c8ae6b47ab5
Small improvements to property support and elimination of setP and getP functions as they are no longer needed
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
140 return callCode; |
6c8ae6b47ab5
Small improvements to property support and elimination of setP and getP functions as they are no longer needed
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
141 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
142 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
144 var ret = ''; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 switch(funinfo.type) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 case 'self': |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 if (args.length < funinfo.def.args.length || funinfo.def.args[0].name != 'self') { |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
149 var receiver = new symbol('self', this.symbols); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } else { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 var receiver = args[0]; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 args.splice(0, 1); |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
153 if (args.length == 0) { |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
154 var rJS = receiver.toJS(true); |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
155 var callee = rJS + '.' + escapeJSName(name); |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
156 |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
157 return '(' + callee + ' instanceof Function ? ' + callee + '() : ' + callee + ')'; |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
158 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
160 ret = receiver.toJS(true) + '.'; |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
161 break; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 case 'parent': |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
163 ret = 'this'; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 for (var i = 0; i < funinfo.depth; ++i) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 ret += '.parent'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
167 break; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
169 for (var i in args) { |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
170 args[i] = args[i].toJS(); |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
171 } |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
172 return ret + escapeJSName(name) + '(' + args.join(', ') + ')'; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
175 object.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 var messages = this.messages; |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
177 var compiled = []; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
178 var imports = [] |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 for (var i in messages) { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
180 if (messages[i] instanceof funcall) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
181 if (messages[i].name == 'import:' && messages[i].args.length == 1) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
182 imports.push({symbols: false, src: messages[i].args[0]}); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
183 } else if(messages[i].name == 'import:from:' && messages[i].args.length == 2) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
184 var importsyms = []; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
185 each(messages[i].args[0].val, function(i, el) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
186 if (!(el instanceof symbol)) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
187 throw new Error('Names in import:from statement must be symbols'); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
188 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
189 importsyms.push(new strlit(el.name)); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
190 }); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
191 imports.push({symbols: new listlit(importsyms), src: messages[i].args[1]}); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
192 } else { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
193 throw new Error('Only import and import:from calls allowed in object context'); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
194 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
195 } else { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
196 var js = messages[i].toJSObject(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
197 if (js) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
198 compiled.push(indent(js)); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
199 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 } |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
202 var pre = ''; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
203 var post = ''; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
204 for (var i = imports.length-1; i >= 0; i--) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
205 pre += 'doImport('; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
206 post += ', ' + imports[i].src.toJS(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
207 if (imports[i].symbols) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
208 post += ', ' + imports[i].symbols.toJS(); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
209 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
210 post += ')'; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
211 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
212 return pre+'{\n\tparent: ' + this.symbols.parentObject() + ',\n\t' + compiled.join(',\n\t') + '\n}'+post; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 object.prototype.toJSModule = function() { |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
216 this.populateSymbols(toplevel); |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
217 return '(function () {\n\tvar module = ' + indent(this.toJS()) + ';\n\treturn module;\n})' |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
220 lambda.prototype.toJS = function() { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 var args = this.args ? this.args.slice(0, this.args.length) : []; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 if (args.length && args[0].cleanName() == 'self') { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 args.splice(0, 1); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 var exprs = this.expressions; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 for (var i in args) { |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
227 args[i] = args[i].toJS(); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 var compiled = [] |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 for (var i in exprs) { |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
231 var js = exprs[i].toJS(); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 if (js) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 compiled.push(indent(js)); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 exprs = compiled; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 if (exprs.length) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 exprs[exprs.length-1] = 'return ' + exprs[exprs.length-1] + ';'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 } |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
240 return 'function (' + args.join(', ') + ') {\n\t' + (this.symbols.needsSelfVar ? 'var self = this;\n\t' : '') + exprs.join(';\n\t') + '\n}' |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 }; |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
242 lambda.prototype.toJSModule = function() { |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
243 this.populateSymbols(toplevel); |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
244 return this.toJS(); |
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
245 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
247 assignment.prototype.toJS = function() { |
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
248 var existing = this.symbols.find(this.symbol.name); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 var prefix = ''; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 if (!existing) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 prefix = 'var '; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } else { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 switch (existing.type) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 case 'self': |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 prefix = 'this.'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 break; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 case 'parent': |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 prefix = 'this.'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 for (var i = 0; i < existing.depth; ++i) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 prefix += 'parent.'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 break; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 } |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
266 var val = this.expression.toJS(); |
12
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
267 if (val === null) { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 return null; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 } |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
270 return prefix + this.symbol.toJS() + ' = ' + val; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 }; |
19
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
272 assignment.prototype.toJSObject = function() { |
132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
273 var val = this.expression.toJS(); |
12
6e4851a204a5
Add ability to load code into editor
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
274 if (val === null) { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 return null; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 } |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
277 return escapeJSName(this.symbol.name) + ': ' + val; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 }; |