ref: d3d073195c861b52964670b69db407429a93dd89
parent: 58b26070febbce31b02072100376d0fba818c04b
author: Tor Andersson <[email protected]>
date: Mon Jan 13 09:08:23 EST 2014
Set 'this' object for all types of function calls.
--- a/jscompile.c
+++ b/jscompile.c
@@ -214,6 +214,31 @@
emit(J, F, OP_STORE);
}
+static void ccall(JF, js_Ast *fun, js_Ast *args)
+{
+ int n;
+ switch (fun->type) {
+ case EXP_INDEX:
+ cexp(J, F, fun->a);
+ emit(J, F, OP_DUP);
+ cexp(J, F, fun->b);
+ emit(J, F, OP_LOADINDEX);
+ break;
+ case EXP_MEMBER:
+ cexp(J, F, fun->a);
+ emit(J, F, OP_DUP);
+ emitname(J, F, OP_LOADMEMBER, fun->b->string);
+ break;
+ default:
+ emit(J, F, OP_THIS);
+ cexp(J, F, fun);
+ break;
+ }
+ n = cargs(J, F, args);
+ emit(J, F, OP_CALL);
+ emit(J, F, n);
+}
+
static void cexp(JF, js_Ast *exp)
{
int then, end;
@@ -230,12 +255,12 @@
case EXP_THIS: emit(J, F, OP_THIS); break;
case EXP_OBJECT:
- emit(J, F, OP_OBJECT);
+ emit(J, F, OP_NEWOBJECT);
cobject(J, F, exp->a);
break;
case EXP_ARRAY:
- emit(J, F, OP_ARRAY);
+ emit(J, F, OP_NEWARRAY);
carray(J, F, exp->a);
break;
@@ -251,19 +276,7 @@
break;
case EXP_CALL:
- if (exp->a->type == EXP_MEMBER) {
- cexp(J, F, exp->a->a);
- emit(J, F, OP_DUP);
- emitname(J, F, OP_LOADMEMBER, exp->a->b->string);
- n = cargs(J, F, exp->b);
- emit(J, F, OP_TCALL);
- emit(J, F, n);
- } else {
- cexp(J, F, exp->a);
- n = cargs(J, F, exp->b);
- emit(J, F, OP_CALL);
- emit(J, F, n);
- }
+ ccall(J, F, exp->a, exp->b);
break;
case EXP_NEW:
--- a/jscompile.h
+++ b/jscompile.h
@@ -14,9 +14,9 @@
OP_FALSE,
OP_THIS,
- OP_ARRAY,
+ OP_NEWARRAY,
OP_ARRAYPUT,
- OP_OBJECT,
+ OP_NEWOBJECT,
OP_OBJECTPUT,
OP_FUNDEC, /* <closure> -(name)- */
@@ -33,9 +33,8 @@
OP_LOAD, /* <addr> -- <addr> <value> */
OP_STORE, /* <addr> <value> -- <value> */
- OP_CALL, /* <fun> <args...> -(numargs)- <return value> */
- OP_TCALL, /* <obj> <fun> <args...> -(numargs)- <return value> */
- OP_NEW,
+ OP_CALL, /* <thisvalue> <closure> <args...> -(numargs)- <returnvalue> */
+ OP_NEW, /* <closure> <args...> -(numargs)- <returnvalue> */
OP_DELETE, /* <addr> -- <success> */
OP_PREINC, /* <addr> -- <value+1> */
--- a/jsdump.c
+++ b/jsdump.c
@@ -632,7 +632,6 @@
jsC_dumpvalue(J, fun->klist[*p++]);
break;
case OP_CALL:
- case OP_TCALL:
case OP_NEW:
printf(" %d", *p++);
break;