]> Nishi Git Mirror - gwion.git/commitdiff
:art: Improve calls checking
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 23 Dec 2018 22:14:09 +0000 (23:14 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 23 Dec 2018 22:14:09 +0000 (23:14 +0100)
include/env.h
src/lib/func.c
src/parse/check.c

index 9994ebf9c94fb48f5f18b1c4c43d3cbab321255c..6298292853724c33b55cd2c9f1dedb34ac6a7848 100644 (file)
@@ -45,7 +45,7 @@ ANN Type scan_type(const Env, const Type, const Type_Decl*);
 ANN Type type_decl_resolve(const Env, const Type_Decl*);
 ANEW ANN m_str tl2str(const Env, const Type_List); // in type_decl.c
 ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def);
-ANN Type known_type(const Env env, const Type_Decl*, const m_str);
+ANN Type known_type(const Env env, const Type_Decl*);
 ANN m_bool env_access(const Env env, const ae_flag flag);
 ANN void env_storage(const Env env, ae_flag* flag);
 ANN2(1,2) void env_add_value(const Env, const m_str, const Type,       const m_bool, void*);
index e76315d8c651865af4072082162de60301c22668..61975a7384a63a4b7a38f949bca8163bb2155ab2 100644 (file)
@@ -14,7 +14,7 @@
 #include "nspc.h"
 #include "operator.h"
 
-ANN Type check_exp_call1(const Env, const Exp restrict,const Exp, const Exp);
+ANN Type check_exp_call1(const Env env, const Exp_Call *exp);
 ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary*);
 
 static INSTR(assign_func) { GWDEBUG_EXE
@@ -25,7 +25,8 @@ static INSTR(assign_func) { GWDEBUG_EXE
 
 static OP_CHECK(opck_func_call) {
   Exp_Binary* bin = (Exp_Binary*)data;
-  return check_exp_call1(env, bin->rhs, bin->lhs, bin->self);
+  Exp_Call call = { .func=bin->rhs, .args=bin->lhs, .self=bin->self };
+  return check_exp_call1(env, &call);
 }
 
 ANN static Type fptr_type(Exp_Binary* bin) {
index aac886e395a25dbb176f777775f930fc14da10a6..f46e93b2c46d61a8bc561e1b0fdc2d1bbd3fbe10 100644 (file)
@@ -478,8 +478,10 @@ ANN static Func get_template_func(const Env env, const Exp_Call* func, const Exp
         "\tplease provide template types. eg: '<type1, type2, ...>'")
 }
 
-ANN2(1,2,4) static Type check_exp_call_template(const Env env, const Exp restrict call,
-    const restrict Exp args, const restrict Exp base) {
+ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) {
+  const Exp call = exp->func;
+  const Exp args = exp->args;
+  const Exp base = exp->self;
   m_uint args_number = 0;
   const Value value = nspc_lookup_value1(call->type->owner, insert_symbol(call->type->name));
   CHECK_OO(value)
@@ -524,24 +526,23 @@ ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) {
   return GW_OK;
 }
 
-ANN2(1,2) Type check_exp_call1(const Env env, const restrict Exp call,
-    const restrict Exp args, restrict Exp base) { GWDEBUG_EXE
-  CHECK_BO(check_exp_call1_check(env, call))
-  if(GET_FLAG(call->type->d.func, ref)) {
-    const Value value = call->type->d.func->value_ref;
+ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {
+  CHECK_BO(check_exp_call1_check(env, exp->func))
+  if(GET_FLAG(exp->func->type->d.func, ref)) {
+    const Value value = exp->func->type->d.func->value_ref;
     CHECK_BO(traverse_template(env, value->owner_class->def))
   }
-  if(args)
-    CHECK_OO(check_exp(env, args))
-  if(GET_FLAG(call->type, func))
-    return check_exp_call_template(env, call, args, base);
-  const Func func = find_func_match(env, call->type->d.func, args);
+  if(exp->args)
+    CHECK_OO(check_exp(env, exp->args))
+  if(GET_FLAG(exp->func->type, func))
+    return check_exp_call_template(env, exp);
+  const Func func = find_func_match(env, exp->func->type->d.func, exp->args);
   if(!func)
-    return function_alternative(call->type, args);
-  if(base->exp_type == ae_exp_call)
-    base->d.exp_call.m_func = func;
-  else // if(base->exp_type == ae_exp_binary)
-    base->d.exp_binary.func = func;
+    return function_alternative(exp->func->type, exp->args);
+  if(exp->self->exp_type == ae_exp_call)
+    exp->self->d.exp_call.m_func = func;
+  else // if(exp->self->exp_type == ae_exp_binary)
+    exp->self->d.exp_binary.func = func;
   return func->def->ret_type;
 }
 
@@ -602,7 +603,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { GWDEBUG_EXE
     CHECK_OO((exp->m_func = ret))
     return ret->def->ret_type;
   }
-  return check_exp_call1(env, exp->func, exp->args, exp->self);
+  return check_exp_call1(env, exp);
 }
 
 ANN static inline m_bool check_exp_unary_spork1(const Env env, const Stmt code) {