]> Nishi Git Mirror - gwion.git/commitdiff
:bug: Fix member Spork/Lambda
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Mar 2019 10:58:46 +0000 (11:58 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Mar 2019 10:58:46 +0000 (11:58 +0100)
ast
src/emit/emit.c
src/parse/check.c
src/vm/vm.c
tests/error/lambda_mismatch1.gw
tests/error/lambda_mismatch2.gw
tests/error/lambda_mismatch3.gw
tests/new/lambda.gw
tests/new/lambda2.gw
tests/new/lambda3.gw
util

diff --git a/ast b/ast
index b10c0fd3b94edab4cb7881f9454529ef536dc5c6..9dd3e3748de42cc3abe9006d5220b7aec821b612 160000 (submodule)
--- a/ast
+++ b/ast
@@ -1 +1 @@
-Subproject commit b10c0fd3b94edab4cb7881f9454529ef536dc5c6
+Subproject commit 9dd3e3748de42cc3abe9006d5220b7aec821b612
index d80b0d4c8a9fe5a564f46c743dd09a945d450a0f..1167759918ae7300e9f5863587419a582cafd649 100644 (file)
@@ -906,13 +906,15 @@ ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If* exp_if) { GWDEBU
 
 ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda) { GWDEBUG_EXE
   if(lambda->def) {
-  const m_uint scope = !lambda->owner ?
-    emit->env->scope->depth : emit_push_type(emit, lambda->owner);
-  CHECK_BB(emit_func_def(emit, lambda->def))
-  const Instr instr = emit_add_instr(emit, RegPushImm);
-  instr->m_val = (m_uint)lambda->def->func->code;
-  if(lambda->owner)
-    emit_pop(emit, scope);
+    const m_uint scope = !lambda->owner ?
+      emit->env->scope->depth : emit_push_type(emit, lambda->owner);
+    CHECK_BB(emit_func_def(emit, lambda->def))
+    if(GET_FLAG(lambda->def, member))
+      emit_add_instr(emit, RegPushMem);
+    const Instr instr = emit_add_instr(emit, RegPushImm);
+    instr->m_val = (m_uint)lambda->def->func->code;
+    if(lambda->owner)
+      emit_pop(emit, scope);
   } else
     emit_add_instr(emit, RegPushImm);
   return GW_OK;
@@ -929,7 +931,7 @@ ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) {
       const Instr instr = emit_add_instr(emit, RegAddRef);
       instr->m_val = exp->emit_var;
     }
-    if(emit->env->func && isa(exp->type, t_function) > 0 &&
+    if(emit->env->func && isa(exp->type, t_lambda) < 0 && isa(exp->type, t_function) > 0 &&
         !GET_FLAG(exp->type->d.func->value_ref->d.func_ref, pure))
       UNSET_FLAG(emit->env->func, pure);
   } while((exp = exp->next));
index 060338f1c59a91f1a1cbd71a223b8b7d9fe1f144..f3e51c47b830ad13f5c67162a523e2cc54c64368 100644 (file)
@@ -319,18 +319,18 @@ ANN static m_bool func_match_inner(const Env env, const Exp e, const Type t,
   const m_bool match = (specific ? e->type == t : isa(e->type, t) > 0) &&
     e->type->array_depth == t->array_depth &&
     array_base(e->type) == array_base(t);
-  if(!match) {
-    if(e->type == t_lambda && isa(t, t_fptr) > 0) {
-      const Type owner = nspc_lookup_type1(t->owner->parent,
-        insert_symbol(t->owner->name));
-      return check_lambda(env, owner, &e->d.exp_lambda, t->d.func->def);
+    if(!match) {
+      if(e->type == t_lambda && isa(t, t_fptr) > 0) {
+        const Type owner = nspc_lookup_type1(t->owner->parent,
+          insert_symbol(t->owner->name));
+        return check_lambda(env, owner, &e->d.exp_lambda, t->d.func->def);
+      }
+      if(implicit) {
+        const struct Implicit imp = { e, t };
+        struct Op_Import opi = { .op=op_impl, .lhs=e->type, .rhs=t, .data=(m_uint)&imp };
+      return op_check(env, &opi) ? 1 : -1;
     }
   }
-  if(implicit) {
-    const struct Implicit imp = { e, t };
-    struct Op_Import opi = { .op=op_impl, .lhs=e->type, .rhs=t, .data=(m_uint)&imp };
-    return op_check(env, &opi) ? 1 : -1;
-  }
   return match ? 1 : -1;
 }
 
@@ -585,6 +585,8 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
     ERR_O(exp->self->pos, "argument number does not match for lambda")
   l->def = new_func_def(NULL, l->name, l->arg, l->code, 0);
   CHECK_BO(traverse_func_def(env, l->def))
+  if(env->class_def)
+    SET_FLAG(l->def, member);
   set_call(exp->self, l->def->func);
   return l->def->ret_type ?: (l->def->ret_type = t_void);
 }
@@ -752,7 +754,8 @@ ANN static inline Type check_exp(const Env env, const Exp exp) { GWDEBUG_EXE
   Exp curr = exp;
   do {
     CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d)))
-    if(env->func && isa(curr->type, t_function) > 0 && !GET_FLAG(curr->type->d.func, pure))
+    if(env->func && isa(curr->type, t_lambda) < 0 && isa(curr->type, t_function) > 0 && 
+        !GET_FLAG(curr->type->d.func, pure))
       UNSET_FLAG(env->func, pure);
   } while((curr = curr->next));
   return exp->type;
index 70c83eb5e0ac7d0b380d4954a072fa0407a289c7..94d2ed56fe27f7fbe0b440fb1a88e87d4ac3bac1 100644 (file)
@@ -602,6 +602,7 @@ funcmember:
     Except(shred, "StackOverflow");
   shred->mem = m;
   shred->pc = pc;
+  shred->code = code;
   if(GET_FLAG(a.code, ctor)) {
     register const f_xtor f = (f_xtor)a.code->native_func;
     f(*(M_Object*)m, NULL, shred);// callnat
@@ -633,7 +634,7 @@ funcstatic:
   register const f_sfun f = (f_sfun)a.code->native_func;
   f(reg, shred);
 funcend:
-  reg += instr->m_val;
+  shred->reg = reg += instr->m_val;
 funcend2:
   shred->mem = mem;
   if(!s->curr)break;
@@ -650,7 +651,7 @@ sporkfunc:
   a.child->reg += instr->m_val;
   DISPATCH()
 sporkthis:
-  *(M_Object*)a.child->reg = *(M_Object*)(reg + instr->m_val);
+  *(M_Object*)a.child->reg = *(M_Object*)(reg -SZ_INT + instr->m_val);
   a.child->reg += SZ_INT;
   DISPATCH()
 sporkexp:
index 6b9216977cf98ebb3aa9f417331ebaa6f2d86665..813b1d7ec58fa5b6ad955af0e429bc7949c82f81 100644 (file)
@@ -1,2 +1,2 @@
 // [contains] argument number does not match for lambda
-`a b`{ <<<a, " ", b>>>; }(1);
+\a b { <<<a, " ", b>>>; }(1);
index 98c67f5d418945d7be031cfa8f0a61efa8e0436d..8ea82eedfef4d2610ba8ad0f79f526522c34c40c 100644 (file)
@@ -1,4 +1,4 @@
 // [contains] argument number does not match for lambda
 typedef void ptr_t(int i);
-`a b`{ <<<a, " ", b>>>; } @=> ptr_t ptr;
+\a b { <<<a, " ", b>>>; } @=> ptr_t ptr;
 ptr(2);
index 74b760184ac8691ec50c2db5f04cd5c4996d0ec3..91c918697bbd4ec3ee275865f3f4e5774dd1109c 100644 (file)
@@ -1,6 +1,6 @@
 // [contains] argument number does not match for lambda
 typedef void ptr_t(int i);
-`a b`{ <<<a, " ", b>>>; } @=> ptr_t ptr;
+\a b { <<<a, " ", b>>>; } @=> ptr_t ptr;
 fun void test(ptr_t ptr) {
   ptr(2);
 }
index 08427245f0aa8e5d188510ff224b62165d705540..86b744e5b6b20affa99d55545b70c4f6159fb114 100644 (file)
@@ -1,6 +1,6 @@
 class C {
   typedef void ptr_t(int i,int j);
-  `a b` { <<<this, " ", a, " ", b, " test">>>; } @=> ptr_t ptr;
+  \a b { <<<this, " ", a, " ", b, " test">>>; } @=> ptr_t ptr;
 //  `a,b` { <<<"test">>>; } @=> 
 //  ptr_t ptr;
 //  ptr(1,2);
index 4f82711907fb4784cbd252bfbf0a4e2ed42d7b5e..f45c8fc6570171566ef19bb54bff0c13eb4cf9c3 100644 (file)
@@ -1,6 +1,6 @@
 class C {
 typedef void ptr_t(int i);
-`a` { <<<this, " ", a>>>; } @=> 
+\a { <<<this, " ", a>>>; } @=> 
 ptr_t ptr;
 //ptr(3);
 fun void t1(int i) { <<<this, " t1 ", i>>>; }
index f94978428586e98a904ee1fc430b042520dbdb98..990d0f9b3978ef5ad998ae07d3459ec95535233e 100644 (file)
@@ -1,2 +1,2 @@
 12 => int i;
-`a b` { <<<"i: ", i, " ", a, " ", b>>>; }(1,2);
+\a b { <<<"i: ", i, " ", a, " ", b>>>; }(1,2);
diff --git a/util b/util
index fa9f700bb617e6368150c9a29ffac4c6d5256d2d..55e2a6ba6d382f8dcb27661773df82de5fe9c470 160000 (submodule)
--- a/util
+++ b/util
@@ -1 +1 @@
-Subproject commit fa9f700bb617e6368150c9a29ffac4c6d5256d2d
+Subproject commit 55e2a6ba6d382f8dcb27661773df82de5fe9c470