]> Nishi Git Mirror - gwion.git/commitdiff
:art: Improve func call type check, enforce expression type
authorfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 21 Feb 2019 19:34:33 +0000 (20:34 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 21 Feb 2019 19:35:19 +0000 (20:35 +0100)
include/opcode.h
opcode.txt
src/emit/emit.c
src/parse/check.c
src/vm/vm.c
tests/error/template_ternary.gw [moved from tests/tree/template_ternary.gw with 56% similarity]

index 3eb434bc83268aa23a049dbd299482fd1dfab9d8..b10319aae77df53d39909495ae8fa3460e5a7fde 100644 (file)
@@ -18,7 +18,6 @@ enum {
   RegDup,
   MemSetImm,
   RegPop,
-  RegPushPtr,
   RegPushMe,
   RegPushMaybe,
   FuncReturn,
@@ -174,7 +173,6 @@ enum {
 #define  RegDup              (f_instr)RegDup
 #define  MemSetImm           (f_instr)MemSetImm
 #define  RegPop              (f_instr)RegPop
-#define  RegPushPtr          (f_instr)RegPushPtr
 #define  RegPushMe           (f_instr)RegPushMe
 #define  RegPushMaybe        (f_instr)RegPushMaybe
 #define  FuncReturn          (f_instr)FuncReturn
index db65393b43fde26237c2722d5e2d4416099ab899..bd71508383d467183d900900833036cef6be98e5 100644 (file)
@@ -15,7 +15,6 @@ RegPushBase4
 RegDup
 MemSetImm
 RegPop
-RegPushPtr
 RegPushMe
 RegPushMaybe
 FuncReturn
index 9e0388d3d4fc7e773e3ba8b0729b71e70adebb57..0351e09e8aaee94d65ef52fdc0f2cf020cae5dae 100644 (file)
@@ -708,9 +708,15 @@ assert(_instr->execute == DotTmpl);
     _instr->m_val2 = strlen(c);
     return GW_OK;
   }
-  const Instr instr = emit_add_instr(emit, RegPushPtr);
-  return !!(instr->m_val = (m_uint)f->code);
+  const Instr _instr = (Instr)vector_back(&emit->code->instr);
+  if(_instr->opcode == (m_bit)(m_uint)RegPushImm)
+    return !!(_instr->m_val = (m_uint)f->code);
+  assert(_instr->opcode == (m_bit)(m_uint)RegPushBase);
+  _instr->m_val = (m_uint)f->code;
+  _instr->opcode = (m_bit)(m_uint)RegPushImm;
+  return GW_OK;
 }
+
 static m_bool emit_template_code(const Emitter emit, const Func f) {
   if(GET_FLAG(f, ref))
     CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->def))
@@ -1574,7 +1580,7 @@ ANN /*static */m_bool emit_func_def(const Emitter emit, const Func_Def func_def)
   emit_func_def_code(emit, func);
   emit->env->func = former;
   emit_pop_code(emit);
-  if(!emit->env->class_def && !GET_FLAG(func_def, global))
+  if(!emit->env->class_def && !GET_FLAG(func_def, global) && !func_def->tmpl)
     emit_func_def_global(emit, func->value_ref);
   MEMOIZE_INI
   return GW_OK;
index 818db81b886111d0ed8937b31217583c34111074..f9a6ab580ed18434682b0650394b431ecfc0ed46 100644 (file)
@@ -364,6 +364,9 @@ ANN2(1, 2) static Func find_func_match(const Env env, const Func up, const Exp e
 }
 
 ANN static m_bool check_call(const Env env, const Exp_Call* exp) {
+  ae_exp_t et = exp->func->exp_type;
+  if(et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast)
+    ERR_B(exp->func->pos, "invalid expression for function call.")
   CHECK_OB(check_exp(env, exp->func))
   return exp->args ? !!check_exp(env, exp->args) : -1;
 }
@@ -553,7 +556,6 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) {
   Tmpl_Call tmpl = { .types=tl[0] };
   const Exp_Call tmp_func = { .func=call, .args=args, .tmpl=&tmpl, .self=base };
   const Func func = get_template_func(env, &tmp_func, base, value);
-//exit(2);
   if(base->exp_type == ae_exp_call)
     base->d.exp_call.m_func = func;
   else // if(base->exp_type == ae_exp_binary)
index edb3e093da8b3c378b44742ea45878c912fa835c..bb1a78e74fe54bb511f29f29fde027e96b078110 100644 (file)
@@ -228,7 +228,7 @@ ANN void vm_run(const VM* vm) {
     &&baseint, &&basefloat, &&baseother, &&baseaddr,
     &&regdup,
     &&memsetimm,
-    &&regpop, &&regpushptr, &&regpushme, &&regpushmaybe,
+    &&regpop, &&regpushme, &&regpushmaybe,
     &&funcreturn,
     &&_goto,
     &&allocint, &&allocfloat, &&allocother, &&allocaddr,
@@ -367,9 +367,6 @@ memsetimm:
 regpop:
   reg -= instr->m_val;
   DISPATCH();
-regpushptr:
-  *(m_uint*)(reg-SZ_INT) = instr->m_val;
-  DISPATCH()
 regpushme:
   *(M_Object*)reg = shred->info->me;
   reg += SZ_INT;
similarity index 56%
rename from tests/tree/template_ternary.gw
rename to tests/error/template_ternary.gw
index 606877145730856c64e32c634f34d7607c3b8597..792855329285dc90ad0cc015209fd7df168b2e65 100644 (file)
@@ -1,3 +1,4 @@
+// [contains] invalid expression for function call
 template<~A~>
 function void test(A a){}