From: Jérémie Astor Date: Thu, 28 Nov 2019 01:14:55 +0000 (+0100) Subject: :art: Few AFL fixes X-Git-Tag: nightly~2073 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=65cbd9bda788998d760aabfca83d975c70e60458;p=gwion.git :art: Few AFL fixes --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 83c5a9ee..7767359c 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -687,8 +687,8 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Exp_Decl *d } } const Instr instr = emit_kind(emit, v->type->size, emit_addr, exec); - instr->m_val = v->from->offset; - instr->m_val2 = v->type->size; + if(emit_addr || !GET_FLAG(v, member)) + instr->m_val = v->from->offset; if(is_obj && (is_array || !is_ref)) { emit_add_instr(emit, Assign); const size_t missing_depth = type->array_depth - (array ? array->depth : 0); diff --git a/src/lib/array.c b/src/lib/array.c index 637481de..f0188be3 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -214,6 +214,8 @@ static INSTR(ArraySlice) { static OP_EMIT(opem_array_slice) { const Exp exp = (Exp)data; Exp_Slice *range = &exp->d.exp_slice; + if(!GET_FLAG(exp->type, nonnull)) + emit_add_instr(emit, GWOP_EXCEPT); emit_add_instr(emit, ArraySlice); const Instr instr = emit_add_instr(emit, ArrayInit); instr->m_val = (m_uint)range->base->type; diff --git a/src/lib/complex.c b/src/lib/complex.c index 31ca8305..64079ce2 100644 --- a/src/lib/complex.c +++ b/src/lib/complex.c @@ -114,11 +114,11 @@ polar_def2_r(Mul, *, +) polar_def2_r(Div, /, -) static GACK(gack_complex) { - printf("#(%.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT)); + gw_out("#(%.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT)); } static GACK(gack_polar) { - printf("%%(%.4f, %.4f*pi)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT) / M_PI); + gw_out("%%(%.4f, %.4f*pi)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT) / M_PI); } EQUALITY_OPER(complex, SZ_COMPLEX) diff --git a/src/lib/engine.c b/src/lib/engine.c index 5a8b0307..da27da59 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -17,35 +17,35 @@ #include "specialid.h" static GACK(gack_class) { - printf("class(%s)", actual_type(shred->info->vm->gwion, t)->name); + gw_out("class(%s)", actual_type(shred->info->vm->gwion, t)->name); } static GACK(gack_function) { - printf("%s", t->name); + gw_out("%s", t->name); } static GACK(gack_fptr) { const VM_Code code = *(VM_Code*)VALUE; if(code) - printf("%s", code->name); + gw_out("%s", code->name); else - printf("%s", t->name); + gw_out("%s", t->name); } static GACK(gack_void) { - printf("(void)"); + gw_out("(void)"); } static GACK(gack_int) { - printf("%"INT_F, *(m_uint*)VALUE); + gw_out("%"INT_F, *(m_uint*)VALUE); } static GACK(gack_char) { - printf("%c", *(char*)VALUE); + gw_out("%c", *(char*)VALUE); } static GACK(gack_float) { - printf("%.4f", *(m_float*)VALUE); + gw_out("%.4f", *(m_float*)VALUE); } #define mk_class_instr(op, arg0, arg1, ...) \ diff --git a/src/lib/func.c b/src/lib/func.c index e424626b..cdeb24b2 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -154,9 +154,6 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def def ERR_B(exp_self(l)->pos, _("argument number does not match for lambda")) l->def->flag = def->flag; l->def->base->td = cpy_type_decl(env->gwion->mp, def->base->td); -// l->def = new_func_def(env->gwion->mp, -// new_func_base(env->gwion->mp, def->base->td, l->name, l->args), -// l->code, def->flag, loc_cpy(env->gwion->mp, def->pos)); CHECK_BB(traverse_func_def(env, l->def)) arg = l->def->base->args; while(arg) { diff --git a/src/lib/object.c b/src/lib/object.c index d5d0b5ff..5078fc39 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -221,7 +221,7 @@ static ID_CHECK(check_this) { } static GACK(gack_object) { - printf("%p", *(M_Object*)VALUE); + gw_out("%p", *(M_Object*)VALUE); } GWION_IMPORT(object) { diff --git a/src/lib/prim.c b/src/lib/prim.c index 5385ce33..e1e715f7 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -61,10 +61,12 @@ static GWION_IMPORT(int_r) { static INSTR(IntRange) { shred->reg -= SZ_INT *2; - const m_int start = *(m_uint*)REG(0); - const m_int end = *(m_uint*)REG(SZ_INT); + const m_int start = *(m_int*)REG(0); + const m_int end = *(m_int*)REG(SZ_INT); const m_int op = start < end ? 1 : -1; const m_uint sz = op > 0 ? end - start : start - end; + if((sz - (shred->reg - (m_bit*)(shred + sizeof(struct VM_Shred_)))) > SIZEOF_REG) + Except(shred, _("Range too big")) for(m_int i = start, j = 0; i != end; i += op, ++j) *(m_uint*)REG(j * SZ_INT) = i; *(m_uint*)REG(sz * SZ_INT) = sz; @@ -95,7 +97,7 @@ static GWION_IMPORT(int_unary) { return GW_OK; } static GACK(gack_bool) { - printf("%s", *(m_uint*)VALUE ? "true" : "false"); + gw_out("%s", *(m_uint*)VALUE ? "true" : "false"); } static GWION_IMPORT(int_values) { diff --git a/src/lib/string.c b/src/lib/string.c index 99d86483..654abb75 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -180,7 +180,7 @@ ID_CHECK(check_funcpp) { static GACK(gack_string) { const M_Object obj = *(M_Object*)VALUE; - printf("%s", obj ? STRING(obj) : "(null string)"); + gw_out("%s", obj ? STRING(obj) : "(null string)"); } static inline m_bool bounds(const m_str str, const m_int i) { diff --git a/src/lib/vec.c b/src/lib/vec.c index 3cc2e837..56ac9419 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -157,7 +157,7 @@ static void vecx_base(const Gwi gwi) { } static GACK(gack_vec3) { - printf("%%(%.4f, %.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT), *(m_float*)(VALUE + SZ_FLOAT*2)); + gw_out("%%(%.4f, %.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT), *(m_float*)(VALUE + SZ_FLOAT*2)); } EQUALITY_OPER(vec3, SZ_VEC3); @@ -306,7 +306,7 @@ static INSTR(Vec4RAssign) { } static GACK(gack_vec4) { - printf("%%(%.4f, %.4f, %.4f, %.4f)", + gw_out("%%(%.4f, %.4f, %.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT), *(m_float*)(VALUE + SZ_FLOAT*2), diff --git a/src/parse/check.c b/src/parse/check.c index cca3e03f..943cce1d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -538,7 +538,7 @@ ANN static m_bool check_func_args(const Env env, Arg_List arg_list) { const Var_Decl decl = arg_list->var_decl; const Value v = decl->value; if(arg_list->td && !arg_list->td->xid) - arg_list->type = v->type = check_td(env, arg_list->td); + CHECK_OB((arg_list->type = v->type = check_td(env, arg_list->td))) if(isa(v->type, env->gwion->type[et_object]) > 0 || isa(v->type, env->gwion->type[et_function]) > 0) UNSET_FLAG(env->func, pure); CHECK_BB(already_defined(env, decl->xid, decl->pos)) @@ -1366,7 +1366,7 @@ ANN m_bool check_func_def(const Env env, const Func_Def fdef) { if(tmpl_base(fdef->base->tmpl)) return GW_OK; if(fdef->base->td && !fdef->base->td->xid) { // tmpl ? - fdef->base->ret_type = check_td(env, fdef->base->td); + CHECK_OB((fdef->base->ret_type = check_td(env, fdef->base->td))) return traverse_func_def(env, fdef); } CHECK_BB(check_func_def_override(env, fdef)) @@ -1379,7 +1379,8 @@ ANN m_bool check_func_def(const Env env, const Func_Def fdef) { nspc_pop_value(env->gwion->mp, env->curr); --env->scope->depth; env->func = former; - SET_FLAG(fdef, checked); + if(ret > 0) + SET_FLAG(fdef, checked); if(GET_FLAG(fdef, global)) env_pop(env,scope); return ret;