annotate compiler.js @ 101:5d15b91e738a

Fix paramerized types. Remove debug print calls.
author Mike Pavone <pavone@retrodev.com>
date Thu, 09 Aug 2012 08:09:14 -0700
parents b58b19c455ec
children 648659961e0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
1 var debugprint = function() {};
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
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) {
926b65fe92b4 Do some cleanup on JS backend
Mike Pavone <pavone@retrodev.com>
parents: 84
diff changeset
16 this.ast = parseFile(this.path + '/' + this.file);
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
66
25b697c91629 Finish implementation of external module access
Mike Pavone <pavone@retrodev.com>
parents: 62
diff changeset
21 var toplevel = new topsymbols([]);
48
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
22 function topsymbols(moduledirs)
30
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
23 {
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
24 this.names = null;
48
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
25 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
26 this.nextmodulenum = 0;
31
668f533e5284 Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
27 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
28 if (typeof window === "object") {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
29 get('/src/', function(data) {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
30 self.names = {};
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
31 var fakeEl = newEl("div", {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
32 innerHTML: data.response
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
33 });
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
34 each(qall('a', fakeEl), function(idx, a) {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
35 var tpidx = a.textContent.indexOf('.tp');
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
36 if (tpidx > -1) {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
37 self.names[a.textContent.substr(0, tpidx)] = true;
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
38 }
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
39 });
31
668f533e5284 Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
40 });
36
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
41 } else {
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
42 this.names = {};
48
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
43 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
44 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
45 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
46 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
47 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
48 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
49 }
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
50 }
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
51 }
36
3b0503a67165 Add scripts for building programs via C using d8 rather than a browser
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
52 }
30
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
53 }
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
54 topsymbols.prototype.find = function(name) {
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
55 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
56 if (!this.names) {
31
668f533e5284 Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
57 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
58 }
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
59 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
60 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
61 return {
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
62 type: 'toplevel',
48
18ab96287c3a Add builtin module os containing some baisc POSIX file IO
Mike Pavone <pavone@retrodev.com>
parents: 42
diff changeset
63 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
64 };
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
65 }
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
66 return null;
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
67 }
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
68 topsymbols.prototype.getEnvType = function() {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
69 return 'void';
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
70 }
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
71 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
72 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
73 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
74 }
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
75 if (name == 'true' || name == 'false') {
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
76 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
77 }
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
78 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
79 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
80 }
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
81 return 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
82 }
30
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
83
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 function osymbols(parent)
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 this.parent = parent;
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 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
88 this.llnames = {};
42
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
89 this.needsenv = false;
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
90 this.typename = null;
59
0fd06e077afe Fix object parent
Mike Pavone <pavone@retrodev.com>
parents: 57
diff changeset
91 this.needsparent = false;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 }
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
93 osymbols.prototype.find = function(name, nestedcall, allowll) {
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
94 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
95 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
96 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
97 return {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 type: 'foreign',
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 def: this.names[name]
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 };
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 }
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
102 var ret = {
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 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
104 isll: false,
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 def: this.names[name],
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
106 selftype: this.typename
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 };
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
108 } 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
109 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
110 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
111 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
112 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
113 };
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 } 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
115 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
116 if (ret) {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 if(ret.type == 'self') {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 ret.type = 'parent';
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 ret.depth = 1;
59
0fd06e077afe Fix object parent
Mike Pavone <pavone@retrodev.com>
parents: 57
diff changeset
120 this.needsparent = true;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 } else if(ret.type == 'parent') {
59
0fd06e077afe Fix object parent
Mike Pavone <pavone@retrodev.com>
parents: 57
diff changeset
122 this.needsparent = true;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 ret.depth++;
42
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
124 } 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
125 this.needsenv = true;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 }
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
128 } else {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
129 return null;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 }
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
131 debugprint('\t//symbol type:', ret ? ret.type : 'null');
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
132 return ret;
8
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 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
135 this.names[name] = def;
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 }
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
137 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
138 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
139 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 osymbols.prototype.parentObject = function() {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 if (!this.parent) {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 return 'null';
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 return 'this';
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
24
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
146 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
147 if (curlist === undefined) {
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
148 curlist = [];
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
149 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
150 }
24
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
151 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
152 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
153 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
154 curlist.push(keys[i]);
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
155 cursyms[keys[i]] = true;
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
156 }
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
157 }
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
158 if (this.parent) {
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
159 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
160 }
fe3533494ce9 Display symbols order first by depth. Eliminate extraneous setter symbols
Mike Pavone <pavone@retrodev.com>
parents: 23
diff changeset
161 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
162 }
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
163 osymbols.prototype.getEnvType = function() {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
164 return this.parent.getEnvType();
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
165 }
42
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
166 osymbols.prototype.envVar = function() {
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
167 return this.parent.envVar();
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
168 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 function lsymbols(parent)
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 this.parent = parent;
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 this.names = {};
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
174 this.closedover = {};
38
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
175 this.declared = {};
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 this.needsSelfVar = false;
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
177 this.passthruenv = false;
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
178 this.envtype = 'void';
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
179 this.needsParentEnv = false;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 }
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
181 lsymbols.prototype.find = function(name, nestedcall, allowll) {
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
182 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
183 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
184 if (this.names[name] instanceof funcall && this.names[name].name == 'foreign:') {
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
185 var ret = {
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 type: 'foreign',
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 def: this.names[name]
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 };
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
189 } else {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
190 if (nestedcall) {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
191 this.closedover[name] = true;
55
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
192 this.passthruenv = false;
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
193 }
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
194 if (name in this.closedover) {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
195 var ret = {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
196 type: 'closedover',
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
197 def: this.names[name]
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
198 };
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
199 } else {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
200 var ret = {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
201 type: 'local',
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
202 def: this.names[name],
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
203 isdeclared: (name in this.declared)
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
204 };
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
205 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206 }
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 } 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
208 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
209 if (ret) {
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
210 if (ret.type == 'closedover') {
31
668f533e5284 Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
211 ret.type = 'upvar';
55
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
212 ret.depth = 0;
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
213 }
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
214 if (ret.type == 'upvar') {
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
215 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
216 ret.depth++;
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
217 ret.startdepth = 1;
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
218 this.needsParentEnv = true;
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
219 } else {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
220 this.passthruenv = true;
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
221 ret.startdepth = 0;
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
222 /*if (ret.depth == 0) {
55
93ddb4ad6fcb Fix some nested closure bugs
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
223 ret.depth = 1;
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
224 }*/
34
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
225 }
31
668f533e5284 Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
226 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227 }
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
228 } else {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
229 return null;
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
230 }
57
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
231 var type = ret ? ret.type : 'null';
08ae75d90dc2 Add != operator. Fix more closure bugs.
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
232 debugprint('\t//symbol type:', type , type == 'upvar' ? 'depth: ' + ret.depth : '');
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
233 return ret;
8
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 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
236 this.names[name] = def;
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
237 };
38
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
238 lsymbols.prototype.declareVar = function(name) {
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
239 this.declared[name] = true;
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
240 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241 lsymbols.prototype.selfVar = function() {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 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
243 this.parent.needsSelf();
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
244 return 'self';
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
245 } else {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
246 return 'this';
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247 }
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
248 };
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
249 lsymbols.prototype.needsSelf = function() {
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 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
251 this.parent.needsSelf();
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 this.needsSelfVar = true;
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 };
23
068d63627b16 Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
256 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
257 lsymbols.prototype.parentEnvType = function() {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
258 if (!this.parent) {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
259 return 'void';
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
260 }
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
261 return this.parent.getEnvType();
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
262 };
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
263 lsymbols.prototype.getEnvType = function() {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
264 if (this.passthruenv) {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
265 return this.parent.getEnvType();
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
266 } else {
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
267 return this.envtype;
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
268 }
a10f1b049193 Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
269 }
42
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
270 lsymbols.prototype.envVar = function() {
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
271 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
272 return 'myenv';
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
273 } else if(this.passthruenv) {
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
274 return 'env';
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
275 }
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
276 return null;
4e983fe32047 Fix closures as methods so that private vars work
Mike Pavone <pavone@retrodev.com>
parents: 38
diff changeset
277 }
8
04ae32e91598 Move compiler and test page related code out of parser.js
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
279 var mainModule;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
280
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
281 function toobj(val)
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
282 {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
283 switch(typeof val)
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
284 {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
285 case 'boolean':
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
286 if(val) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
287 return mainModule.strue;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
288 } else {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
289 return mainModule.sfalse;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
290 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
291 case 'number':
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
292 return mainModule.snumber(val);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
293 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
294 throw new Error("can't make val into object");
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
295 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
296
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
297 op.prototype.populateSymbols = function(symbols, isReceiver) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
298 this.left.populateSymbols(symbols);
97
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
299 if (this.op == '&&' || this.op == '||') {
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
300 //&& and || are syntactic sugar for if and ifnot with
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
301 //the second argument transformed into a lambda to
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
302 //achieve short-circuit evalutation
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
303 this.right = new lambda([], [this.right]);
59a94f3ad56f Added short-circuit && and || operators
Mike Pavone <pavone@retrodev.com>
parents: 96
diff changeset
304 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
305 this.right.populateSymbols(symbols);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
306 };
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
307
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
308 symbol.prototype.populateSymbols = function(symbols) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
309 this.symbols = symbols;
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
310 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
311 if (ret && (ret.type == 'self' || ret.type == 'parent')) {
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
312 symbols.find('self');
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
313 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
314 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
315
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
316 intlit.prototype.populateSymbols = function(symbols) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
317 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
318
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
319 floatlit.prototype.populateSymbols = function(symbols) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
320 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
321
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
322 strlit.prototype.populateSymbols = function(symbols) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
323 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
324
25
4d87c38404d6 List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
325 listlit.prototype.populateSymbols = function(symbols) {
38
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
326 for (var i = 0; i < this.val.length; i++) {
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
327 this.val[i].populateSymbols(symbols);
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
328 }
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
329 }
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
330
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
331 arraylit.prototype.populateSymbols = function(symbols) {
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
332 for (var i = 0; i < this.val.length; i++) {
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
333 this.val[i].populateSymbols(symbols);
e7be612fd3ae Very basic array support
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
334 }
25
4d87c38404d6 List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
335 }
4d87c38404d6 List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
336
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
337 funcall.prototype.populateSymbols = function(symbols) {
96
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
338 var isll = false;
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
339 if (this.name == 'foreign:') {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
340 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
341 return;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
342 } else {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
343 throw new Error("Unexpected AST type for foreign:");
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
344 }
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
345 } 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
346 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
347 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
348 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
349 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
350 } 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
351 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
352 }
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
353 } 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
354 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
355 }
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
356 } 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
357 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
358 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
359 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
360 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
361 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
362 } 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
363 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
364 }
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
365 } 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
366 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
367 }
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
368 } 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
369 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
370 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
371 }
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
372 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
373 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
374 var funinfo = symbols.find(name);
8a9b96888b7d Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents: 68
diff changeset
375 if (funinfo && (funinfo.type == 'self' || funinfo.type == 'parent')) {
8a9b96888b7d Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents: 68
diff changeset
376 symbols.find('self');
8a9b96888b7d Fix another symbol table/closure bug
Mike Pavone <pavone@retrodev.com>
parents: 68
diff changeset
377 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
378 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
379 this.args[i].populateSymbols(symbols, undefined, isll);
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
380 }
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
381 if (this.receiver) {
96
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
382 this.receiver.populateSymbols(symbols, undefined, isll);
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
383 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
384 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
385
25
4d87c38404d6 List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
386 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
387 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
388 }
4d87c38404d6 List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
389
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
390 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
391 var symbols = new osymbols(symbols);
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
392 for (var i in this.messages) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
393 this.messages[i].populateSymbolsObject(symbols);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
394 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
395 this.symbols = symbols;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
396 }
96
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
397 var lambdanum = 0;
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
398 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
399 if (!isll) {
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
400 this.name = 'lambda_' + lambdanum++;
84b65ee8b78b Optimize self method calls into static function calls
Mike Pavone <pavone@retrodev.com>
parents: 95
diff changeset
401 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
402 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
403 var exprs = this.expressions;
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
404 var symbols = new lsymbols(symbols);
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
405 for (var i in args) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
406 symbols.defineVar(args[i].cleanName(), null);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
407 args[i].populateSymbols(symbols);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
408 }
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
409 if (isobject && (!args.length || args[0].cleanName() != 'self')) {
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
410 symbols.defineVar('self', null);
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
411 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
412 for (var i in exprs) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
413 exprs[i].populateSymbols(symbols);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
414 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
415 this.symbols = symbols;
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
416 };
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
417
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
418 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
419 debugprint('//assignment', this.symbol.name, 'populateSymbols');
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
420 var existing = symbols.find(this.symbol.name);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
421 if (!existing) {
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
422 symbols.defineVar(this.symbol.name, this.expression);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
423 }
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
424 this.symbol.populateSymbols(symbols);
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
425 this.expression.populateSymbols(symbols);
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
426 this.symbols = symbols;
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
427 };
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
428 assignment.prototype.populateSymbolsObject = 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
429 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
430 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
431 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
432 } else {
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
433 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
434 symbols.defineMsg(this.symbol.name + '!', new setter(null));
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
435 }
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
436 this.symbol.populateSymbols(symbols);
54
976a0924e1d4 Fix closure over self var
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
437 this.expression.populateSymbols(symbols, true);
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
438 this.symbols = symbols;
16
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
439 };
59e83296e331 Add populateSymbols method to AST
Mike Pavone <pavone@retrodev.com>
parents: 8
diff changeset
440
20
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
441 function setter(fun)
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
442 {
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
443 this.fun = fun;
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
444 }
30
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
445 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
446 function getter(fun)
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
447 {
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
448 this.fun = fun;
bf03c9f0dd55 Initial work on proper property support
Mike Pavone <pavone@retrodev.com>
parents: 16
diff changeset
449 }
30
608eb70fe261 Fix some compiler bugs and do initial work on module import
Mike Pavone <pavone@retrodev.com>
parents: 25
diff changeset
450 getter.prototype.args = [new symbol('self')];
99
b58b19c455ec Initial work on type system
Mike Pavone <pavone@retrodev.com>
parents: 97
diff changeset
451