]> Nishi Git Mirror - gwion.git/commitdiff
:art: Use cast_to for dur expressions
authorfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 13 Dec 2018 01:03:53 +0000 (02:03 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 13 Dec 2018 01:03:53 +0000 (02:03 +0100)
src/emit/emit.c
src/parse/check.c

index 57f27358d425a9bb226a3aa97139487bb7eb0f76..a5adc9947618b5b93d6f618f27b9af33bbb767a3 100644 (file)
@@ -579,14 +579,13 @@ ANN static m_bool emit_func_arg_vararg(const Emitter emit, const Exp_Call* exp_c
 }
 
 ANN static m_bool emit_func_args(const Emitter emit, const Exp_Call* exp_call) { GWDEBUG_EXE
-  if(exp_call->args)
-    CHECK_BB(emit_exp(emit, exp_call->args, 1))
+  CHECK_BB(emit_exp(emit, exp_call->args, 1))
   if(GET_FLAG(exp_call->m_func->def, variadic))
     CHECK_BB(emit_func_arg_vararg(emit, exp_call))
   return GW_OK;
 }
 
-ANN static m_bool emit_exp_call_helper(const Emitter emit, const Exp_Call* exp_call) { GWDEBUG_EXE
+ANN static m_bool prepare_call(const Emitter emit, const Exp_Call* exp_call) { GWDEBUG_EXE
   if(exp_call->args)
     CHECK_BB(emit_func_args(emit, exp_call))
   CHECK_BB(emit_exp(emit, exp_call->func, 0))
@@ -610,10 +609,10 @@ ANN static inline m_int push_tmpl_func(const Emitter emit, const Func f,
 
 ANN static m_bool emit_exp_call_template(const Emitter emit, const Exp_Call* exp_call) {
   if(emit->env->func && emit->env->func == exp_call->m_func)
-    return emit_exp_call_helper(emit, exp_call);
+    return prepare_call(emit, exp_call);
   m_int scope = push_tmpl_func(emit, exp_call->m_func, exp_call->tmpl->types);
   CHECK_BB(scope);
-  CHECK_BB(emit_exp_call_helper(emit, exp_call))
+  CHECK_BB(prepare_call(emit, exp_call))
   emit_pop_type(emit);
   emit_pop(emit, (m_uint)scope);
   UNSET_FLAG(exp_call->m_func, checked);
@@ -622,7 +621,7 @@ ANN static m_bool emit_exp_call_template(const Emitter emit, const Exp_Call* exp
 
 ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { GWDEBUG_EXE
   if(!exp_call->tmpl)
-    CHECK_BB(emit_exp_call_helper(emit, exp_call))
+    CHECK_BB(prepare_call(emit, exp_call))
   else
     CHECK_BB(emit_exp_call_template(emit, exp_call))
   return emit_exp_call1(emit, exp_call->m_func);
@@ -659,8 +658,6 @@ ANN static m_bool emit_exp_post(const Emitter emit, const Exp_Postfix* post) { G
 
 ANN static m_bool emit_exp_dur(const Emitter emit, const Exp_Dur* dur) { GWDEBUG_EXE
   CHECK_BB(emit_exp(emit, dur->base, 0))
-  if(isa(dur->base->type, t_int) > 0)
-    emit_add_instr(emit, CastI2F);
   CHECK_BB(emit_exp(emit, dur->unit, 0))
   emit_add_instr(emit, FloatTimes);
   return GW_OK;
index 2b64f399c891321d6ec40ae1154d594b5e06da89..2964118a5a7b4639684e60afc245c91f3ad7a9a6 100644 (file)
@@ -582,10 +582,14 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix* post) { GWDEBUG
 
 ANN static Type check_exp_dur(const Env env, const Exp_Dur* exp) { GWDEBUG_EXE
   CHECK_OO(check_exp(env, exp->base))
-  CHECK_OO(check_exp(env, exp->unit))
-  if(isa(exp->base->type, t_int) < 0 && isa(exp->base->type, t_float) < 0)
-    ERR_O(exp->base->pos, "invalid type '%s' in prefix of dur expression...\n"
+  if(isa(exp->base->type, t_float) < 0) {
+    if(isa(exp->base->type, t_int) > 0)
+      exp->base->cast_to = t_float;
+    else
+      ERR_O(exp->base->pos, "invalid type '%s' in prefix of dur expression...\n"
           "    (must be of type 'int' or 'float')", exp->base->type->name)
+  }
+  CHECK_OO(check_exp(env, exp->unit))
   if(isa(exp->unit->type, t_dur) < 0)
     ERR_O(exp->unit->pos, "invalid type '%s' in postfix of dur expression...\n"
           "    (must be of type 'dur')", exp->base->type->name)