Mercurial > repos > tabletprog
comparison cbackend.js @ 72:ab6f24d6945d
Fix determination of whether a method call has an implicit self argument or not. Cleanup C warnings in output.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 14 Jul 2012 21:00:21 -0700 |
parents | ba032565c7a5 |
children | abc6f3d644a4 |
comparison
equal
deleted
inserted
replaced
70:0efd25a4958a | 72:ab6f24d6945d |
---|---|
167 if (this.receiver) { | 167 if (this.receiver) { |
168 args.splice(0, 0, this.receiver); | 168 args.splice(0, 0, this.receiver); |
169 } | 169 } |
170 var method = false; | 170 var method = false; |
171 var funinfo = this.symbols.find(name); | 171 var funinfo = this.symbols.find(name); |
172 var start = 0; | |
172 if (!funinfo || funinfo.def instanceof setter) { | 173 if (!funinfo || funinfo.def instanceof setter) { |
173 method = true; | 174 method = true; |
174 } else { | 175 } else { |
175 switch(funinfo.type) | 176 switch(funinfo.type) |
176 { | 177 { |
177 case 'self': | 178 case 'self': |
178 | 179 case 'parent': |
179 if (args.length < funinfo.def.args.length || !funinfo.def.args.length || funinfo.def.args[0].name != 'self') { | 180 var defargs = funinfo.def.args.length; |
180 args.splice(0, 0, new symbol('self', this.symbols)); | 181 if (!defargs || funinfo.def.args[0].name != 'self') { |
181 } else { | 182 defargs ++ |
182 args.splice(0, 1); | 183 } |
184 if (args.length < defargs) { | |
185 if (funinfo.type == 'self') { | |
186 args.splice(0, 0, new symbol('self', this.symbols)); | |
187 } else { | |
188 var obj = (new symbol('self', this.symbols)).toC() + '->header.'; | |
189 for (var i = 0; i < funinfo.depth; ++i) { | |
190 obj += (i ? '->' : '') + 'parent'; | |
191 } | |
192 args.splice(0, 0, ', ' + obj); | |
193 start = 1; | |
194 } | |
183 } | 195 } |
184 method = true; | 196 method = true; |
185 break; | 197 break; |
186 case 'parent': | 198 } |
187 ret = 'self'; | 199 } |
188 for (var i = 0; i < funinfo.depth; ++i) { | 200 for (var i = start; i < args.length; i++) { |
189 ret += '->parent'; | 201 args[i] = ', ' + (!i && method ? '(object *)(' : '') + args[i].toC() + (!i && method ? ')' : ''); |
190 } | |
191 break; | |
192 } | |
193 } | |
194 for (var i in args) { | |
195 args[i] = ', ' + args[i].toC(); | |
196 } | 202 } |
197 var callpart; | 203 var callpart; |
198 if (method) { | 204 if (method) { |
199 callpart = 'mcall(' + getMethodId(name) + '/* ' + name + ' */'; | 205 callpart = 'mcall(' + getMethodId(name) + '/* ' + name + ' */'; |
200 } else { | 206 } else { |
829 compiled.push(indent(js)); | 835 compiled.push(indent(js)); |
830 } | 836 } |
831 } | 837 } |
832 exprs = compiled; | 838 exprs = compiled; |
833 if (exprs.length) { | 839 if (exprs.length) { |
834 exprs[exprs.length-1] = 'return ' + exprs[exprs.length-1] + ';'; | 840 exprs[exprs.length-1] = 'return (object *)(' + exprs[exprs.length-1] + ');'; |
835 } | 841 } |
836 | 842 |
837 if (Object.keys(this.symbols.closedover).length) { | 843 if (Object.keys(this.symbols.closedover).length) { |
838 forwarddec += 'typedef struct lambda_' + mynum + '_env {\n'; | 844 forwarddec += 'typedef struct lambda_' + mynum + '_env {\n'; |
839 if (this.symbols.needsParentEnv) { | 845 if (this.symbols.needsParentEnv) { |
941 lines: [paramget + 'return ' + val + '(' + (cobj.hasenv ? 'self->env' : 'NULL') + ', ' + params.length + (params.length ? ', ' : '') + params.join(', ') + ');'] | 947 lines: [paramget + 'return ' + val + '(' + (cobj.hasenv ? 'self->env' : 'NULL') + ', ' + params.length + (params.length ? ', ' : '') + params.join(', ') + ');'] |
942 }); | 948 }); |
943 } else { | 949 } else { |
944 cobj.addProperty(this.symbol.name, val); | 950 cobj.addProperty(this.symbol.name, val); |
945 if (this.expression instanceof object && this.expression.symbols.needsparent) { | 951 if (this.expression instanceof object && this.expression.symbols.needsparent) { |
946 cobj.addInit('self->' + escapeCName(this.symbol.name) + '->parent = self;'); | 952 cobj.addInit('self->' + escapeCName(this.symbol.name) + '->parent = (object *)self;'); |
947 } | 953 } |
948 } | 954 } |
949 }; | 955 }; |