]> Nishi Git Mirror - gwion.git/commitdiff
:art: Lambda unique name
authorfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 25 Feb 2019 15:11:27 +0000 (16:11 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 25 Feb 2019 15:11:27 +0000 (16:11 +0100)
src/lib/func.c
src/lib/gack.c
src/parse/check.c

index 5b89b2f9f9adf8de497b06afdd27ce1bbd8fc8cb..24cc059c934b88535a60306d54ba437a04dfa4a1 100644 (file)
@@ -65,21 +65,20 @@ ANN static Type fptr_type(Exp_Binary* bin) {
 }
 
 ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner,
-    Exp_Lambda *lambda, const Func_Def def) {
-  const m_uint scope = ((lambda->owner = owner)) ?
+    Exp_Lambda *l, const Func_Def def) {
+  const m_uint scope = ((l->owner = owner)) ?
     env_push_type(env, owner) : env->scope;
-  Arg_List base = def->arg_list, arg = lambda->arg;
+  Arg_List base = def->arg_list, arg = l->arg;
   while(base && arg) {
     arg->td = base->td;
     base = base->next;
     arg = arg->next;
   }
   if(base || arg)
-    ERR_B(lambda->self->pos, "argument number does not match for lambda")
-  lambda->def = new_func_def(def->td, insert_symbol("lambda"),
-    lambda->arg, lambda->code, def->flag);
-  const m_bool ret = traverse_func_def(env, lambda->def);
-  arg=lambda->arg;
+    ERR_B(l->self->pos, "argument number does not match for lambda")
+  l->def = new_func_def(def->td, l->name, l->arg, l->code, def->flag);
+  const m_bool ret = traverse_func_def(env, l->def);
+  arg = l->arg;
   while(arg) {
     arg->td = NULL;
     arg = arg->next;
@@ -93,16 +92,10 @@ static OP_CHECK(opck_fptr_at) {
   Exp_Binary* bin = (Exp_Binary*)data;
   bin->rhs->emit_var = 1;
   if(isa(bin->lhs->type, t_lambda) > 0) {
-    Exp_Lambda *lambda = &bin->lhs->d.exp_lambda;
-/*
-    lambda->def = new_func_def(bin->rhs->type->d.func->def->td,
-      insert_symbol("lambda"), bin->rhs->type->d.func->def->arg_list,
-      lambda->code, bin->rhs->type->d.func->def->flag);
-    CHECK_BO(traverse_func_def(env, lambda->def))
-*/
+    Exp_Lambda *l = &bin->lhs->d.exp_lambda;
     const Type owner = nspc_lookup_type1(bin->rhs->type->owner->parent,
        insert_symbol(bin->rhs->type->owner->name));
-    CHECK_BO(check_lambda(env, owner, lambda, bin->rhs->type->d.func->def))
+    CHECK_BO(check_lambda(env, owner, l, bin->rhs->type->d.func->def))
     return bin->rhs->type;
   }
   const Func l_func = bin->lhs->type->d.func;
index c2e2185a9dc9d2f70209e995f786211cafebbd99..f79fed52fc74d28be5cc30b4e62f85632df98b32 100644 (file)
@@ -72,9 +72,13 @@ ANN2(1) static inline void print_object(const Type type, const M_Object obj) {
 }
 
 ANN static inline void print_func(const Type type, const m_bit* stack) {
-  const VM_Code code = isa(type, t_fptr) > 0 ?
-    *(VM_Code*)stack : type->d.func->code;
-  gw_out("%s %p", type->name, (void*)code);
+  if(type->d.func) {
+    const VM_Code code = isa(type, t_fptr) > 0 ?
+      *(VM_Code*)stack : type->d.func->code;
+    gw_out("%s %p", type->name, (void*)code ? code->name : NULL);
+  } else {
+    gw_out("%s %p", type->name, NULL);
+  }
 }
 
 ANN static void print_prim(const Type type, const m_bit* stack) {
index 4b008075167f954277e3d8cdb0a124e6092b32dd..250d878c3d2dffc02941bf4bcace2291a1066bae 100644 (file)
@@ -575,8 +575,8 @@ ANN static inline void set_call(const Exp e, const Func f) {
 ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
   if(exp->args)
     CHECK_OO(check_exp(env, exp->args))
-  Exp_Lambda *lambda = &exp->func->d.exp_lambda;
-  Arg_List arg = lambda->arg;
+  Exp_Lambda *l = &exp->func->d.exp_lambda;
+  Arg_List arg = l->arg;
   Exp e = exp->args;
   while(arg && e) {
     arg->type = e->type;
@@ -585,11 +585,10 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
   }
   if(arg || e)
     ERR_O(exp->self->pos, "argument number does not match for lambda")
-  lambda->def = new_func_def(NULL, insert_symbol("lambda"),
-    lambda->arg, lambda->code, 0);
-  CHECK_BO(traverse_func_def(env, lambda->def))
-  set_call(exp->self, lambda->def->func);
-  return lambda->def->ret_type ?: (lambda->def->ret_type = t_void);
+  l->def = new_func_def(NULL, l->name, l->arg, l->code, 0);
+  CHECK_BO(traverse_func_def(env, l->def))
+  set_call(exp->self, l->def->func);
+  return l->def->ret_type ?: (l->def->ret_type = t_void);
 }
 
 ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {