From: fennecdjay Date: Wed, 25 Sep 2019 00:10:43 +0000 (+0200) Subject: :art: Full embedability X-Git-Tag: nightly~2199^2~18 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7aa1c3828a6776659609bf4627874cc7de616d7b;p=gwion.git :art: Full embedability --- diff --git a/include/object.h b/include/object.h index 8b4a44aa..da09c027 100644 --- a/include/object.h +++ b/include/object.h @@ -11,10 +11,10 @@ struct M_Object_ { ANN void instantiate_object(const VM_Shred, const Type); ANN void free_object(MemPool p, const M_Object); ANEW M_Object new_object(MemPool, const VM_Shred, const Type); -ANEW M_Object new_M_UGen(MemPool); +ANEW M_Object new_M_UGen(const struct Gwion_*); ANN ANEW M_Object new_array(MemPool, const Type t, const m_uint length); ANEW M_Object new_string(MemPool, const VM_Shred, const m_str); -ANEW M_Object new_string2(MemPool, const VM_Shred, const m_str); +ANEW M_Object new_string2(const struct Gwion_*, const VM_Shred, const m_str); ANEW M_Object gwion_new_string(const struct Gwion_*, const m_str); ANEW M_Object new_shred(const VM_Shred, const m_bool); ANN void fork_launch(const VM*, const M_Object, const m_uint); diff --git a/include/operator.h b/include/operator.h index 9df6637f..f401301d 100644 --- a/include/operator.h +++ b/include/operator.h @@ -2,7 +2,7 @@ #define __OPERATOR #define OP_ANY_TYPE (Type)1 -#define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return t_null; } +#define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return env->gwion->type[et_null]; } typedef Type (*opck)(const Env, void*, m_bool*); typedef struct Instr_* (*opem)(const Emitter, void*); diff --git a/include/type.h b/include/type.h index 9e6c17b9..eb989a43 100644 --- a/include/type.h +++ b/include/type.h @@ -24,10 +24,6 @@ struct Type_ { ae_flag flag; }; -extern Type - 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; - ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type); ANEW ANN Type type_copy(MemPool, const Type type); ANN m_str get_type_name(const Env, const m_str, const m_uint); @@ -44,18 +40,14 @@ ANN Type array_base(Type) __attribute__((pure)); ANN m_bool type_ref(Type) __attribute__((pure)); __attribute__((returns_nonnull)) ANN Type template_parent(const Env, const Type type); -static inline Type actual_type(const Type t) { - return isa(t, t_class) > 0 ? t->e->d.base_type : t; -} +ANN Type actual_type(const struct Gwion_* gwion, const Type t); ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); } -ANN static inline m_bool is_fptr(const Type t) { - return isa(actual_type(t), t_fptr) > 0; -} +ANN m_bool is_fptr(const struct Gwion_*, const Type t); ANN m_uint get_depth(const Type type); typedef enum { et_void, et_int, et_bool, et_float, et_complex, et_polar, et_vec3, et_vec4, - et_null, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, zt_gack, + et_null, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, et_gack, et_function, et_fptr, et_varloop, et_vararg, et_lambda, et_class, et_union, et_undefined, et_auto, et_tuple, MAX_TYPE } type_enum; diff --git a/include/ugen.h b/include/ugen.h index 6c278b55..b38dc8eb 100644 --- a/include/ugen.h +++ b/include/ugen.h @@ -41,8 +41,8 @@ struct UGen_ { #define TICK(a) __attribute__((hot)) ANN inline void a(const UGen u) -ANN void ugen_ini(MemPool p, const UGen, const uint, const uint); -ANN void ugen_gen(MemPool p, const UGen, const f_tick, void*, const m_bool); +ANN void ugen_ini(const struct Gwion_*, const UGen, const uint, const uint); +ANN void ugen_gen(const struct Gwion_*, const UGen, const f_tick, void*, const m_bool); ANN void ugen_connect(const UGen lhs, const UGen rhs); ANN void ugen_disconnect(const UGen lhs, const UGen rhs); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index bc59a5ba..1f38acfa 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -200,7 +200,7 @@ ANN ArrayInfo* emit_array_extend_inner(const Emitter emit, const Type t, const E info->base = base; const Instr alloc = emit_add_instr(emit, ArrayAlloc); alloc->m_val = (m_uint)info; - if(isa(base, t_object) > 0 && !GET_FLAG(base, abstract)) { + if(isa(base, emit->gwion->type[et_object]) > 0 && !GET_FLAG(base, abstract)) { emit_pre_constructor_array(emit, base); info->is_obj = 1; } @@ -331,7 +331,7 @@ ANN static m_bool emit_symbol_builtin(const Emitter emit, const Exp_Primary* pri const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, regpushimm); if(!exp_self(prim)->emit_var && size == SZ_INT) { - if(isa(v->type, t_object) > 0) { + if(isa(v->type, emit->gwion->type[et_object]) > 0) { instr->opcode = eRegPushImm; instr->m_val = (m_uint)v->d.ptr; } else if(v->d.ptr) @@ -349,8 +349,8 @@ ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) { const Value v = prim->value; if(v->owner_class) return emit_symbol_owned(emit, prim); - if(isa(v->type, t_class) > 0) { - regpushi(emit, (m_uint)actual_type(v->type)); + if(isa(v->type, emit->gwion->type[et_class]) > 0) { + regpushi(emit, (m_uint)actual_type(emit->gwion, v->type)); return GW_OK; } if(GET_FLAG(v, builtin) || GET_FLAG(v, union) || GET_FLAG(v, enum)) @@ -358,7 +358,7 @@ ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) { const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase); instr->m_val = v->offset; - if(isa(v->type, t_function) > 0 && isa(v->type, t_fptr) < 0) + if(isa(v->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, v->type)) instr->m_val = exp_self(prim)->type->e->d.func->value_ref->offset; return GW_OK; } @@ -442,7 +442,7 @@ ANN void emit_except(const Emitter emit, const Type t) { } ANN static inline m_bool tuple_index(const Emitter emit, struct ArrayAccessInfo *const info) { - assert(isa(info->array.type, t_tuple) > 0); + assert(isa(info->array.type, emit->gwion->type[et_tuple]) > 0); const m_uint idx = info->array.exp->d.exp_primary.d.num; emit_except(emit, info->array.type); tuple_access(emit, info->array.exp->d.exp_primary.d.num, info->array.depth ? 0 : info->is_var); @@ -552,7 +552,7 @@ ANN static m_bool prim_str(const Emitter emit, const Exp_Primary* prim) { const Value v = prim->value; const Symbol sym = insert_symbol(c); if(!v->d.ptr) - v->d.ptr = (m_uint*)new_string2(emit->gwion->mp, NULL, s_name(sym)); + v->d.ptr = (m_uint*)new_string2(emit->gwion, NULL, s_name(sym)); regpushi(emit, (m_uint)v->d.ptr); emit_add_instr(emit, RegAddRef); return GW_OK; @@ -592,7 +592,7 @@ ANN static m_bool emit_exp_primary(const Emitter emit, const Exp_Primary* prim) ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const uint emit_var) { const m_uint size = v->type->size; - if(isa(v->type, t_class) < 0) { + if(isa(v->type, emit->gwion->type[et_class]) < 0) { const Instr instr = emit_kind(emit, size, emit_var, dotstatic); instr->m_val = (m_uint)(v->owner->info->class_data + v->offset); instr->m_val2 = size; @@ -616,7 +616,7 @@ ANN static m_bool decl_static(const Emitter emit, const Var_Decl var_decl, const ANN static m_bool emit_exp_decl_static(const Emitter emit, const Var_Decl var_decl, const uint is_ref, const uint emit_addr) { const Value value = var_decl->value; - if(isa(value->type, t_object) > 0 && !is_ref) + if(isa(value->type, emit->gwion->type[et_object]) > 0 && !is_ref) CHECK_BB(decl_static(emit, var_decl, 0)) return emit_dot_static_data(emit, value, emit_addr); } @@ -627,8 +627,8 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Var_Decl va const Type type = v->type; const Array_Sub array = var_decl->array; const m_bool is_array = array && array->exp; - const m_bool is_obj = isa(type, t_object) > 0; - const uint emit_addr = ((is_ref && !array) || isa(type, t_object) < 0) ? + const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; + const uint emit_addr = ((is_ref && !array) || isa(type, emit->gwion->type[et_object]) < 0) ? emit_var : 1; if(is_obj && (is_array || !is_ref)/* && !GET_FLAG(var_decl->value, ref)*/) CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) @@ -662,8 +662,8 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de const Type type = v->type; const Array_Sub array = var_decl->array; const m_bool is_array = array && array->exp; - const m_bool is_obj = isa(type, t_object) > 0; - const uint emit_addr = ((is_ref && !array) || isa(type, t_object) < 0) ? + const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; + const uint emit_addr = ((is_ref && !array) || isa(type, emit->gwion->type[et_object]) < 0) ? emit_var : 1; if(is_obj && (is_array || !is_ref)) CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) @@ -675,7 +675,8 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de if(is_obj && (is_array || !is_ref)) { const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; - if(isa(type, t_fork) < 0) { // beware fork +// TODO: (test type)watch me: am I needed ? + if(isa(type, emit->gwion->type[et_fork]) < 0) { // beware fork const Instr instr = emit_add_instr(emit, RegAddRef); instr->m_val = emit_var; } @@ -826,7 +827,7 @@ ANN static m_bool emit_exp_post(const Emitter emit, const Exp_Postfix* post) { ANN static m_bool is_special(const Emitter emit, const Type t) { if(isa(t, emit->gwion->type[et_complex]) > 0 || isa(t, emit->gwion->type[et_polar]) > 0 || isa(t, emit->gwion->type[et_vec3]) > 0 || isa(t, emit->gwion->type[et_vec4]) > 0 || - isa(t, t_vararg) > 0) + isa(t, emit->gwion->type[et_vararg]) > 0) return GW_OK; return GW_ERROR; } @@ -890,8 +891,8 @@ ANN static m_bool emit_template_code(const Emitter emit, const Func f) { ANN static Instr get_prelude(const Emitter emit, const Func f) { Instr instr; - const Type t = actual_type(f->value_ref->type); - if(isa(t, t_fptr) < 0) + const Type t = actual_type(emit->gwion, f->value_ref->type); + if(!is_fptr(emit->gwion, t)) instr = emit_add_instr(emit, !GET_FLAG(f, builtin) ? FuncUsr : SetCode); else { emit_except(emit, t); @@ -953,7 +954,7 @@ ANN static Instr emit_call(const Emitter emit, const Func f) { ANN Instr emit_exp_call1(const Emitter emit, const Func f) { if(!f->code || (GET_FLAG(f, ref) && !GET_FLAG(f, builtin))) { - if(GET_FLAG(f, template) && !is_fptr(f->value_ref->type)) { + if(GET_FLAG(f, template) && !is_fptr(emit->gwion, f->value_ref->type)) { if(emit->env->func != f) CHECK_BO(emit_template_code(emit, f)) else { @@ -961,13 +962,13 @@ ANN Instr emit_exp_call1(const Emitter emit, const Func f) { back->opcode = ePushStaticCode; back->m_val = 0; } - } else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(f->value_ref->type)) { + } else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) { const Instr back = !GET_FLAG(f->def, op) ? emit_add_instr(emit, PushStaticCode) : (Instr)vector_back(&emit->code->instr); back->m_val = (m_uint)f; } } else if((f->value_ref->owner_class && is_special(emit, f->value_ref->owner_class) > 0) || !f->value_ref->owner_class || (GET_FLAG(f, template) && - isa(f->value_ref->type, t_fptr) < 0)) + !is_fptr(emit->gwion, f->value_ref->type))) push_func_code(emit, f); else if(vector_size(&emit->code->instr)) { const Instr back = (Instr)vector_back(&emit->code->instr); @@ -975,7 +976,7 @@ ANN Instr emit_exp_call1(const Emitter emit, const Func f) { back->m_val = f->vt_index; } if(vector_size(&emit->code->instr) && GET_FLAG(f, member) && - is_fptr(f->value_ref->type)) { + is_fptr(emit->gwion, f->value_ref->type)) { const Instr back = (Instr)vector_back(&emit->code->instr); m_bit exec = back->opcode; m_uint val = back->m_val; @@ -1069,7 +1070,7 @@ ANN Instr emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); spork->m_val = emit->code->stack_depth; } else { - if(GET_FLAG(f, member) && is_fptr(f->value_ref->type)) { + if(GET_FLAG(f, member) && is_fptr(emit->gwion, f->value_ref->type)) { const m_uint depth = f->def->stack_depth; regpop(emit, depth -SZ_INT); const Instr spork = emit_add_instr(emit, SporkMemberFptr); @@ -1135,7 +1136,7 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda) } ANN static m_bool emit_exp_typeof(const Emitter emit, const Exp_Typeof *exp) { - regpushi(emit, (m_uint)actual_type(exp->exp->type)); + regpushi(emit, (m_uint)actual_type(emit->gwion, exp->exp->type)); return GW_OK; } @@ -1144,13 +1145,14 @@ DECL_EXP_FUNC(emit) ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { do { CHECK_BB(exp_func[exp->exp_type](emit, &exp->d)) - if(ref && isa(exp->type, t_object) > 0 && isa(exp->type, t_shred) < 0 ) { // beware fork + if(ref && isa(exp->type, emit->gwion->type[et_object]) > 0 && isa(exp->type, emit->gwion->type[et_shred]) < 0 ) { // beware fork const Instr instr = emit_add_instr(emit, RegAddRef); instr->m_val = exp->emit_var; } if(exp->cast_to) CHECK_BB(emit_implicit_cast(emit, exp, exp->cast_to)) - if(emit->env->func && isa(exp->type, t_lambda) < 0 && isa(exp->type, t_function) > 0 && + if(emit->env->func && isa(exp->type, emit->gwion->type[et_lambda]) < 0 && + isa(exp->type, emit->gwion->type[et_function]) > 0 && !GET_FLAG(exp->type->e->d.func->value_ref->d.func_ref, pure)) UNSET_FLAG(emit->env->func, pure); } while((exp = exp->next)); @@ -1192,7 +1194,7 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func) return optimize_taill_call(emit, &stmt->val->d.exp_call); CHECK_BB(emit_exp_pop_next(emit, stmt->val, 0)) - if(isa(stmt->val->type, t_object) > 0 && isa(stmt->val->type , t_shred) < 0) // beware shred + if(isa(stmt->val->type, emit->gwion->type[et_object]) > 0 && isa(stmt->val->type , emit->gwion->type[et_shred]) < 0) // beware shred emit_add_instr(emit, RegAddRef); } vector_add(&emit->code->stack_return, (vtype)emit_add_instr(emit, Goto)); @@ -1446,7 +1448,7 @@ ANN static m_bool emit_case_body(const Emitter emit, const struct Stmt_Match_* s ANN static m_bool case_value(const Emitter emit, const Exp base, const Exp e) { const Value v = e->d.exp_primary.value; - v->offset = emit_local(emit, base->type->size, isa(base->type, t_object) > 0); + v->offset = emit_local(emit, base->type->size, isa(base->type, emit->gwion->type[et_object]) > 0); CHECK_BB(emit_exp(emit, base, 1)) regpop(emit, base->type->size); const Instr instr = emit_add_instr(emit, Reg2Mem4); @@ -1553,7 +1555,7 @@ ANN static m_bool emit_dot_static_import_data(const Emitter emit, const Value v, else { const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, emit_addr, regpushimm); - instr->m_val = (isa(v->type, t_object) > 0 ? + instr->m_val = (isa(v->type, emit->gwion->type[et_object]) > 0 ? (m_uint)&v->d.ptr : (m_uint)v->d.ptr); instr->m_val2 = size; } @@ -1652,7 +1654,7 @@ ANN static m_bool emit_exp_dot_special(const Emitter emit, const Exp_Dot* member ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) { const Func f = exp_self(member)->type->e->d.func; - if(isa(member->t_base, t_class) > 0 || GET_FLAG(member->base->type, force)) { + if(isa(member->t_base, emit->gwion->type[et_class]) > 0 || GET_FLAG(member->base->type, force)) { const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode); if(f->code) func_i->m_val = (m_uint)(f->code ?: (VM_Code)f); @@ -1682,15 +1684,15 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member) { } if(is_special(emit, member->t_base) > 0) return emit_exp_dot_special(emit, member); - const Value value = find_value(actual_type(member->t_base), member->xid); - if(isa(member->t_base, t_class) < 0 && (GET_FLAG(value, member) || -(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0)) + const Value value = find_value(actual_type(emit->gwion, member->t_base), member->xid); + if(isa(member->t_base, emit->gwion->type[et_class]) < 0 && (GET_FLAG(value, member) || +(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type))) ) { CHECK_BB(emit_exp(emit, member->base, 0)) // emit_except(emit, member->t_base); emit_add_instr(emit, GWOP_EXCEPT); } - if(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0) + if(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type)) return emit_member_func(emit, member); return (GET_FLAG(value, member) ? emit_member : emit_dot_static_import_data) (emit, value, exp_self(member)->emit_var); } @@ -1712,7 +1714,7 @@ ANN static void emit_func_def_args(const Emitter emit, Arg_List a) { do { const Value value = a->var_decl->value; const m_uint size = value->type->size; - const m_bool obj = isa(value->type, t_object) > 0; + const m_bool obj = isa(value->type, emit->gwion->type[et_object]) > 0; emit->code->stack_depth += size; value->offset = emit_local(emit, size, obj); } while((a = a->next)); diff --git a/src/lib/array.c b/src/lib/array.c index 0ecec885..32b401ef 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -15,6 +15,7 @@ #include "import.h" #include "traverse.h" #include "parse.h" +#include "gwi.h" struct M_Vector_ { m_bit* ptr; @@ -52,7 +53,7 @@ static DTOR(array_dtor) { o->type_ref : o->type_ref->e->parent; const Type base = array_base(t); struct M_Vector_* a = ARRAY(o); - if(t->array_depth > 1 || isa(base, t_object) > 0) + if(t->array_depth > 1 || isa(base, shred->info->vm->gwion->type[et_object]) > 0) for(m_uint i = 0; i < ARRAY_LEN(a); ++i) release(*(M_Object*)(ARRAY_PTR(a) + i * SZ_INT), shred); free_m_vector(shred->info->mp, a); @@ -101,7 +102,7 @@ static MFUN(vm_vector_rem) { const M_Vector v = ARRAY(o); if(index < 0 || (m_uint)index >= ARRAY_LEN(v)) return; - if(isa(o->type_ref, t_object) > 0) { + if(isa(o->type_ref, shred->info->vm->gwion->type[et_object]) > 0) { M_Object obj; m_vector_get(v, (vtype)index, &obj); release(obj,shred); @@ -140,8 +141,8 @@ ANN static Type get_array_type(Type t) { static OP_CHECK(opck_array_at) { ARRAY_OPCK - if(opck_const_rhs(env, data, mut) == t_null) - return t_null; + if(opck_const_rhs(env, data, mut) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; if(bin->lhs->type->array_depth != bin->rhs->type->array_depth) ERR_N(exp_self(bin)->pos, _("array depths do not match.")) if(bin->rhs->exp_type == ae_exp_decl) { @@ -181,7 +182,7 @@ static OP_CHECK(opck_array_cast) { r = r->e->parent; if(l->array_depth == r->array_depth || isa(l->e->d.base_type, r->e->d.base_type) > 0) return l; - return t_null; + return env->gwion->type[et_null]; } static FREEARG(freearg_array) { @@ -191,7 +192,8 @@ static FREEARG(freearg_array) { } GWION_IMPORT(array) { - t_array = gwi_mk_type(gwi, "@Array", SZ_INT, t_object); + const Type t_array = gwi_mk_type(gwi, "@Array", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_array] = t_array; GWI_BB(gwi_class_ini(gwi, t_array, NULL, array_dtor)) GWI_BB(gwi_item_ini(gwi, "int", "@array")) diff --git a/src/lib/engine.c b/src/lib/engine.c index a25b4b49..42a45fc1 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -38,25 +38,26 @@ mk_class_instr(le, r, l) mk_class_instr(lt, r, l, && l != r) ANN static m_bool import_core_libs(const Gwi gwi) { - GWI_OB((t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL))) + const Type t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL); + gwi->gwion->type[et_class] = t_class; GWI_BB(gwi_add_type(gwi, t_class)) - GWI_OB((t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL))) // size = SZ_INT to enable declarations - GWI_BB(gwi_add_type(gwi, t_undefined)) - GWI_OB((t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL))) // size = SZ_INT to enable declarations - GWI_BB(gwi_add_type(gwi, t_auto)) + const Type t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL); + GWI_BB(gwi_set_global_type(gwi, t_undefined, et_undefined)) + const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL); + GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto)) SET_FLAG(t_class, abstract); const Type t_void = gwi_mk_type(gwi, "void", 0, NULL); GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) - GWI_OB((t_null = gwi_mk_type(gwi, "@null", SZ_INT, NULL))) - GWI_BB(gwi_add_type(gwi, t_null)) - GWI_OB((t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL))) - GWI_BB(gwi_add_type(gwi, t_function)) - GWI_OB((t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, t_function))) - GWI_BB(gwi_add_type(gwi, t_fptr)) - GWI_OB((t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, t_function))) - GWI_BB(gwi_add_type(gwi, t_lambda)) - GWI_OB((t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL))) - GWI_BB(gwi_add_type(gwi, t_gack)) + const Type t_null = gwi_mk_type(gwi, "@null", SZ_INT, NULL); + GWI_BB(gwi_set_global_type(gwi, t_null, et_null)) + const Type t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL); + GWI_BB(gwi_set_global_type(gwi, t_function, et_function)) + const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, t_function); + GWI_BB(gwi_set_global_type(gwi, t_fptr, et_fptr)) + const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, t_function); + GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda)) + const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); + GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack)) const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL); GWI_BB(gwi_set_global_type(gwi, t_int, et_int)) const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL); @@ -79,7 +80,8 @@ ANN static m_bool import_core_libs(const Gwi gwi) { const Type t_vec4 = gwi_mk_type(gwi, "Vec4", SZ_VEC4, NULL); gwi->gwion->type[et_vec4] = t_vec4; GWI_BB(import_object(gwi)) - GWI_OB((t_union = gwi_mk_type(gwi, "@Union", SZ_INT, t_object))) + const Type t_union = gwi_mk_type(gwi, "@Union", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_union] = t_union; GWI_BB(gwi_class_ini(gwi, t_union, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) GWI_BB(import_tuple(gwi)) diff --git a/src/lib/event.c b/src/lib/event.c index 693b5a01..a6ad0016 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -9,6 +9,7 @@ #include "object.h" #include "operator.h" #include "import.h" +#include "gwi.h" static CTOR(event_ctor) { EV_SHREDS(o) = new_vector(shred->info->mp); @@ -56,7 +57,8 @@ static MFUN(event_broadcast) { } GWION_IMPORT(event) { - t_event = gwi_mk_type(gwi, "Event", SZ_INT, t_object ); + const Type t_event = gwi_mk_type(gwi, "Event", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_event] = t_event; GWI_BB(gwi_class_ini(gwi, t_event, event_ctor, event_dtor)) GWI_BB(gwi_item_ini(gwi, "int", "@shreds")) GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL)) diff --git a/src/lib/func.c b/src/lib/func.c index 80aba0ca..f29b4966 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -32,7 +32,7 @@ static OP_CHECK(opck_func_call) { e->exp_type = ae_exp_call; memcpy(&e->d.exp_call, &call, sizeof(Exp_Call)); ++*mut; - return check_exp_call1(env, &e->d.exp_call) ?: t_null; + return check_exp_call1(env, &e->d.exp_call) ?: env->gwion->type[et_null]; } static inline void fptr_instr(const Emitter emit, const Func f, const m_uint i) { @@ -46,7 +46,7 @@ static OP_EMIT(opem_func_assign) { if(bin->rhs->type->e->d.func->def->base->tmpl) fptr_instr(emit, bin->lhs->type->e->d.func, 2); const Instr instr = emit_add_instr(emit, int_r_assign); - if(isa(bin->lhs->type, t_fptr) < 0 && GET_FLAG(bin->rhs->type->e->d.func, member)) { + if(!is_fptr(emit->gwion, bin->lhs->type) && GET_FLAG(bin->rhs->type->e->d.func, member)) { const Instr pop = emit_add_instr(emit, LambdaAssign); pop->m_val = SZ_INT; } @@ -67,8 +67,8 @@ ANN static m_bool fptr_tmpl_push(const Env env, struct FptrInfo *info) { t1 = info->rhs->def->base->tmpl->list; nspc_push_type(env->gwion->mp, env->curr); while(t0) { - nspc_add_type(env->curr, t0->xid, t_undefined); - nspc_add_type(env->curr, t1->xid, t_undefined); + nspc_add_type(env->curr, t0->xid, env->gwion->type[et_undefined]); + nspc_add_type(env->curr, t1->xid, env->gwion->type[et_undefined]); t0 = t0->next; t1 = t1->next; } @@ -132,17 +132,17 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { for(m_uint i = 0; i <= v->offset && !type; ++i) { const Symbol sym = (!info->lhs->def->base->tmpl || i != 0) ? func_symbol(env, nspc->name, c, stmpl, i) : info->lhs->def->base->xid; - if(isa(info->lhs->value_ref->type, t_class) < 0) + if(isa(info->lhs->value_ref->type, env->gwion->type[et_class]) < 0) CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym))) else { DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid)) - info->lhs = actual_type(t)->e->d.func; + info->lhs = actual_type(env->gwion, t)->e->d.func; } Func_Base *base[2] = { info->lhs->def->base, info->rhs->def->base }; if(fptr_tmpl_push(env, info) > 0) { if(fptr_rettype(env, info) > 0 && fptr_arity(info) && fptr_args(env, base) > 0) - type = actual_type(info->lhs->value_ref->type) ?: info->lhs->value_ref->type; + type = actual_type(env->gwion, info->lhs->value_ref->type) ?: info->lhs->value_ref->type; if(info->rhs->def->base->tmpl) nspc_pop_type(env->gwion->mp, env->curr); } @@ -183,7 +183,7 @@ ANN static m_bool fptr_lambda(const Env env, struct FptrInfo *info) { } ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) { - if(isa(info->exp->type, t_lambda) < 0) { + if(isa(info->exp->type, env->gwion->type[et_lambda]) < 0) { m_bool nonnull = GET_FLAG(info->exp->type, nonnull); CHECK_BB(fptr_check(env, info)) DECL_OB(const Type, t, = fptr_type(env, info)) @@ -266,7 +266,7 @@ static OP_CHECK(opck_spork) { ERR_O(exp_self(unary)->pos, _("forks must be stored in a value:\n" "fork xxx @=> Fork f")) if(unary->exp && unary->exp->exp_type == ae_exp_call) - return unary->op == insert_symbol("spork") ? t_shred : t_fork; + return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; else if(unary->code) { ++env->scope->depth; nspc_push_value(env->gwion->mp, env->curr); @@ -274,7 +274,7 @@ static OP_CHECK(opck_spork) { nspc_pop_value(env->gwion->mp, env->curr); --env->scope->depth; CHECK_BO(ret) - return unary->op == insert_symbol("spork") ? t_shred : t_fork; + return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; } else ERR_O(exp_self(unary)->pos, _("only function calls can be sporked...")) return NULL; diff --git a/src/lib/gack.c b/src/lib/gack.c index a830373a..55c1fbf0 100644 --- a/src/lib/gack.c +++ b/src/lib/gack.c @@ -13,12 +13,12 @@ #include "gwion.h" #include "gack.h" -static void print_type(const Type type) { - const m_bool is_func = isa(type, t_function) > 0 && isa(type, t_fptr) < 0; +static void print_type(const Gwion gwion, const Type type) { + const m_bool is_func = isa(type, gwion->type[et_function]) > 0 && !is_fptr(gwion, type); gw_out("(%s) ", is_func ? "@function" : type->name); if(GET_FLAG(type, typedef)) { gw_out(" aka "); - print_type(type->e->parent); + print_type(gwion, type->e->parent); } } @@ -68,21 +68,21 @@ static inline void print_string(const M_Object obj) { print_string1(obj ? STRING(obj) : "(null string)"); } -ANN2(1) static inline void print_object(const Type type, const M_Object obj) { - if(isa(type, t_string) > 0) +ANN2(1) static inline void print_object(const Gwion gwion, const Type type, const M_Object obj) { + if(isa(type, gwion->type[et_string]) > 0) print_string(obj); else gw_out("%p", (void*)obj); } -ANN static inline void print_func(const Type type, const m_bit* stack) { - if(isa(type, t_fptr) > 0 && type->e->d.func->def->base->tmpl) { +ANN static inline void print_func(const Gwion gwion,const Type type, const m_bit* stack) { + if(is_fptr(gwion, type) > 0 && type->e->d.func->def->base->tmpl) { const Func f = *(Func*)stack; gw_out("%s", f ? f->name : "(nil)"); return; } if(type->e->d.func) { - const VM_Code code = isa(type, t_fptr) > 0 ? + const VM_Code code = is_fptr(gwion, type) ? *(VM_Code*)stack : type->e->d.func->code; gw_out("%s %s %p", type->name, (void*)code ? code->name : NULL, code); } else // uncalled lambda @@ -113,15 +113,15 @@ ANN void gack(const Gwion gwion, const m_bit* reg, const Instr instr) { for(m_uint i = size + 1; --i;) { const Type type = (Type)vector_at(v, size - i); if(size == 1) - print_type(type); - if(isa(type, t_object) > 0) - print_object(type, *(M_Object*)(reg-offset)); - else if(isa(type, t_function) > 0) - print_func(type, (reg-offset)); - else if(type == t_class) - print_type(type); - else if(isa(type, t_class) > 0) - print_type(type->e->d.base_type); + print_type(gwion, type); + if(isa(type, gwion->type[et_object]) > 0) + print_object(gwion, type, *(M_Object*)(reg-offset)); + else if(isa(type, gwion->type[et_function]) > 0) + print_func(gwion, type, (reg-offset)); + else if(type == gwion->type[et_class]) + print_type(gwion, type); + else if(isa(type, gwion->type[et_class]) > 0) + print_type(gwion, type->e->d.base_type); else if(isa(type, gwion->type[et_void]) > 0) print_string1("void"); else diff --git a/src/lib/import.c b/src/lib/import.c index 26429232..25b19b63 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -605,7 +605,7 @@ ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name) { ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) { DECL_OB(const Exp, exp, = make_exp(gwi, type, name)) DECL_OB(const Type, t, = known_type(gwi->gwion->env, exp->d.exp_decl.td)) - if(isa(t, t_object) > 0) + if(isa(t, gwi->gwion->type[et_object]) > 0) SET_FLAG(exp->d.exp_decl.td, ref); gwi->union_data.list = new_decl_list(gwi->gwion->mp, exp, gwi->union_data.list); return GW_OK; diff --git a/src/lib/modules.c b/src/lib/modules.c index c65eefd7..919da90f 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -13,6 +13,7 @@ #include "import.h" #include "ugen.h" #include "func.h" +#include "gwi.h" static DTOR(basic_dtor) { free(UGEN(o)->module.gen.data); @@ -23,8 +24,8 @@ static TICK(gain_tick) { } static CTOR(gain_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 1, 1); - ugen_gen(shred->info->mp, UGEN(o), gain_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), gain_tick, (m_float*)xmalloc(SZ_FLOAT), 0); UGEN(o)->module.gen.tick = gain_tick; *(m_float*)UGEN(o)->module.gen.data = 1; } @@ -39,7 +40,7 @@ static MFUN(gain_set_gain) { } static GWION_IMPORT(gain) { - const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, t_ugen); + const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_gain, gain_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "gain", gain_get_gain); GWI_BB(gwi_func_end(gwi, 0)) @@ -55,8 +56,8 @@ static TICK(impulse_tick) { } static CTOR(impulse_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 0, 1); - ugen_gen(shred->info->mp, UGEN(o), impulse_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 0, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), impulse_tick, (m_float*)xmalloc(SZ_FLOAT), 0); *(m_float*)UGEN(o)->module.gen.data = 0; } @@ -69,7 +70,7 @@ static MFUN(impulse_set_next) { } static GWION_IMPORT(impulse) { - const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, t_ugen); + const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_impulse, impulse_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "next", impulse_get_next); GWI_BB(gwi_func_end(gwi, 0)) @@ -84,13 +85,13 @@ static TICK(fullrect_tick) { } static CTOR(fullrect_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 1, 1); - ugen_gen(shred->info->mp, UGEN(o), fullrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), fullrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0); *(m_float*)UGEN(o)->module.gen.data = 1; } static GWION_IMPORT(fullrect) { - const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, t_ugen); + const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_fullrect, fullrect_ctor, basic_dtor)) return gwi_class_end(gwi); } @@ -103,13 +104,13 @@ static TICK(halfrect_tick) { } static CTOR(halfrect_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 1, 1); - ugen_gen(shred->info->mp, UGEN(o), halfrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), halfrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0); *(m_float*)UGEN(o)->module.gen.data = 1; } static GWION_IMPORT(halfrect) { - const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, t_ugen); + const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_halfrect, halfrect_ctor, basic_dtor)) return gwi_class_end(gwi); } @@ -119,8 +120,8 @@ static TICK(step_tick) { } static CTOR(step_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 0, 1); - ugen_gen(shred->info->mp, UGEN(o), step_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 0, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), step_tick, (m_float*)xmalloc(SZ_FLOAT), 0); *(m_float*)UGEN(o)->module.gen.data = 0; } @@ -133,7 +134,7 @@ static MFUN(step_set_next) { } static GWION_IMPORT(step) { - const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, t_ugen); + const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_step, step_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "next", step_get_next); GWI_BB(gwi_func_end(gwi, 0)) @@ -151,13 +152,13 @@ static TICK(zerox_tick) { } static CTOR(zerox_ctor) { - ugen_ini(shred->info->mp, UGEN(o), 1, 1); - ugen_gen(shred->info->mp, UGEN(o), zerox_tick, (m_float*)xmalloc(SZ_FLOAT), 0); + ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1); + ugen_gen(shred->info->vm->gwion, UGEN(o), zerox_tick, (m_float*)xmalloc(SZ_FLOAT), 0); *(m_float*)UGEN(o)->module.gen.data = 1; } static GWION_IMPORT(zerox) { - const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, t_ugen); + const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, gwi->gwion->type[et_ugen]); GWI_BB(gwi_class_ini(gwi, t_zerox, zerox_ctor, basic_dtor)) return gwi_class_end(gwi); } diff --git a/src/lib/object.c b/src/lib/object.c index ff06d0e1..d916859c 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -41,13 +41,13 @@ M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { } M_Object new_string(MemPool p, const VM_Shred shred, const m_str str) { - const M_Object o = new_object(p, shred, t_string); + const M_Object o = new_object(p, shred, shred->info->vm->gwion->type[et_string]); STRING(o) = s_name(insert_symbol(shred->info->vm->gwion->st, str)); return o; } -M_Object new_string2(MemPool p, const VM_Shred shred, const m_str str) { - const M_Object o = new_object(p, shred, t_string); +M_Object new_string2(const struct Gwion_ *gwion, const VM_Shred shred, const m_str str) { + const M_Object o = new_object(gwion->mp, shred, gwion->type[et_string]); STRING(o) = str; return o; } @@ -72,7 +72,7 @@ ANN void __release(const M_Object o, const VM_Shred shred) { Value v; while(scope_iter(&iter, &v) > 0) { if(!GET_FLAG(v, static) && !GET_FLAG(v, pure) && - isa(v->type, t_object) > 0) + isa(v->type, shred->info->vm->gwion->type[et_object]) > 0) release(*(M_Object*)(o->data + v->offset), shred); } if(GET_FLAG(t, dtor) && t->nspc->dtor) { @@ -114,7 +114,7 @@ static inline m_bool nonnull_check(const Type l, const Type r) { static inline Type check_nonnull(const Env env, const Type l, const Type r, const m_str action, const loc_t pos) { if(GET_FLAG(r, nonnull)) { - if(isa(l, t_null) > 0) + if(isa(l, env->gwion->type[et_null]) > 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); if(isa(l, r) < 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); @@ -122,7 +122,7 @@ static inline Type check_nonnull(const Env env, const Type l, const Type r, } if(nonnull_check(l, r)) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); - if(l != t_null && isa(l, r) < 0) + if(l != env->gwion->type[et_null] && isa(l, r) < 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); return r; } @@ -131,10 +131,10 @@ static OP_CHECK(at_object) { const Exp_Binary* bin = (Exp_Binary*)data; const Type l = bin->lhs->type; const Type r = bin->rhs->type; - if(opck_rassign(env, data, mut) == t_null) - return t_null; - if(check_nonnull(env, l, r, "assign", exp_self(bin)->pos) == t_null) - return t_null; + if(opck_rassign(env, data, mut) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; + if(check_nonnull(env, l, r, "assign", exp_self(bin)->pos) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; if(bin->rhs->exp_type == ae_exp_decl) { SET_FLAG(bin->rhs->d.exp_decl.td, ref); SET_FLAG(bin->rhs->d.exp_decl.list->self->value, ref); @@ -180,8 +180,8 @@ static OP_CHECK(opck_object_cast) { const Exp_Cast* cast = (Exp_Cast*)data; const Type l = cast->exp->type; const Type r = exp_self(cast)->type; - if(check_nonnull(env, l, r, "cast", exp_self(cast)->pos) == t_null) - return t_null; + if(check_nonnull(env, l, r, "cast", exp_self(cast)->pos) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; return get_force_type(env, r); } @@ -198,8 +198,8 @@ static OP_CHECK(opck_implicit_null2obj) { const struct Implicit* imp = (struct Implicit*)data; const Type l = imp->e->type; const Type r = imp->t; - if(check_nonnull(env, l, r, "implicitly cast", imp->pos) == t_null) - return t_null; + if(check_nonnull(env, l, r, "implicitly cast", imp->pos) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; imp->e->cast_to = r; return imp->t; } @@ -222,7 +222,8 @@ static ID_CHECK(check_this) { } GWION_IMPORT(object) { - t_object = gwi_mk_type(gwi, "Object", SZ_INT, NULL); + const Type t_object = gwi_mk_type(gwi, "Object", SZ_INT, NULL); + gwi->gwion->type[et_object] = t_object; GWI_BB(gwi_class_ini(gwi, t_object, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) GWI_BB(gwi_oper_cond(gwi, "Object", BranchEqInt, BranchNeqInt)) diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index a30074f7..c3060eea 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -20,7 +20,7 @@ static inline m_str access(ae_Exp_Meta meta) { OP_CHECK(opck_basic_cast) { const Exp_Cast* cast = (Exp_Cast*)data; return isa(cast->exp->type, exp_self(cast)->type) > 0 ? - exp_self(cast)->type : t_null; + exp_self(cast)->type : env->gwion->type[et_null]; } OP_CHECK(opck_usr_implicit) { @@ -51,8 +51,8 @@ OP_CHECK(opck_rhs_emit_var) { OP_CHECK(opck_rassign) { const Exp_Binary* bin = (Exp_Binary*)data; - if(opck_const_rhs(env, data, mut) == t_null) - return t_null; + if(opck_const_rhs(env, data, mut) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; bin->rhs->emit_var = 1; return bin->rhs->type; } @@ -95,7 +95,7 @@ OP_CHECK(opck_new) { const Exp_Unary* unary = (Exp_Unary*)data; SET_FLAG(unary->td, ref); DECL_OO(const Type, t, = known_type(env, unary->td)) - if(isa(t, t_object) < 0 && isa(t, t_function) < 0) + if(isa(t, env->gwion->type[et_object]) < 0 && isa(t, env->gwion->type[et_function]) < 0) ERR_O(exp_self(unary)->pos, _("primitive types cannot be used as reference (@)...\n")) if(type_ref(t)) ERR_N(td_pos(unary->td), _("can't use 'new' on ref type '%s'\n"), t->name) diff --git a/src/lib/prim.c b/src/lib/prim.c index 82114d10..3cd9745f 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -136,7 +136,7 @@ static OP_CHECK(opck_chuck_now) { } */ static OP_CHECK(opck_implicit_f2i) { - return t_null; + return env->gwion->type[et_null]; } static OP_CHECK(opck_implicit_i2f) { diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 183a867f..a23884ee 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -14,6 +14,7 @@ #include "import.h" #include "emit.h" #include "traverse.h" +#include "gwi.h" static OP_CHECK(opck_ptr_assign) { const Exp_Binary* bin = (Exp_Binary*)data; @@ -24,7 +25,7 @@ static OP_CHECK(opck_ptr_assign) { do if(!strcmp(t->name, get_type_name(env, bin->rhs->type->name, 1))) return bin->lhs->type; while((t = t->e->parent)); - return t_null; + return env->gwion->type[et_null]; } static INSTR(instr_ptr_assign) { @@ -83,7 +84,7 @@ static INSTR(instr_ptr_deref) { } static INSTR(Cast2Ptr) { - const M_Object o = new_object(shred->info->mp, shred, t_ptr); + const M_Object o = new_object(shred->info->mp, shred, shred->info->vm->gwion->type[et_ptr]); *(m_uint**)o->data = *(m_uint**)REG(-SZ_INT); *(M_Object*)REG(-SZ_INT) = o; } @@ -105,7 +106,8 @@ static OP_EMIT(opem_ptr_deref) { GWION_IMPORT(ptr) { const m_str list[] = { "A" }; - t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, t_object); + const Type t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_ptr] = t_ptr; GWI_BB(gwi_tmpl_ini(gwi, 1, list)) GWI_BB(gwi_class_ini(gwi, t_ptr, NULL, NULL)) GWI_BB(gwi_tmpl_end(gwi)) diff --git a/src/lib/shred.c b/src/lib/shred.c index 49a64918..1c70b813 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -14,6 +14,7 @@ #include "import.h" #include "emit.h" #include "specialid.h" +#include "gwi.h" static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev, o_fork_retsize, o_fork_retval, o_fork_orig; @@ -31,10 +32,11 @@ VM_Shred new_shred_base(const VM_Shred shred, const VM_Code code) { } M_Object new_shred(const VM_Shred shred, m_bool is_spork) { - const M_Object obj = new_object(shred->info->mp, NULL, is_spork ? t_shred : t_fork); + const M_Object obj = new_object(shred->info->mp, NULL, + shred->info->vm->gwion->type[is_spork ? et_shred :et_fork]); ME(obj) = shred; if(!is_spork) { - *(M_Object*)(obj->data + o_fork_ev) = new_object(shred->info->mp, NULL, t_event); + *(M_Object*)(obj->data + o_fork_ev) = new_object(shred->info->mp, NULL, shred->info->vm->gwion->type[et_event]); EV_SHREDS(*(M_Object*)(obj->data + o_fork_ev)) = new_vector(shred->info->mp); } return obj; @@ -229,7 +231,8 @@ void fork_launch(const VM* vm, const M_Object o, const m_uint sz) { #include "nspc.h" GWION_IMPORT(shred) { - GWI_OB((t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, t_object))) + const Type t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_shred] = t_shred; GWI_BB(gwi_class_ini(gwi, t_shred, NULL, shred_dtor)) gwi_item_ini(gwi, "int", "@me"); @@ -299,7 +302,8 @@ GWION_IMPORT(shred) { SET_FLAG((t_shred), abstract); - GWI_OB((t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, t_shred))) + const Type t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, t_shred); + gwi->gwion->type[et_fork] = t_fork; GWI_BB(gwi_class_ini(gwi, t_fork, NULL, fork_dtor)) gwi_item_ini(gwi, "int", "@thread"); GWI_BB((o_fork_thread = gwi_item_end(gwi, ae_flag_const, NULL))) diff --git a/src/lib/string.c b/src/lib/string.c index a0f08b87..2ba94e2d 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -16,6 +16,7 @@ #include "emit.h" #include "specialid.h" #include "func.h" +#include "gwi.h" ANN static void push_string(const VM_Shred shred, const M_Object obj, const m_str c) { STRING(obj) = s_name(insert_symbol(shred->info->vm->gwion->st, c)); @@ -181,9 +182,9 @@ ID_CHECK(check_funcpp) { } GWION_IMPORT(string) { - t_string = gwi_mk_type(gwi, "string", SZ_INT, t_object); + const Type t_string = gwi_mk_type(gwi, "string", SZ_INT, gwi->gwion->type[et_object]); GWI_BB(gwi_class_ini(gwi, t_string, string_ctor, NULL)) - + gwi->gwion->type[et_string] = t_string; gwi_item_ini(gwi, "int", "@data"); GWI_BB(gwi_item_end(gwi, ae_flag_const, NULL)) GWI_BB(gwi_class_end(gwi)) diff --git a/src/lib/tuple.c b/src/lib/tuple.c index f6d50ba7..403ba60f 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -40,7 +40,7 @@ struct UnpackInfo_ { static INSTR(TupleUnpack) { const M_Object o = *(M_Object*)(shred->reg - SZ_INT); struct UnpackInfo_ *info = (struct UnpackInfo_*)instr->m_val; - memcpy(shred->mem + info->mem_offset, o->data + t_tuple->nspc->info->offset + info->obj_offset, info->size); + memcpy(shred->mem + info->mem_offset, o->data + shred->info->vm->gwion->type[et_tuple]->nspc->info->offset + info->obj_offset, info->size); } INSTR(TupleMember) { @@ -111,13 +111,13 @@ ANN void emit_unpack_instr(const Emitter emit, struct TupleEmit *te) { emit_unpack_instr(emit, te); } -static m_bool tuple_match(const Type lhs, const Type rhs) { +static m_bool tuple_match(const Env env, const Type lhs, const Type rhs) { DECL_OB(const Vector, lv, = &lhs->e->tuple->types) DECL_OB(const Vector, rv, = &rhs->e->tuple->types) for(m_uint i = 0; i < vector_size(rv); i++) { DECL_OB(const Type, l, = (Type)vector_at(lv, i)) const Type r = (Type)vector_at(rv, i); - if(r != t_undefined) + if(r != env->gwion->type[et_undefined]) CHECK_BB(isa(l, r)) } return GW_OK; @@ -125,10 +125,10 @@ static m_bool tuple_match(const Type lhs, const Type rhs) { static OP_CHECK(opck_at_object_tuple) { const Exp_Binary *bin = (Exp_Binary*)data; - if(opck_rassign(env, data, mut) == t_null) - return t_null; - if(tuple_match(bin->lhs->type, bin->rhs->type) < 0) - return t_null; + if(opck_rassign(env, data, mut) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; + if(tuple_match(env, bin->lhs->type, bin->rhs->type) < 0) + return env->gwion->type[et_null]; bin->rhs->emit_var = 1; return bin->rhs->type; } @@ -155,12 +155,12 @@ static OP_CHECK(opck_at_tuple) { static OP_CHECK(opck_at_tuple_object) { const Exp_Binary *bin = (Exp_Binary*)data; - if(opck_rassign(env, data, mut) == t_null) - return t_null; + if(opck_rassign(env, data, mut) == env->gwion->type[et_null]) + return env->gwion->type[et_null]; if(!bin->rhs->type->e->tuple) return bin->rhs->type; - if(tuple_match(bin->rhs->type, bin->lhs->type) < 0) - return t_null; + if(tuple_match(env, bin->rhs->type, bin->lhs->type) < 0) + return env->gwion->type[et_null]; bin->rhs->emit_var = 1; return bin->rhs->type; } @@ -188,13 +188,13 @@ mk_opem_tuple2object(impl, struct Implicit *, exp->t) static OP_CHECK(opck_cast_tuple) { const Exp_Cast *cast = (Exp_Cast*)data; - CHECK_BO(tuple_match(exp_self(cast)->type, cast->exp->type)) + CHECK_BO(tuple_match(env, exp_self(cast)->type, cast->exp->type)) return exp_self(cast)->type; } static OP_CHECK(opck_impl_tuple) { struct Implicit *imp = (struct Implicit*)data; - CHECK_BO(tuple_match(imp->e->type, imp->t)) + CHECK_BO(tuple_match(env, imp->e->type, imp->t)) return imp->t; } @@ -235,8 +235,8 @@ ANN void tuple_info(const Env env, Type_Decl *base, const Var_Decl var) { INSTR(TupleCtor) { const Type t = (Type)instr->m_val; const M_Object o = new_object(shred->info->vm->gwion->mp, shred, t); - const size_t sz = t_tuple->nspc->info->offset; - memcpy(o->data + t_tuple->nspc->info->offset, + const size_t sz = shred->info->vm->gwion->type[et_tuple]->nspc->info->offset; + memcpy(o->data + shred->info->vm->gwion->type[et_tuple]->nspc->info->offset, shred->reg - (t->nspc->info->offset - sz), (t->nspc->info->offset - sz)); shred->reg -= (t->nspc->info->offset - sz - SZ_INT); *(M_Object*)(shred->reg - SZ_INT) = o; @@ -244,7 +244,7 @@ INSTR(TupleCtor) { ANN static Symbol tuple_sym(const Env env, const Vector v) { GwText text = { .mp=env->gwion->mp }; - text_add(&text, t_tuple->name); + text_add(&text, env->gwion->type[et_tuple]->name); text_add(&text, "<~"); for(m_uint i = 0; i < vector_size(v); ++i) { const Type t = (Type)vector_at(v, i); @@ -293,7 +293,7 @@ ANN Type tuple_type(const Env env, const Vector v, const loc_t pos) { } Section * section = new_section_stmt_list(env->gwion->mp, base); Class_Body body = new_class_body(env->gwion->mp, section, NULL); - const ID_List ilist = new_id_list(env->gwion->mp, insert_symbol(t_tuple->name), + const ID_List ilist = new_id_list(env->gwion->mp, insert_symbol(env->gwion->type[et_tuple]->name), loc_cpy(env->gwion->mp, pos)); Type_Decl *td = new_type_decl(env->gwion->mp, ilist); Class_Def cdef = new_class_def(env->gwion->mp, ae_flag_template, @@ -325,7 +325,8 @@ ANN void free_tupleform(MemPool p, const TupleForm tuple) { } GWION_IMPORT(tuple) { - GWI_OB((t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, t_object))) + const Type t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_tuple] = t_tuple; GWI_BB(gwi_class_ini(gwi, t_tuple, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) SET_FLAG(t_tuple, abstract | ae_flag_template); diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 7b2250e9..117e2ccf 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -13,6 +13,7 @@ #include "gwi.h" #include "ugen.h" #include "driver.h" +#include "gwi.h" ANN static inline void ugop_add (const UGen u, const m_float f) { u->in += f; } ANN static inline void ugop_sub (const UGen u, const m_float f) { u->in -= f; } @@ -83,49 +84,49 @@ ANEW static UGen new_UGen(MemPool p) { return u; } -ANEW M_Object new_M_UGen(MemPool p) { - const M_Object o = new_object(p, NULL, t_ugen); - UGEN(o) = new_UGen(p); +ANEW M_Object new_M_UGen(const struct Gwion_ *gwion) { + const M_Object o = new_object(gwion->mp, NULL, gwion->type[et_ugen]); + UGEN(o) = new_UGen(gwion->mp); return o; } -ANN static void assign_channel(MemPool p, const UGen u) { +ANN static void assign_channel(const struct Gwion_ *gwion, const UGen u) { u->multi = 1; u->compute = gen_compute_multi; u->connect.multi->channel = (M_Object*)xmalloc(u->connect.multi->n_chan * SZ_INT); for(uint i = u->connect.multi->n_chan + 1; --i;) { const uint j = i - 1; - const M_Object chan = new_M_UGen(p); - ugen_ini(p, UGEN(chan), u->connect.multi->n_in > j, u->connect.multi->n_out > j); + const M_Object chan = new_M_UGen(gwion); + ugen_ini(gwion, UGEN(chan), u->connect.multi->n_in > j, u->connect.multi->n_out > j); UGEN(chan)->module.ref = u; UGEN(chan)->compute = compute_chan; u->connect.multi->channel[j] = chan; } } -ANN void ugen_gen(MemPool p, const UGen u, const f_tick tick, void* data, const m_bool trig) { +ANN void ugen_gen(const struct Gwion_ *gwion, const UGen u, const f_tick tick, void* data, const m_bool trig) { u->module.gen.tick = tick; u->module.gen.data = data; if(trig) { - u->module.gen.trig = new_UGen(p); + u->module.gen.trig = new_UGen(gwion->mp); u->module.gen.trig->compute = compute_mono; - ugen_ini(p, u->module.gen.trig, 1, 1); + ugen_ini(gwion, u->module.gen.trig, 1, 1); u->compute = (u->compute == gen_compute_mono ? gen_compute_monotrig : gen_compute_multitrig); } } -ANN void ugen_ini(MemPool p, const UGen u, const uint in, const uint out) { +ANN void ugen_ini(const struct Gwion_ *gwion, const UGen u, const uint in, const uint out) { const uint chan = in > out ? in : out; if(chan == 1) { - u->connect.net = mp_calloc(p, ugen_net); + u->connect.net = mp_calloc(gwion->mp, ugen_net); vector_init(&u->connect.net->from); vector_init(&u->connect.net->to); } else { - u->connect.multi = mp_calloc(p, ugen_multi); + u->connect.multi = mp_calloc(gwion->mp, ugen_multi); u->connect.multi->n_in = in; u->connect.multi->n_out = out; u->connect.multi->n_chan = chan; - assign_channel(p, u); + assign_channel(gwion, u); } } @@ -306,10 +307,10 @@ struct ugen_importer { ANN static m_int add_ugen(const Gwi gwi, struct ugen_importer* imp) { VM* vm = gwi_vm(gwi); - const M_Object o = new_M_UGen(gwi->gwion->mp); + const M_Object o = new_M_UGen(gwi->gwion); const UGen u = imp->ugen = UGEN(o); - ugen_ini(vm->gwion->mp, u, imp->nchan, imp->nchan); - ugen_gen(vm->gwion->mp, u, imp->tick, (void*)imp->vm, 0); + ugen_ini(vm->gwion, u, imp->nchan, imp->nchan); + ugen_gen(vm->gwion, u, imp->tick, (void*)imp->vm, 0); vector_add(&vm->ugen, (vtype)u); CHECK_BB(gwi_item_ini(gwi, "UGen", imp->name)) return gwi_item_end(gwi, ae_flag_const, o); @@ -324,7 +325,7 @@ static GWION_IMPORT(global_ugens) { struct ugen_importer adc = { vm, adc_tick, NULL, "adc", vm->bbq->si->in }; add_ugen(gwi, &adc); ugen_connect(dac.ugen, hole.ugen); - SET_FLAG(t_ugen, abstract); + SET_FLAG(gwi->gwion->type[et_ugen], abstract); return GW_OK; } @@ -334,7 +335,8 @@ static OP_CHECK(opck_chuck_ugen) { } GWION_IMPORT(ugen) { - t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, t_object); + const Type t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, gwi->gwion->type[et_object]); + gwi->gwion->type[et_ugen] = t_ugen; GWI_BB(gwi_class_ini(gwi, t_ugen, ugen_ctor, ugen_dtor)) GWI_BB(gwi_item_ini(gwi, "int", "@ugen")) GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL)) diff --git a/src/lib/vararg.c b/src/lib/vararg.c index b6acd692..2de725e6 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -12,6 +12,7 @@ #include "gwion.h" #include "operator.h" #include "import.h" +#include "gwi.h" void free_vararg(MemPool p, struct Vararg_* arg) { xfree(arg->d); @@ -83,13 +84,14 @@ static FREEARG(freearg_vararg) { } GWION_IMPORT(vararg) { - GWI_OB((t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, t_object))) + const Type t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, gwi->gwion->type[et_object]); const Type t_varobj = gwi_mk_type(gwi, "VarObject", SZ_INT, t_vararg); SET_FLAG(t_varobj, abstract); - t_varloop = gwi_mk_type(gwi, "@VarLoop", SZ_INT, NULL); + const Type t_varloop = gwi_mk_type(gwi, "@VarLoop", SZ_INT, NULL); GWI_BB(gwi_add_type(gwi, t_varobj)) - GWI_BB(gwi_add_type(gwi, t_varloop)) + GWI_BB(gwi_set_global_type(gwi, t_varloop, et_varloop)) GWI_BB(gwi_class_ini(gwi, t_vararg, NULL, NULL)) + gwi->gwion->type[et_vararg] = t_vararg; GWI_BB(gwi_union_ini(gwi, NULL)) GWI_BB(gwi_union_add(gwi, "@VarLoop", "start")) GWI_BB(gwi_union_add(gwi, "@VarLoop", "end")) diff --git a/src/oo/env.c b/src/oo/env.c index 0b8e0598..aece42e0 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -82,7 +82,7 @@ ANN void env_pop(const Env env, const m_uint scope) { } ANN void env_add_type(const Env env, const Type type) { - const Type v_type = type_copy(env->gwion->mp, t_class); + const Type v_type = type_copy(env->gwion->mp, env->gwion->type[et_class]); v_type->e->d.base_type = type; SET_FLAG(type, builtin); const Symbol sym = insert_symbol(type->name); diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index e88a9910..69362ac9 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -64,7 +64,7 @@ ANN Type find_type(const Env env, ID_List path) { ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { const Value v = nspc_lookup_value0(env->curr, s); - if(!v || isa(v->type, t_class) > 0) + if(!v || isa(v->type, env->gwion->type[et_class]) > 0) return GW_OK; env_err(env, pos, _("'%s' already declared as variable of type '%s'."), s_name(s), v->type->name); diff --git a/src/oo/nspc.c b/src/oo/nspc.c index dad4e10c..7490e778 100644 --- a/src/oo/nspc.c +++ b/src/oo/nspc.c @@ -33,7 +33,7 @@ ANN static void free_nspc_value(const Nspc a, Gwion gwion) { if(!a->is_union) { while(scope_iter(&iter, &v) > 0) { if(v) { - if(isa(v->type, t_object) > 0) + if(isa(v->type, gwion->type[et_object]) > 0) nspc_release_object(a, v, gwion); REM_REF(v, gwion); } diff --git a/src/oo/type.c b/src/oo/type.c index c3d6e78c..0038bcb9 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -60,12 +60,6 @@ ANN Type type_copy(MemPool p, const Type type) { a->e->d.base_type = type->e->d.base_type; a->array_depth = type->array_depth; a->e->def = type->e->def; - if(t_function && isa(type, t_function) > 0) { - if(a->e->tuple) { - free_tupleform(p, a->e->tuple); - a->e->tuple = NULL; - } - } return a; } @@ -115,12 +109,12 @@ ANN Type array_type(const Env env, const Type base, const m_uint depth) { const Type type = nspc_lookup_type1(base->e->owner, sym); if(type) return type; - const Type t = new_type(env->gwion->mp, t_array->xid, base->name, t_array); + const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, base->name, env->gwion->type[et_array]); t->name = s_name(sym); t->size = SZ_INT; t->array_depth = depth + base->array_depth; t->e->d.base_type = base; - t->nspc = t_array->nspc; + t->nspc = env->gwion->type[et_array]->nspc; ADD_REF(t->nspc); SET_FLAG(t, checked); t->e->owner = base->e->owner; @@ -197,6 +191,10 @@ ANN m_uint get_depth(const Type type) { return depth; } -Type - 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; +ANN m_bool is_fptr(const struct Gwion_* gwion, const Type t) { + return isa(actual_type(gwion, t), gwion->type[et_fptr]) > 0; +} + +ANN Type actual_type(const struct Gwion_* gwion, const Type t) { + return isa(t, gwion->type[et_class]) > 0 ? t->e->d.base_type : t; +} diff --git a/src/oo/value.c b/src/oo/value.c index 70289cea..f0398620 100644 --- a/src/oo/value.c +++ b/src/oo/value.c @@ -12,9 +12,9 @@ ANN static void free_value(Value a, Gwion gwion) { const Type t = a->type; if(!GET_FLAG(a, func) && a->d.ptr && !GET_FLAG(a, union) && !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class) - && isa(t, t_object) < 0) + && isa(t, gwion->type[et_object]) < 0) _mp_free(gwion->mp, t->size, a->d.ptr); - if(isa(t, t_class) > 0/* || isa(a->type, t_function) > 0*/) + if(isa(t, gwion->type[et_class]) > 0/* || isa(a->type, t_function) > 0*/) REM_REF(t, gwion) mp_free(gwion->mp, Value, a); } diff --git a/src/parse/check.c b/src/parse/check.c index 1d87b180..1905510c 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -75,10 +75,10 @@ ANN Type check_td(const Env env, Type_Decl *td) { CHECK_BO(scan1_exp(env, td->exp)) CHECK_BO(scan2_exp(env, td->exp)) CHECK_OO(check_exp(env, td->exp)) - const Type t = actual_type(td->exp->type); - if(!t || (isa(td->exp->type, t_class) < 0 && t == t_class)) + const Type t = actual_type(env->gwion, td->exp->type); + if(!t || (isa(td->exp->type, env->gwion->type[et_class]) < 0 && t == env->gwion->type[et_class])) ERR_O(td->exp->pos, _("Expression must be of type '%s', not '%s'\n" - "maybe you meant typeof(Expression)"), t_class->name, td->exp->type->name); + "maybe you meant typeof(Expression)"), env->gwion->type[et_class]->name, td->exp->type->name); m_uint depth; td->xid = str2list(env, t->name, &depth); if(depth) { @@ -112,13 +112,13 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { clear_decl(env, decl); CHECK_BO(scan1_exp(env, exp_self(decl))) CHECK_BO(scan2_exp(env, exp_self(decl))) - if(isa(decl->type, t_class) > 0) { + if(isa(decl->type, env->gwion->type[et_class]) > 0) { do { - list->self->value->type = t_auto; + list->self->value->type = env->gwion->type[et_auto]; } while((list = list->next)); - ((Exp_Decl*)decl)->type = t_auto; + ((Exp_Decl*)decl)->type = env->gwion->type[et_auto]; } - if(decl->type == t_auto) + if(decl->type == env->gwion->type[et_auto]) ERR_O(td_pos(decl->td), _("can't infer type.")); } if(!decl->type) @@ -140,14 +140,14 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { if(env->class_def) { if(GET_FLAG(decl->td, member)) { decl_member(env, v); - if(isa(env->class_def, t_object) > 0) + if(isa(env->class_def, env->gwion->type[et_object]) > 0) tuple_info(env, decl->td, var); } else if(GET_FLAG(decl->td, static)) decl_static(env, v); } else if(global || (env->func && GET_FLAG(env->func->def, global))) SET_FLAG(v, abstract); - if(isa(decl->type, t_fptr) > 0) + if(is_fptr(env->gwion, decl->type)) CHECK_BO(check_fptr_decl(env, var)) SET_FLAG(v, checked | ae_flag_used); nspc_add_value(env->curr, var->xid, v); @@ -243,7 +243,7 @@ ANN static inline Value prim_str_value(const Env env, const Symbol sym) { const Value v = nspc_lookup_value0(env->global_nspc, sym); if(v) return v; - const Value value = new_value(env->gwion->mp, t_string, s_name(sym)); + const Value value = new_value(env->gwion->mp, env->gwion->type[et_string], s_name(sym)); nspc_add_value_front(env->global_nspc, sym, value); return value; } @@ -255,7 +255,7 @@ ANN Type prim_str(const Env env, Exp_Primary *const prim) { sprintf(c, "%s:string", str); prim->value = prim_str_value(env, insert_symbol(c)); } - return t_string; + return env->gwion->type[et_string];// prim->value } ANN static Type prim_id(const Env env, Exp_Primary* primary) { @@ -319,7 +319,7 @@ ANN static Type prim_gack(const Env env, const Exp_Primary * primary) { if(env->func) UNSET_FLAG(env->func, pure); CHECK_OO((check_exp(env, primary->d.exp))) - return t_gack; + return env->gwion->type[et_gack]; } ANN static Type prim_tuple(const Env env, const Exp_Primary * primary) { @@ -341,7 +341,7 @@ ANN static Type prim_##name(const Env env NUSED, const Exp_Primary * primary NUS describe_prim_xxx(num, env->gwion->type[et_int]) describe_prim_xxx(float, env->gwion->type[et_float]) describe_prim_xxx(nil, env->gwion->type[et_void]) -describe_prim_xxx(unpack, t_tuple) +describe_prim_xxx(unpack, env->gwion->type[et_tuple]) typedef Type (*_type_func)(const Env, const void*); static const _type_func prim_func[] = { @@ -366,7 +366,7 @@ ANN static Type tuple_depth(const Env env, const Array_Sub array) { if(idx >= vector_size(v)) ERR_O(exp->pos, _("tuple subscripts too big")) const Type type = (Type)vector_at(v, idx); - if(type == t_undefined) + if(type == env->gwion->type[et_undefined]) ERR_O(exp->pos, _("tuple subscripts is undefined at index %lu"), idx) if(!exp->next) return type; @@ -392,7 +392,7 @@ ANN static Type at_depth(const Env env, const Array_Sub array) { } if(t->array_depth >= depth) return array_type(env, array_base(array->type), t->array_depth - depth); - return (isa(t, t_tuple) < 0 ? partial_depth : tuple_depth)(env, array); + return (isa(t, env->gwion->type[et_tuple]) < 0 ? partial_depth : tuple_depth)(env, array); } static inline m_bool index_is_int(const Env env, Exp e, m_uint *depth) { @@ -443,7 +443,7 @@ ANN static m_bool func_match_inner(const Env env, const Exp e, const Type t, e->type->array_depth == t->array_depth && array_base(e->type) == array_base(t); if(!match) { - if(e->type == t_lambda && isa(t, t_fptr) > 0) { + if(e->type == env->gwion->type[et_lambda] && is_fptr(env->gwion, t)) { const Type owner = nspc_lookup_type1(t->e->owner->parent, insert_symbol(t->e->owner->name)); return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def); @@ -469,8 +469,8 @@ ANN2(1,2) static Func find_func_match_actual(const Env env, Func func, const Exp CHECK_OO(func->next); return find_func_match_actual(env, func->next, args, implicit, specific); } - if(e1->type == t_undefined || - (func->def->base->tmpl && is_fptr(func->value_ref->type) > 0)) { + if(e1->type == env->gwion->type[et_undefined] || + (func->def->base->tmpl && is_fptr(env->gwion, func->value_ref->type) > 0)) { if(SAFE_FLAG(func->value_ref->owner_class, template)) CHECK_BO(template_push_types(env, func->value_ref->owner_class->e->def->base.tmpl)) e1->type = known_type(env, e1->td); @@ -538,7 +538,7 @@ ANN static m_bool check_func_args(const Env env, Arg_List arg_list) { const Value v = decl->value; if(arg_list->td && !arg_list->td->xid) arg_list->type = v->type = check_td(env, arg_list->td); - if(isa(v->type, t_object) > 0 || isa(v->type, t_function) > 0) + 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)) SET_FLAG(v, checked); @@ -553,7 +553,7 @@ CHECK_BO(check_call(env, exp)) Func m_func = NULL, former = env->func; DECL_OO(const m_str, tmpl_name, = tl2str(env, types)) const m_uint scope = env_push(env, v->owner_class, v->owner); - if(is_fptr(v->type)) { + if(is_fptr(env->gwion, v->type)) { const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl_name, 0); const Value value = nspc_lookup_value1(v->owner, sym); Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->type->e->d.func->def; @@ -564,7 +564,7 @@ CHECK_BO(check_call(env, exp)) if(template_push_types(env, fbase->tmpl) > 0) { const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase, base->flag); if(value) { - fptr->type = actual_type(value->type); + fptr->type = actual_type(env->gwion, value->type); fptr->value = value; } if(traverse_fptr_def(env, fptr) > 0 && @@ -573,7 +573,7 @@ CHECK_BO(check_call(env, exp)) m_func = find_func_match(env, fbase->func, exp->args); nspc_pop_type(env->gwion->mp, env->curr); if(!value && m_func) - nspc_add_type_front(v->owner, sym, actual_type(m_func->value_ref->type)); + nspc_add_type_front(v->owner, sym, actual_type(env->gwion, m_func->value_ref->type)); } free_fptr_def(env->gwion->mp, fptr); // ???? related } @@ -745,7 +745,7 @@ ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) { CHECK_OB(check_exp(env, exp)) - if(isa(exp->type, t_function) < 0) + if(isa(exp->type, env->gwion->type[et_function]) < 0) ERR_B(exp->pos, _("function call using a non-function value")) return GW_OK; } @@ -774,7 +774,7 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) { ANN Type check_exp_call1(const Env env, const Exp_Call *exp) { CHECK_BO(check_exp_call1_check(env, exp->func)) - if(exp->func->type == t_lambda) + if(exp->func->type == env->gwion->type[et_lambda]) return check_lambda_call(env, exp); if(GET_FLAG(exp->func->type->e->d.func, ref)) { const Value value = exp->func->type->e->d.func->value_ref; @@ -799,7 +799,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary* bin) { bin->rhs->exp_type == ae_exp_decl) bin->lhs->d.exp_unary.fork_ok = 1; CHECK_OO(check_exp(env, bin->lhs)) - if(bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == t_auto) + if(bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == env->gwion->type[et_auto]) bin->rhs->type = bin->rhs->d.exp_decl.type = bin->lhs->type; CHECK_OO(check_exp(env, bin->rhs)) struct Op_Import opi = { .op=bin->op, .lhs=bin->lhs->type, @@ -818,7 +818,7 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix* post) { struct Op_Import opi = { .op=post->op, .lhs=check_exp(env, post->exp), .data=(uintptr_t)post, .pos=exp_self(post)->pos }; CHECK_OO(opi.lhs) const Type t = op_check(env, &opi); - if(t && isa(t, t_object) < 0) + if(t && isa(t, env->gwion->type[et_object]) < 0) exp_self(post)->meta = ae_meta_value; return t; } @@ -839,7 +839,7 @@ ANN static m_bool predefined_call(const Env env, const Type t, const loc_t pos) ANN static Type check_exp_call(const Env env, Exp_Call* exp) { if(exp->tmpl) { CHECK_OO(check_exp(env, exp->func)) - const Type t = actual_type(!GET_FLAG(exp->func->type, nonnull) ? + const Type t = actual_type(env->gwion, !GET_FLAG(exp->func->type, nonnull) ? exp->func->type : exp->func->type->e->parent); const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)); if(!GET_FLAG(v, func) && !GET_FLAG(exp->func->type, func) ) @@ -892,7 +892,7 @@ ANN static Type check_exp_if(const Env env, const Exp_If* exp_if) { ANN static Type check_exp_dot(const Env env, Exp_Dot* member) { const m_str str = s_name(member->xid); CHECK_OO((member->t_base = check_exp(env, member->base))) - const m_bool base_static = isa(member->t_base, t_class) > 0; + const m_bool base_static = isa(member->t_base, env->gwion->type[et_class]) > 0; const Type the_base = base_static ? member->t_base->e->d.base_type : member->t_base; if(!the_base->nspc) ERR_O(member->base->pos, @@ -929,8 +929,8 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot* member) { ANN m_bool check_type_def(const Env env, const Type_Def tdef) { return tdef->type->e->def ? check_class_def(env, tdef->type->e->def) : GW_OK; } -ANN static Type check_exp_lambda(const Env env NUSED, - const Exp_If* exp_if NUSED) { return t_lambda; } +ANN static Type check_exp_lambda(const Env env, + const Exp_If* exp_if NUSED) { return env->gwion->type[et_lambda]; } ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) { DECL_OO(const Type, t, = check_exp(env, exp->exp)) @@ -950,9 +950,9 @@ ANN static inline Type check_exp(const Env env, const Exp exp) { do { next = curr->next; CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d))) - if(isa(curr->type, t_varloop) > 0 && (prev || next)) + if(isa(curr->type, env->gwion->type[et_varloop]) > 0 && (prev || next)) ERR_O(exp->pos, _("Varloop must be the only expression")) - if(env->func && isa(curr->type, t_lambda) < 0 && isa(curr->type, t_function) > 0 && + if(env->func && isa(curr->type, env->gwion->type[et_lambda]) < 0 && isa(curr->type, env->gwion->type[et_function]) > 0 && !GET_FLAG(curr->type->e->d.func, pure)) UNSET_FLAG(env->func, pure); } while((prev = curr) && (curr = next)); @@ -1001,7 +1001,7 @@ ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) { const m_uint depth = t->array_depth - 1; if(GET_FLAG(t, typedef)) t = t->e->parent; - if(!ptr || isa(t, t_array) < 0) + if(!ptr || isa(t, env->gwion->type[et_array]) < 0) ERR_B(stmt_self(stmt)->pos, _("type '%s' is not array.\n" " This is not allowed in auto loop"), stmt->exp->type->name) if(stmt->is_ptr) { @@ -1076,7 +1076,7 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { ERR_B(stmt_self(stmt)->pos, _("'return' statement found outside function definition")) DECL_OB(const Type, ret_type, = stmt->val ? check_exp(env, stmt->val) : env->gwion->type[et_void]) if(!env->func->def->base->ret_type) { - assert(isa(env->func->value_ref->type, t_lambda) > 0); + assert(isa(env->func->value_ref->type, env->gwion->type[et_lambda]) > 0); env->func->def->base->ret_type = ret_type; return GW_OK; } @@ -1119,7 +1119,7 @@ ANN m_bool check_union_decl(const Env env, const Union_Def udef) { Decl_List l = udef->l; do { CHECK_OB(check_exp(env, l->self)) - if(isa(l->self->type, t_object) > 0) { + if(isa(l->self->type, env->gwion->type[et_object]) > 0) { Var_Decl_List list = l->self->d.exp_decl.list; do SET_FLAG(list->self->value, pure); while((list = list->next)); @@ -1291,7 +1291,7 @@ ANN static m_bool check_parent_match(const Env env, const Func_Def fdef) { vector_init(&env->curr->info->vtable); if(parent) { const Value v = find_value(parent, fdef->base->xid); - if(v && isa(v->type, t_function) > 0) { + if(v && isa(v->type, env->gwion->type[et_function]) > 0) { const m_bool match = parent_match_actual(env, fdef, v->d.func_ref); if(match) return match; @@ -1325,7 +1325,7 @@ ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef) { const Func func = fdef->base->func; if(env->class_def && env->class_def->e->parent) { const Value override = find_value(env->class_def->e->parent, fdef->base->xid); - if(override && override->owner_class && isa(override->type, t_function) < 0) + if(override && override->owner_class && isa(override->type, env->gwion->type[et_function]) < 0) ERR_B(fdef->pos, _("function name '%s' conflicts with previously defined value...\n" " from super class '%s'..."), @@ -1337,7 +1337,7 @@ ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef) { } ANN static Value set_variadic(const Env env) { - const Value variadic = new_value(env->gwion->mp, t_vararg, "vararg"); + const Value variadic = new_value(env->gwion->mp, env->gwion->type[et_vararg], "vararg"); SET_FLAG(variadic, checked); nspc_add_value(env->curr, insert_symbol("vararg"), variadic); return variadic; @@ -1413,14 +1413,14 @@ ANN m_bool check_class_def(const Env env, const Class_Def cdef) { return GW_OK; const Type type = cdef->base.type; SET_FLAG(type, check); - if(type->e->parent == t_undefined) { + if(type->e->parent == env->gwion->type[et_undefined]) { type->e->parent = check_td(env, cdef->base.ext); return traverse_cdef(env, cdef); } if(cdef->base.ext) CHECK_BB(scanx_parent(cdef->base.type, check_class_parent, env)) else if(!type->e->parent) - type->e->parent = t_object; + type->e->parent = env->gwion->type[et_object]; inherit(type); if(cdef->body) CHECK_BB(env_body(env, cdef, check_section)) diff --git a/src/parse/operator.c b/src/parse/operator.c index c38d3f53..78ca400b 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -168,7 +168,7 @@ ANN Type op_check(const Env env, struct Op_Import* opi) { struct OpChecker ock = { env, &nspc->info->op_map, &opi2, 0 }; const Type ret = op_check_inner(&ock); if(ret) { - if(ret == t_null) + if(ret == env->gwion->type[et_null]) break; if(!ock.mut) set_nspc(&ock, nspc); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 5b0ca0f2..efd329b2 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -24,7 +24,7 @@ static inline void add_type(const Env env, const Nspc nspc, const Type t) { ANN static Value mk_class(const Env env, const Type base) { const Symbol sym = insert_symbol(base->name); - const Type t = type_copy(env->gwion->mp, t_class); + const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]); const Value v = new_value(env->gwion->mp, t, s_name(sym)); t->e->d.base_type = base; v->owner = base->e->owner; @@ -76,7 +76,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { CHECK_OB(known_type(env, fptr->base->td)) CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td))); const m_str name = s_name(fptr->base->xid); - const Type t = new_type(env->gwion->mp, t_fptr->xid, name, t_fptr); + const Type t = new_type(env->gwion->mp, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]); t->e->owner = !(!env->class_def && GET_FLAG(fptr->base->td, global)) ? env->curr : env->global_nspc; t->nspc = new_nspc(env->gwion->mp, name); @@ -144,7 +144,7 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { CHECK_BB(env_access(env, tdef->ext->flag, td_pos(tdef->ext))) DECL_OB(const Type, base, = tdef->tmpl ? find_type(env, tdef->ext->xid) : known_type(env, tdef->ext)) CHECK_BB(scan0_defined(env, tdef->xid, td_pos(tdef->ext))) - if(isa(base, t_function) < 0) { + if(isa(base, env->gwion->type[et_function]) < 0) { if(!tdef->ext->types && (!tdef->ext->array || !tdef->ext->array->exp)) typedef_simple(env, tdef, base); else @@ -181,14 +181,14 @@ ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) { ANN static Type union_type(const Env env, const Nspc nspc, const Symbol s, const m_bool add) { const m_str name = s_name(s); - const Type t = type_copy(env->gwion->mp, t_union); + const Type t = type_copy(env->gwion->mp, env->gwion->type[et_union]); t->xid = ++env->scope->type_xid; t->name = name; t->nspc = new_nspc(env->gwion->mp, name); t->nspc->parent = nspc; t->nspc->is_union = 1; t->e->owner = nspc; - t->e->parent = t_union; + t->e->parent = env->gwion->type[et_union]; if(add) { add_type(env, nspc, t); mk_class(env, t); @@ -274,7 +274,7 @@ ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def cdef) { } ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { - const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), t_object); + const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), env->gwion->type[et_object]); t->e->owner = env->curr; t->nspc = new_nspc(env->gwion->mp, t->name); // t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 86c54c23..c03be21f 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -43,7 +43,7 @@ ANN static Type void_type(const Env env, const Type_Decl* td) { DECL_OO(const Type, type, = known_type(env, td)) { const Type t = get_type(type); - if(isa(t, t_object) > 0) + if(isa(t, env->gwion->type[et_object]) > 0) CHECK_BO(type_recursive(env, td, t)) } if(type->size) @@ -78,7 +78,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)) Type t = decl->type; const Value former = nspc_lookup_value0(env->curr, var->xid); - if(former && t != t_auto) + if(former && t != env->gwion->type[et_auto]) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) if(var->array) { @@ -267,8 +267,7 @@ ANN m_bool scan1_fptr_def(const Env env, const Fptr_Def fptr) { ANN m_bool scan1_type_def(const Env env, const Type_Def tdef) { if(!tdef->type->e->def)return GW_OK; -// return tdef->type->e->def ? scan1_cdef(env, tdef->type->e->def) : GW_OK; - return isa(tdef->type, t_fptr) < 0 ? scan1_cdef(env, tdef->type->e->def) : GW_OK; + return !is_fptr(env->gwion, tdef->type) ? scan1_cdef(env, tdef->type->e->def) : GW_OK; } ANN m_bool scan1_union_def_action(const Env env, const Union_Def udef, @@ -387,7 +386,7 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { if(cdef->base.type == t) ERR_B(pos, _("recursive (%s <= %s) class declaration."), cdef->base.type->name, t->name); } while((t = t->e->parent)); - if(isa(parent, t_object) < 0) + if(isa(parent, env->gwion->type[et_object]) < 0) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) if(parent->e->def && !GET_FLAG(parent, scan1)) CHECK_BB(scanx_parent(parent, scan1_cdef, env)) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 2ccebe1b..f239b9cd 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -17,6 +17,7 @@ #include "instr.h" #include "import.h" +#include "tuple.h" ANN static m_bool scan2_stmt(const Env, const Stmt); ANN static m_bool scan2_stmt_list(const Env, Stmt_List); @@ -99,7 +100,7 @@ ANN m_bool scan2_fptr_def(const Env env, const Fptr_Def fptr) { ANN m_bool scan2_type_def(const Env env, const Type_Def tdef) { if(!tdef->type->e->def) return GW_OK; - return isa(tdef->type, t_fptr) < 0 ? scan2_class_def(env, tdef->type->e->def) : GW_OK; + return !is_fptr(env->gwion, tdef->type) ? scan2_class_def(env, tdef->type->e->def) : GW_OK; } ANN static inline Value prim_value(const Env env, const Symbol s) { @@ -303,8 +304,8 @@ ANN static m_bool scan2_stmt_list(const Env env, Stmt_List list) { ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const Value overload) { const m_bool base = tmpl_base(f->base->tmpl); const m_bool tmpl = GET_FLAG(overload, template); - if(isa(overload->type, t_function) < 0 || isa(overload->type, t_fptr) > 0) { - if(isa(actual_type(overload->type), t_function) < 0) + if(isa(overload->type, env->gwion->type[et_function]) < 0 || is_fptr(env->gwion, overload->type)) { + if(isa(actual_type(env->gwion, overload->type), env->gwion->type[et_function]) < 0) ERR_B(f->pos, _("function name '%s' is already used by another value"), overload->name) } if((!tmpl && base) || (tmpl && !base && !GET_FLAG(f, template))) @@ -324,12 +325,15 @@ ANN static Func scan_new_func(const Env env, const Func_Def f, const m_str name) } ANN static Type func_type(const Env env, const Func func) { - const Type t = type_copy(env->gwion->mp, func->def->base->td ? t_function : t_lambda); + const Type t = type_copy(env->gwion->mp, env->gwion->type[func->def->base->td ? et_function : et_lambda]); t->name = func->name; t->e->owner = env->curr; if(GET_FLAG(func, member)) t->size += SZ_INT; t->e->d.func = func; + if(t->e->tuple) + free_tupleform(env->gwion->mp, t->e->tuple); + t->e->tuple = NULL; return t; } diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 4f24d268..b94925ac 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -68,7 +68,7 @@ scanx_parent(const Type t, const _exp_func f, void* d) { ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef, const _exp_func f_cdef, const _exp_func f_union) { const Type t = get_type(cdef->base.type); - if(t->e->parent != t_union) + if(t->e->parent != env->gwion->type[et_union]) return f_cdef(opt, t->e->def); CHECK_BB(template_push_types(env, t->e->def->base.tmpl)) const m_bool ret = f_union(opt, t->e->def->union_def); diff --git a/src/parse/template.c b/src/parse/template.c index 11cc1942..618e2d9f 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -186,7 +186,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { if(GET_FLAG(t, ref)) return t; if(!type->types) { - if(t != t_tuple) + if(t != env->gwion->type[et_tuple]) ERR_O(t->e->def->pos, _("you must provide template types for type '%s'"), t->name) return t; @@ -199,7 +199,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { if(a->base.type) return a->base.type; a->base.tmpl = mk_tmpl(env, t, t->e->def->base.tmpl, type->types); - if(t->e->parent != t_union) { + if(t->e->parent != env->gwion->type[et_union]) { CHECK_BO(scan0_class_def(env, a)) nspc_add_type_front(env->curr, a->base.xid, a->base.type); } else { @@ -220,7 +220,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { } else return scan_tuple(env, type); } else if(type->types) { // TODO: clean me - if(isa(t, t_function) > 0 && t->e->d.func->def->base->tmpl) { + if(isa(t, env->gwion->type[et_function]) > 0 && t->e->d.func->def->base->tmpl) { DECL_OO(const m_str, tl_name, = tl2str(env, type->types)) const Symbol sym = func_symbol(env, t->e->owner->name, t->e->d.func->name, tl_name, 0); free_mstr(env->gwion->mp, tl_name); diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index e0106766..f3bd8df5 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -40,7 +40,7 @@ ANN Type type_decl_resolve(const Env env, const Type_Decl* td) { if(GET_FLAG(td, nonnull)) { if(isa(ret, env->gwion->type[et_void]) > 0) ERR_O(td_pos(td), _("void types can't be nonnull.")) - if(isa(ret, t_object) < 0 && isa(ret, t_function) < 0) + if(isa(ret, env->gwion->type[et_object]) < 0 && isa(ret, env->gwion->type[et_function]) < 0) return ret; return type_nonnull(env, ret); } @@ -79,6 +79,6 @@ ANN static inline void* type_unknown(const Env env, const ID_List id) { ANN Type known_type(const Env env, const Type_Decl* td) { if(!td->xid) - return t_undefined; + return env->gwion->type[et_undefined]; return type_decl_resolve(env, td) ?:type_unknown(env, td->xid); } diff --git a/src/vm/vm.c b/src/vm/vm.c index 4c127ff0..1f05477e 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -807,7 +807,7 @@ pushstaticcode: reg += SZ_INT; DISPATCH() pushstr: - *(M_Object*)reg = new_string2(vm->gwion->mp, shred, (m_str)VAL); + *(M_Object*)reg = new_string2(vm->gwion, shred, (m_str)VAL); reg += SZ_INT; DISPATCH(); gcini: diff --git a/tests/import/array.c b/tests/import/array.c index 2a939954..c17d062a 100644 --- a/tests/import/array.c +++ b/tests/import/array.c @@ -9,12 +9,13 @@ #include "gwion.h" #include "operator.h" #include "import.h" +#include "gwi.h" MFUN(test_mfun){} GWION_IMPORT(array_test) { Type t_invalid_var_name; - CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, t_object))) + CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object]))) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) CHECK_BB(gwi_item_ini(gwi, "int[]", "int_array")) CHECK_BB(gwi_item_end(gwi, 0, NULL)) // import array var diff --git a/tests/import/begin_class.c b/tests/import/begin_class.c index f6831cfe..431bb007 100644 --- a/tests/import/begin_class.c +++ b/tests/import/begin_class.c @@ -9,11 +9,12 @@ #include "gwion.h" #include "operator.h" #include "import.h" +#include "gwi.h" MFUN(test_mfun){} GWION_IMPORT(begin_class) { Type t_invalid_var_name; - CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, t_object))) + CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object]))) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) return GW_OK; diff --git a/tests/import/callback.c b/tests/import/callback.c index 922b571b..5d0323e9 100644 --- a/tests/import/callback.c +++ b/tests/import/callback.c @@ -11,6 +11,7 @@ #include "operator.h" #include "import.h" #include "func.h" +#include "gwi.h" struct ret_info { Instr instr; @@ -72,7 +73,7 @@ GWION_IMPORT(callback) { CHECK_BB(gwi_fptr_ini(gwi, "Vec4", "PtrType")) CHECK_OB(gwi_fptr_end(gwi, 0)) - const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, t_object); + const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, gwi->gwion->type[et_object]); CHECK_BB(gwi_class_ini(gwi, t_callback, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "int", "callback", cb_func)) CHECK_BB(gwi_func_arg(gwi, "PtrType", "func")) diff --git a/tests/import/class_template.c b/tests/import/class_template.c index 09ac6c04..c507b2ef 100644 --- a/tests/import/class_template.c +++ b/tests/import/class_template.c @@ -9,6 +9,7 @@ #include "gwion.h" #include "operator.h" #include "import.h" +#include "gwi.h" static m_int o_map_key; static m_int o_map_value; @@ -29,7 +30,7 @@ GWION_IMPORT(class_template) { Type t_class_template; const m_str list[2] = { "A", "B" }; gwi_tmpl_ini(gwi, 2, list); - CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, t_object))) + CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, gwi->gwion->type[et_object]))) CHECK_BB(gwi_class_ini(gwi, t_class_template, class_template_ctor, NULL)) gwi_tmpl_end(gwi); CHECK_BB(gwi_item_ini(gwi, "A[]", "key")) diff --git a/tests/import/coverage.c b/tests/import/coverage.c index 526d7726..d4f01ed5 100644 --- a/tests/import/coverage.c +++ b/tests/import/coverage.c @@ -20,7 +20,7 @@ SFUN(coverage_vec4) { m_vec4 v = {0,0,0,0}; *(m_vec4*)RETURN = v; } GWION_IMPORT(coverage) { Type t_coverage; - CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, t_object))) + CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, gwi->gwion->type[et_object]))) CHECK_BB(gwi_class_ini(gwi, t_coverage, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "int", "i", coverage_int)) CHECK_BB(gwi_func_end(gwi, ae_flag_static)) diff --git a/tests/import/global_var.c b/tests/import/global_var.c index 79d3834d..2526058f 100644 --- a/tests/import/global_var.c +++ b/tests/import/global_var.c @@ -14,7 +14,7 @@ GWION_IMPORT(global_var_test) { // ALLOC_PTR(i, m_uint, 1); - const M_Object obj = new_object(gwi->gwion->mp, NULL, t_string); + const M_Object obj = new_object(gwi->gwion->mp, NULL, gwi->gwion->type[et_string]); STRING(obj) = s_name(insert_symbol(gwi->gwion->st, "test")); CHECK_BB(gwi_item_ini(gwi,"string", "i")) CHECK_BB(gwi_item_end(gwi, 0, obj)) diff --git a/tests/import/static_string.c b/tests/import/static_string.c index 850906a7..23cd0a6c 100644 --- a/tests/import/static_string.c +++ b/tests/import/static_string.c @@ -13,7 +13,7 @@ #include "gwi.h" GWION_IMPORT(static_string_test) { - const M_Object obj = new_object(gwi->gwion->mp, NULL, t_string); + const M_Object obj = new_object(gwi->gwion->mp, NULL, gwi->gwion->type[et_string]); STRING(obj) = s_name(insert_symbol(gwi->gwion->st, "test static string")); CHECK_BB(gwi_item_ini(gwi, "string", "self")) CHECK_BB(gwi_item_end(gwi, ae_flag_global, obj)) diff --git a/tests/import/variadic.c b/tests/import/variadic.c index 0f25c0f7..8e25c674 100644 --- a/tests/import/variadic.c +++ b/tests/import/variadic.c @@ -10,6 +10,7 @@ #include "operator.h" #include "import.h" #include "vararg.h" +#include "gwi.h" static MFUN(m_test) { printf("%p\n", *(M_Object*)MEM(0)); @@ -39,7 +40,7 @@ static MFUN(m_variadic) { } GWION_IMPORT(variadic test) { - const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, t_object); + const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, gwi->gwion->type[et_object]); CHECK_BB(gwi_class_ini(gwi, t_variadic, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "void", "member", m_variadic)) CHECK_BB(gwi_func_arg(gwi, "string", "format"))