From b0f8d4e60c9d25a86913c92aec4e3b950ddf7207 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 24 Sep 2019 20:43:43 +0200 Subject: [PATCH] Revert ":art: Implicitly cast int to enum" This reverts commit 415b061f86b6f30d601fad8fc2d04a21c09ea287. --- include/type.h | 2 +- src/lib/prim.c | 25 +++++++++++-------------- src/oo/type.c | 4 ++-- src/parse/scan0.c | 4 ++-- tests/import/enum.c | 4 ++-- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/type.h b/include/type.h index e69aa500..e55834ac 100644 --- a/include/type.h +++ b/include/type.h @@ -24,7 +24,7 @@ struct Type_ { ae_flag flag; }; -extern Type t_void, t_int, t_enum, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4, +extern Type t_void, t_int, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4, t_null, t_object, t_shred, t_fork, t_event, t_ugen, t_string, t_ptr, t_array, t_gack, t_function, t_fptr, t_varloop, t_vararg, t_lambda, t_class, t_union, t_undefined, t_auto, t_tuple; diff --git a/src/lib/prim.c b/src/lib/prim.c index 5d8607e8..295e6809 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -58,11 +58,6 @@ static GWION_IMPORT(int_r) { return GW_OK; } -static OP_CHECK(opck_i2enum) { - struct Implicit* imp = (struct Implicit*)data; - return imp->e->cast_to = imp->t; -} - static GWION_IMPORT(int_unary) { GWI_BB(gwi_oper_ini(gwi, NULL, "int", "int")) GWI_BB(gwi_oper_add(gwi, opck_unary_meta)) @@ -79,16 +74,13 @@ static GWION_IMPORT(int_unary) { return GW_OK; } -static GWION_IMPORT(bool) { - GWI_OB((t_enum = gwi_mk_type(gwi, "@enum", SZ_INT, t_int))) - GWI_BB(gwi_add_type(gwi, t_enum)) - GWI_BB(gwi_oper_ini(gwi, "int", "@enum", NULL)) - GWI_BB(gwi_oper_add(gwi, opck_i2enum)) - GWI_BB(gwi_oper_end(gwi, "@implicit", NULL)) +static GWION_IMPORT(int_values) { GWI_BB(gwi_enum_ini(gwi, "bool")) GWI_BB(gwi_enum_add(gwi, "false", 0)) GWI_BB(gwi_enum_add(gwi, "true", 1)) t_bool = gwi_enum_end(gwi); +// GWI_BB(gwi_item_ini(gwi, "bool", "maybe")) +// GWI_BB(gwi_item_end(gwi, 0, NULL)) gwi_reserve(gwi, "maybe"); struct SpecialId_ spid = { .type=t_bool, .exec=RegPushMaybe, .is_const=1 }; gwi_specialid(gwi, "maybe", &spid); @@ -101,7 +93,8 @@ static GWION_IMPORT(int) { GWI_BB(import_int_op(gwi)) GWI_BB(import_int_logical(gwi)) GWI_BB(import_int_r(gwi)) - return import_int_unary(gwi); + GWI_BB(import_int_unary(gwi)) + return import_int_values(gwi); } static GWION_IMPORT(values) { @@ -140,7 +133,12 @@ static GWION_IMPORT(values) { gwi_specialid(gwi, "now", &spid); return GW_OK; } - +/* +static OP_CHECK(opck_chuck_now) { + Exp_Binary* bin = (Exp_Binary*)data; + ERR_N(exp_self(bin)->pos, _("can't assign 'now' to 'now'")) +} +*/ static OP_CHECK(opck_implicit_f2i) { return t_null; } @@ -294,6 +292,5 @@ GWION_IMPORT(prim) { GWI_BB(import_floatint(gwi)) GWI_BB(import_dur(gwi)) GWI_BB(import_time(gwi)) - GWI_BB(import_bool(gwi)) return import_values(gwi); } diff --git a/src/oo/type.c b/src/oo/type.c index 681e7441..418d0fb4 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -44,7 +44,7 @@ Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) type->name = name; type->e = mp_calloc(p, TypeInfo); type->e->parent = parent; - if(t_object && parent && isa(parent, t_object) > 0) { + if(type->e->parent) { type->size = parent->size; type->e->tuple = new_tupleform(p); } @@ -197,6 +197,6 @@ ANN m_uint get_depth(const Type type) { return depth; } -Type t_void, t_int, t_enum, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4, +Type t_void, t_int, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4, t_null, t_object, t_shred, t_fork, t_event, t_ugen, t_string, t_ptr, t_array, t_gack, t_function, t_fptr, t_varloop, t_vararg, t_lambda, t_class, t_union, t_undefined, t_auto, t_tuple; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index c6cd9d1e..6036a898 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -150,10 +150,10 @@ ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) { s_name(edef->xid), v->type->name) CHECK_BB(scan0_defined(env, edef->xid, edef->pos)) } - const Type t = type_copy(env->gwion->mp, t_enum); + const Type t = type_copy(env->gwion->mp, t_int); t->xid = ++env->scope->type_xid; t->name = edef->xid ? s_name(edef->xid) : "int"; - t->e->parent = t_enum; + t->e->parent = t_int; const Nspc nspc = GET_FLAG(edef, global) ? env->global_nspc : env->curr; t->e->owner = nspc; edef->t = t; diff --git a/tests/import/enum.c b/tests/import/enum.c index bdc84bbd..0804c25d 100644 --- a/tests/import/enum.c +++ b/tests/import/enum.c @@ -38,8 +38,8 @@ GWION_IMPORT(enum_test) { CHECK_OB(gwi_enum_end(gwi)) Type t_enum; - CHECK_OB((t_myenum = gwi_mk_type(gwi, "Enum", 0, NULL))) - CHECK_BB(gwi_class_ini(gwi, t_myenum, NULL, NULL)) + CHECK_OB((t_enum = gwi_mk_type(gwi, "Enum", 0, NULL))) + CHECK_BB(gwi_class_ini(gwi, t_enum, NULL, NULL)) CHECK_BB(gwi_enum_ini(gwi, 0)) CHECK_BB(gwi_enum_add(gwi, "ENUM0", 0)) CHECK_BB(gwi_enum_add(gwi, "ENUM1", 1)) -- 2.43.0