Mercurial > repos > tabletprog
annotate compiler.js @ 259:32964a4e7a33
Add ltrim method to string
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 29 May 2014 18:51:15 -0700 |
parents | 2557ce4e671f |
children | d6a4c9e7716e |
rev | line source |
---|---|
54 | 1 var debugprint = function() {}; |
2 | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 function indent(str) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 return str.split('\n').join('\n\t'); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
8 function modulefile(path, file) |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
9 { |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
10 this.path = path; |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
11 this.file = file; |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
12 } |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
13 |
95
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
14 modulefile.prototype.populateSymbols = function (toplevel) { |
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
15 if (!this.ast) { |
251
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
16 this.ast = parseFile(this.path + '/' + this.file).macroexpand(toplevel.topenv); |
95
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
17 this.ast.populateSymbols(toplevel); |
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
18 } |
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
19 }; |
926b65fe92b4
Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
20 |
104 | 21 modulefile.prototype.popuplateSymbolsAsync = function(toplevel, whenDone) { |
22 if (!this.ast) { | |
23 var self = this; | |
24 get(this.path + '/' + this.file, function(data) { | |
207
60eff5f81d9a
Basic implementation of macros is now working
Mike Pavone <pavone@retrodev.com>
parents:
201
diff
changeset
|
25 //TODO: macro expand in the async case |
104 | 26 self.ast = parser.parse(data.responseText); |
27 self.ast.populateSymbols(toplevel); | |
28 whenDone(); | |
29 }); | |
30 } else { | |
31 whenDone(); | |
32 } | |
33 }; | |
34 | |
35 function getfileshtml(path, data, names) | |
36 { | |
37 var fakeEl = newEl("div", { | |
38 innerHTML: data.response | |
39 }); | |
40 each(qall('a', fakeEl), function(idx, a) { | |
41 var tpidx = a.textContent.indexOf('.tp'); | |
42 var modname = a.textContent.substr(0, tpidx); | |
43 if (tpidx > -1) { | |
44 names[modname] = new modulefile(path, modname + '.tp'); | |
45 } | |
46 }); | |
47 } | |
48 | |
251
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
49 var toplevel = null;//new topsymbols([]); |
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
50 function topsymbols(moduledirs, top) |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
51 { |
251
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
52 if (!top) { |
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
53 top = new topenv(moduledirs); |
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
54 } |
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
55 this.topenv = top; |
2557ce4e671f
Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
Michael Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
56 this.moduledirs = moduledirs; |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
57 this.names = null; |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
58 this.used = {}; |
68
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
59 this.nextmodulenum = 0; |
104 | 60 this.onready = null; |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
61 var self = this; |
36
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
62 if (typeof window === "object") { |
104 | 63 get('/modules/', function(data) { |
64 var names = {} | |
65 getfileshtml('/modules', data, names); | |
66 get('/src/', function(data) { | |
67 getfileshtml('/src', data, names); | |
68 self.names = names; | |
69 if (self.onready) { | |
70 self.onready(); | |
36
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
71 } |
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
72 }); |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
73 }); |
36
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
74 } else { |
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
75 this.names = {}; |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
76 for (var dirnum in moduledirs) { |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
77 var results = os.system("ls", [moduledirs[dirnum]]).split('\n'); |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
78 for (var i in results) { |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
79 var tpidx = results[i].indexOf('.tp') |
68
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
80 if (tpidx > 0 && tpidx == results[i].length - 3) { |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
81 this.names[results[i].substr(0, tpidx)] = new modulefile(moduledirs[dirnum], results[i]); |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
82 } |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
83 } |
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
84 } |
36
3b0503a67165
Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
85 } |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
86 } |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
87 topsymbols.prototype.find = function(name) { |
54 | 88 debugprint('//topsymbols.find', name, name in this.names); |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
89 if (!this.names) { |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
90 throw new Error('data not ready'); |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
91 } |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
92 if (name in this.names) { |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
93 this.used[name] = true; |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
94 return { |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
95 type: 'toplevel', |
48
18ab96287c3a
Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents:
42
diff
changeset
|
96 def: this.names[name] |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
97 }; |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
98 } |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
99 return null; |
104 | 100 }; |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
101 topsymbols.prototype.getEnvType = function() { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
102 return 'void'; |
104 | 103 }; |
68
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
104 topsymbols.prototype.moduleVar = function(name) { |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
105 if (!(name in this.names)) { |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
106 throw new Error('symbol ' + name + ' not found at toplevel'); |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
107 } |
170
18598163e3ef
Add linked list implementation and cons operator
Mike Pavone <pavone@retrodev.com>
parents:
110
diff
changeset
|
108 if (name == 'true' || name == 'false' || name == 'list') { |
68
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
109 return 'module_' + name; |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
110 } |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
111 if (!this.names[name].modulevar) { |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
112 this.names[name].modulevar = 'module_' + this.nextmodulenum++ |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
113 } |
3a169ebb3224
Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
Mike Pavone <pavone@retrodev.com>
parents:
66
diff
changeset
|
114 return this.names[name].modulevar; |
104 | 115 }; |
116 topsymbols.prototype.onReady = function(fun) { | |
117 if (this.names) { | |
118 fun(); | |
119 return; | |
120 } | |
121 if (!this.onready) { | |
122 this.onready = fun; | |
123 } else { | |
124 var oldready = this.onready; | |
125 this.onready = function() { | |
126 oldready(); | |
127 fun(); | |
128 }; | |
129 } | |
130 }; | |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
131 |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 function osymbols(parent) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 this.parent = parent; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 this.names = {}; |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
136 this.llnames = {}; |
42
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
137 this.needsenv = false; |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
138 this.typename = null; |
59 | 139 this.needsparent = false; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
141 osymbols.prototype.find = function(name, nestedcall, allowll) { |
54 | 142 debugprint('//osymbols.find', name + ', exists?:', name in this.names, ', nested?:', nestedcall); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 if (name in this.names) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 return { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 type: 'foreign', |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 def: this.names[name] |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 }; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 } |
54 | 150 var ret = { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 type: 'self', |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
152 isll: false, |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 def: this.names[name], |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
154 selftype: this.typename |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 }; |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
156 } else if(allowll && name in this.llnames) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
157 return { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
158 type: 'self', |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
159 isll: true, |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
160 selftype: this.typename |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
161 }; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } else if(this.parent) { |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
163 var ret = this.parent.find(name, nestedcall, allowll); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 if (ret) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 if(ret.type == 'self') { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 ret.type = 'parent'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 ret.depth = 1; |
59 | 168 this.needsparent = true; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 } else if(ret.type == 'parent') { |
59 | 170 this.needsparent = true; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 ret.depth++; |
42
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
172 } else if(ret.type == 'closedover' || ret.type == 'upvar') { |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
173 this.needsenv = true; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 } |
54 | 176 } else { |
177 return null; | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 } |
54 | 179 debugprint('\t//symbol type:', ret ? ret.type : 'null'); |
180 return ret; | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 }; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 osymbols.prototype.defineMsg = function(name, def) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 this.names[name] = def; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 } |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
185 osymbols.prototype.defineLLProperty = function(name) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
186 this.llnames[name] = true; |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
187 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 osymbols.prototype.parentObject = function() { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 if (!this.parent) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 return 'null'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 return 'this'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
24
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
194 osymbols.prototype.allSymbols = function(curlist, cursyms) { |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
195 if (curlist === undefined) { |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
196 curlist = []; |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
197 cursyms = {}; |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
198 } |
24
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
199 var keys = Object.keys(this.names).sort(); |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
200 for (var i in keys) { |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
201 if (!(keys[i] in cursyms)) { |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
202 curlist.push(keys[i]); |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
203 cursyms[keys[i]] = true; |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
204 } |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
205 } |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
206 if (this.parent) { |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
207 return this.parent.allSymbols(curlist, cursyms); |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
208 } |
fe3533494ce9
Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
209 return curlist; |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
210 } |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
211 osymbols.prototype.getEnvType = function() { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
212 return this.parent.getEnvType(); |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
213 } |
42
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
214 osymbols.prototype.envVar = function() { |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
215 return this.parent.envVar(); |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
216 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 function lsymbols(parent) |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 this.parent = parent; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 this.names = {}; |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
222 this.closedover = {}; |
38 | 223 this.declared = {}; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 this.needsSelfVar = false; |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
225 this.passthruenv = false; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
226 this.envtype = 'void'; |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
227 this.needsParentEnv = false; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 } |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
229 lsymbols.prototype.find = function(name, nestedcall, allowll) { |
54 | 230 debugprint('//lsymbols.find', name + ', exists?:', name in this.names, ', nested?:', nestedcall); |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 if (name in this.names) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') { |
54 | 233 var ret = { |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 type: 'foreign', |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 def: this.names[name] |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 }; |
54 | 237 } else { |
196
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
238 if (nestedcall && !(name in this.closedover)) { |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
239 debugprint('//symbol', name, 'is now closed over'); |
54 | 240 this.closedover[name] = true; |
55
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
241 this.passthruenv = false; |
156
d6e79885bd3b
Fix compiler bug involving referencing a self method in a method defined before the referenced method
Mike Pavone <pavone@retrodev.com>
parents:
110
diff
changeset
|
242 } |
54 | 243 if (name in this.closedover) { |
244 var ret = { | |
245 type: 'closedover', | |
246 def: this.names[name] | |
247 }; | |
248 } else { | |
249 var ret = { | |
250 type: 'local', | |
251 def: this.names[name], | |
252 isdeclared: (name in this.declared) | |
253 }; | |
254 } | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 } else if(this.parent) { |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
257 var ret = this.parent.find(name, true, allowll); |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
258 if (ret) { |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
259 if (ret.type == 'closedover') { |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
260 ret.type = 'upvar'; |
55
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
261 ret.depth = 0; |
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
262 } |
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
263 if (ret.type == 'upvar') { |
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
264 if (Object.keys(this.closedover).length) { |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
265 ret.depth++; |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
266 ret.startdepth = 1; |
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
267 this.needsParentEnv = true; |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
268 } else { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
269 this.passthruenv = true; |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
270 ret.startdepth = 0; |
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
271 /*if (ret.depth == 0) { |
55
93ddb4ad6fcb
Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
272 ret.depth = 1; |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
273 }*/ |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
274 } |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
30
diff
changeset
|
275 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 } |
54 | 277 } else { |
278 return null; | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 } |
57
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
280 var type = ret ? ret.type : 'null'; |
08ae75d90dc2
Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
281 debugprint('\t//symbol type:', type , type == 'upvar' ? 'depth: ' + ret.depth : ''); |
54 | 282 return ret; |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 }; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 lsymbols.prototype.defineVar = function(name, def) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 this.names[name] = def; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 }; |
38 | 287 lsymbols.prototype.declareVar = function(name) { |
288 this.declared[name] = true; | |
289 } | |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 lsymbols.prototype.selfVar = function() { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 if (this.parent && this.parent instanceof lsymbols) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 this.parent.needsSelf(); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 return 'self'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 } else { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 return 'this'; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 }; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 lsymbols.prototype.needsSelf = function() { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 if (this.parent && this.parent instanceof lsymbols) { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 this.parent.needsSelf(); |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 } else { |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 this.needsSelfVar = true; |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 } |
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 }; |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
305 lsymbols.prototype.allSymbols = osymbols.prototype.allSymbols; |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
306 lsymbols.prototype.parentEnvType = function() { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
307 if (!this.parent) { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
308 return 'void'; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
309 } |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
310 return this.parent.getEnvType(); |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
311 }; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
312 lsymbols.prototype.getEnvType = function() { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
313 if (this.passthruenv) { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
314 return this.parent.getEnvType(); |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
315 } else { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
316 return this.envtype; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
317 } |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
318 } |
42
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
319 lsymbols.prototype.envVar = function() { |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
320 if (Object.keys(this.closedover).length) { |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
321 return 'myenv'; |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
322 } else if(this.passthruenv) { |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
323 return 'env'; |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
324 } |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
325 return null; |
4e983fe32047
Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents:
38
diff
changeset
|
326 } |
8
04ae32e91598
Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
328 var mainModule; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
329 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
330 function toobj(val) |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
331 { |
110
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
104
diff
changeset
|
332 return (typeof val == "boolean") ? (val ? module_true : module_false) : val; |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
333 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
334 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
335 op.prototype.populateSymbols = function(symbols, isReceiver) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
336 this.left.populateSymbols(symbols); |
97
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
337 if (this.op == '&&' || this.op == '||') { |
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
338 //&& and || are syntactic sugar for if and ifnot with |
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
339 //the second argument transformed into a lambda to |
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
340 //achieve short-circuit evalutation |
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
341 this.right = new lambda([], [this.right]); |
59a94f3ad56f
Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents:
96
diff
changeset
|
342 } |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
343 this.right.populateSymbols(symbols); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
344 }; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
345 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
346 symbol.prototype.populateSymbols = function(symbols) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
347 this.symbols = symbols; |
54 | 348 var ret = symbols.find(this.cleanName()); |
60
ef3b34c2c0a4
Fix populatesymbols for parent property references. Fix lambda-style modules in cbackend.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
349 if (ret && (ret.type == 'self' || ret.type == 'parent')) { |
54 | 350 symbols.find('self'); |
351 } | |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
352 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
353 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
354 intlit.prototype.populateSymbols = function(symbols) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
355 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
356 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
357 floatlit.prototype.populateSymbols = function(symbols) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
358 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
359 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
360 strlit.prototype.populateSymbols = function(symbols) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
361 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
362 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
363 listlit.prototype.populateSymbols = function(symbols) { |
38 | 364 for (var i = 0; i < this.val.length; i++) { |
365 this.val[i].populateSymbols(symbols); | |
366 } | |
367 } | |
368 | |
369 arraylit.prototype.populateSymbols = function(symbols) { | |
370 for (var i = 0; i < this.val.length; i++) { | |
371 this.val[i].populateSymbols(symbols); | |
372 } | |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
373 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
374 |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
375 funcall.prototype.populateSymbols = function(symbols) { |
96
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
376 var isll = false; |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
377 if (this.name == 'foreign:') { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
378 if ((this.args[0] instanceof lambda) || (this.args[0] instanceof object) || (this.args[0] instanceof symbol)) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
379 return; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
380 } else { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
381 throw new Error("Unexpected AST type for foreign:"); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
382 } |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
383 } else if (this.name == 'llProperty:withType:') { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
384 if (this.args[0] instanceof symbol) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
385 if ((this.args[1] instanceof symbol) || (this.args[1] instanceof funcall)) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
386 symbols.defineLLProperty(this.args[0].name); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
387 return; |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
388 } else { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
389 throw new Error("Second argument to llProperty:withType: must be a symbol or funcall"); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
390 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
391 } else { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
392 throw new Error("First argument to llProperty:withType: must be a symbol"); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
393 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
394 } else if (this.name == 'llMessage:withVars:andCode:') { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
395 if (this.args[0] instanceof symbol) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
396 if (this.args[1] instanceof lambda) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
397 if (this.args[2] instanceof lambda) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
398 symbols.defineMsg(this.args[0].name, this.args[2]); |
96
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
399 isll = true; |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
400 } else { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
401 throw new Error("Third argument to llMessage:withVars:andCode: must be a lambda"); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
402 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
403 } else { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
404 throw new Error("Second argument to llMessage:withVars:andCode: must be a lambda"); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
405 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
406 } else { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
407 throw new Error("First argument to llMessage:withVars:andCode: must be a symbol"); |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
408 } |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
409 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
410 this.symbols = symbols; |
62
f57b2f4048d0
Fix funcall.populateSymbols to use the fixed up name when doing the initial symbol.find. This ensures the parent tree is properly produced
Mike Pavone <pavone@retrodev.com>
parents:
60
diff
changeset
|
411 var name = this.name[this.name.length-1] == ':' ? this.name.substr(0, this.name.length-1) : this.name; |
77
8a9b96888b7d
Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents:
68
diff
changeset
|
412 var funinfo = symbols.find(name); |
8a9b96888b7d
Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents:
68
diff
changeset
|
413 if (funinfo && (funinfo.type == 'self' || funinfo.type == 'parent')) { |
8a9b96888b7d
Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents:
68
diff
changeset
|
414 symbols.find('self'); |
8a9b96888b7d
Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents:
68
diff
changeset
|
415 } |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
416 for (var i in this.args) { |
96
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
417 this.args[i].populateSymbols(symbols, undefined, isll); |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
418 } |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
419 if (this.receiver) { |
96
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
420 this.receiver.populateSymbols(symbols, undefined, isll); |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
421 } |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
422 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
423 |
196
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
424 funcall.prototype.defineSymbolsObject = function(symbols) { |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
425 } |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
426 |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
427 funcall.prototype.populateSymbolsObject = function(symbols) { |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
428 this.populateSymbols(symbols); |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
429 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
430 |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
431 object.prototype.populateSymbols = function(symbols) { |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
77
diff
changeset
|
432 var symbols = new osymbols(symbols); |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
433 for (var i in this.messages) { |
196
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
434 this.messages[i].defineSymbolsObject(symbols); |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
435 } |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
436 for (var i in this.messages) { |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
437 this.messages[i].populateSymbolsObject(symbols); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
438 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
439 this.symbols = symbols; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
440 } |
96
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
441 var lambdanum = 0; |
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
442 lambda.prototype.populateSymbols = function(symbols, isobject, isll) { |
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
443 if (!isll) { |
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
444 this.name = 'lambda_' + lambdanum++; |
84b65ee8b78b
Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents:
95
diff
changeset
|
445 } |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
446 var args = this.args ? this.args.slice(0, this.args.length) : []; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
447 var exprs = this.expressions; |
54 | 448 var symbols = new lsymbols(symbols); |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
449 for (var i in args) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
450 symbols.defineVar(args[i].cleanName(), null); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
451 args[i].populateSymbols(symbols); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
452 } |
54 | 453 if (isobject && (!args.length || args[0].cleanName() != 'self')) { |
454 symbols.defineVar('self', null); | |
455 } | |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
456 for (var i in exprs) { |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
457 exprs[i].populateSymbols(symbols); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
458 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
459 this.symbols = symbols; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
460 }; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
461 |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
462 assignment.prototype.populateSymbols = function(symbols) { |
62
f57b2f4048d0
Fix funcall.populateSymbols to use the fixed up name when doing the initial symbol.find. This ensures the parent tree is properly produced
Mike Pavone <pavone@retrodev.com>
parents:
60
diff
changeset
|
463 debugprint('//assignment', this.symbol.name, 'populateSymbols'); |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
464 var existing = symbols.find(this.symbol.name); |
201
d2e0664ba73e
Don't allow assignments to module variables
Mike Pavone <pavone@retrodev.com>
parents:
196
diff
changeset
|
465 if (!existing || existing.type == 'toplevel') { |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
466 symbols.defineVar(this.symbol.name, this.expression); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
467 } |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
468 this.symbol.populateSymbols(symbols); |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
469 this.expression.populateSymbols(symbols); |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
470 this.symbols = symbols; |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
471 }; |
196
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
472 assignment.prototype.defineSymbolsObject = function(symbols) { |
62
f57b2f4048d0
Fix funcall.populateSymbols to use the fixed up name when doing the initial symbol.find. This ensures the parent tree is properly produced
Mike Pavone <pavone@retrodev.com>
parents:
60
diff
changeset
|
473 debugprint('//messagedef', this.symbol.name, 'populateSymbols'); |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
474 if (this.expression instanceof lambda || (this.expression instanceof funcall & this.expression.name == 'foreign:')) { |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
475 symbols.defineMsg(this.symbol.name, this.expression); |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
476 } else { |
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
477 symbols.defineMsg(this.symbol.name, new getter(null)); |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
478 symbols.defineMsg(this.symbol.name + '!', new setter(null)); |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
479 } |
196
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
480 }; |
228df5004ab5
Define methods in an object before running populate symbols on those methods to avoid a bug in which self was not properly marked as closed over due to a method not being defined when a symbol search was done
Mike Pavone <pavone@retrodev.com>
parents:
171
diff
changeset
|
481 assignment.prototype.populateSymbolsObject = function(symbols) { |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
482 this.symbol.populateSymbols(symbols); |
54 | 483 this.expression.populateSymbols(symbols, true); |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
484 this.symbols = symbols; |
16
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
485 }; |
59e83296e331
Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
486 |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
487 function setter(fun) |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
488 { |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
489 this.fun = fun; |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
490 } |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
491 setter.prototype.args = [new symbol('self'), new symbol('newval')]; |
20
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
492 function getter(fun) |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
493 { |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
494 this.fun = fun; |
bf03c9f0dd55
Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
495 } |
30
608eb70fe261
Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
496 getter.prototype.args = [new symbol('self')]; |
99
b58b19c455ec
Initial work on type system
Mike Pavone <pavone@retrodev.com>
parents:
97
diff
changeset
|
497 |