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