From b40b3c0a2405bdcbbd8eb7867b3a44066f70ea58 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 28 Oct 2022 08:58:00 +0200 Subject: [PATCH] :fire: Remove Ptr:[T] --- examples/implicit_ptr.gw | 4 - examples/ptr_assign.gw | 6 - examples/ptr_cast.gw | 2 - examples/ptr_deref.gw | 3 - include/lang_private.h | 1 - src/lib/engine.c | 1 - src/lib/ptr.c | 208 ---------------------------- tests/error/empty_ptr.gw | 3 - tests/error/invalid_pointer_cast.gw | 2 - tests/error/ptr_assign_const.gw | 1 - tests/error/ptr_assign_invalid.gw | 7 - tests/error/ptr_from_const.gw | 1 - tests/error/ptr_implicit_const.gw | 3 - tests/new/typedef_func_tmpl_tmpl.gw | 2 - 14 files changed, 244 deletions(-) delete mode 100644 examples/implicit_ptr.gw delete mode 100644 examples/ptr_assign.gw delete mode 100644 examples/ptr_cast.gw delete mode 100644 examples/ptr_deref.gw delete mode 100644 src/lib/ptr.c delete mode 100644 tests/error/empty_ptr.gw delete mode 100644 tests/error/invalid_pointer_cast.gw delete mode 100644 tests/error/ptr_assign_const.gw delete mode 100644 tests/error/ptr_assign_invalid.gw delete mode 100644 tests/error/ptr_from_const.gw delete mode 100644 tests/error/ptr_implicit_const.gw delete mode 100644 tests/new/typedef_func_tmpl_tmpl.gw diff --git a/examples/implicit_ptr.gw b/examples/implicit_ptr.gw deleted file mode 100644 index 58b94db1..00000000 --- a/examples/implicit_ptr.gw +++ /dev/null @@ -1,4 +0,0 @@ -fun void test(Ptr:[int] p) { - <<< *p >>>; -} -var int i => test; diff --git a/examples/ptr_assign.gw b/examples/ptr_assign.gw deleted file mode 100644 index ba71a88b..00000000 --- a/examples/ptr_assign.gw +++ /dev/null @@ -1,6 +0,0 @@ -class C { -} -class D extends C { -} -var D d; -d :=> var Ptr:[C] pd; diff --git a/examples/ptr_cast.gw b/examples/ptr_cast.gw deleted file mode 100644 index 4043e527..00000000 --- a/examples/ptr_cast.gw +++ /dev/null @@ -1,2 +0,0 @@ -12 :=> var int i; -<<>>; diff --git a/examples/ptr_deref.gw b/examples/ptr_deref.gw deleted file mode 100644 index 495280bb..00000000 --- a/examples/ptr_deref.gw +++ /dev/null @@ -1,3 +0,0 @@ -var int i; -i :=> var Ptr:[int] pti; -<<<12 => *pti, " ", *pti>>>; diff --git a/include/lang_private.h b/include/lang_private.h index 4e8441d7..cf949958 100644 --- a/include/lang_private.h +++ b/include/lang_private.h @@ -9,7 +9,6 @@ ANN m_bool import_shred(const Gwi gwi); ANN m_bool import_event(const Gwi gwi); ANN m_bool import_ugen(const Gwi gwi); ANN m_bool import_array(const Gwi gwi); -ANN m_bool import_ptr(const Gwi gwi); ANN m_bool import_xork(const Gwi gwi); ANN m_bool import_modules(const Gwi gwi); ANN m_bool import_object_op(const Gwi gwi); diff --git a/src/lib/engine.c b/src/lib/engine.c index 69ed96e0..13b23894 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -119,7 +119,6 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(import_array(gwi)) GWI_BB(import_event(gwi)) GWI_BB(import_ugen(gwi)) - GWI_BB(import_ptr(gwi)) GWI_BB(import_xork(gwi)) GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_new)) diff --git a/src/lib/ptr.c b/src/lib/ptr.c deleted file mode 100644 index 1274b3bf..00000000 --- a/src/lib/ptr.c +++ /dev/null @@ -1,208 +0,0 @@ -#include -#include -#include "gwion_util.h" -#include "gwion_ast.h" -#include "gwion_env.h" -#include "vm.h" -#include "gwion.h" -#include "instr.h" -#include "object.h" -#include "operator.h" -#include "import.h" -#include "emit.h" -#include "traverse.h" -#include "parse.h" -#include "gack.h" -#include "gwi.h" - -static m_bool ptr_access(const Env env, const Exp e) { - const m_str access = exp_access(e); - if (!access) return GW_OK; - ERR_B(e->pos, _("operand is %s"), access); -} - -ANN static inline Type ptr_base(const Type t) { - return (Type)vector_front(&t->info->tuple->types); -} - -static OP_CHECK(opck_ptr_assign) { - const Exp_Binary *bin = (Exp_Binary *)data; - CHECK_BN(ptr_access(env, bin->lhs)); - CHECK_BN(ptr_access(env, bin->rhs)); - exp_setvar(bin->lhs, 1); - exp_setvar(bin->rhs, 1); - Type t = bin->lhs->type; - do { - Type u = bin->rhs->type; - do { - const Type base = ptr_base(u); - if (isa(t, base) > 0) return bin->rhs->type; - } while ((u = u->info->parent) && u->info->cdef->base.tmpl->call); - } while ((t = t->info->parent)); - ERR_N(exp_self(bin)->pos, "can't assign to pointer"); -} - -static OP_EMIT(opem_ptr_assign) { - const Exp_Binary *bin = (Exp_Binary *)data; - const Type t = bin->lhs->cast_to ?: bin->lhs->type; - if (isa(t, emit->gwion->type[et_compound]) > 0) - (void)emit_compound_addref(emit, t, -(SZ_INT + t->size), 0); - emit_add_instr(emit, int_r_assign); - return GW_OK; -} - -static OP_CHECK(opck_ptr_deref) { - const Exp_Unary *unary = (Exp_Unary *)data; - return ptr_base(unary->exp->type); -} - -static OP_CHECK(opck_ptr_cast) { - const Exp_Cast *cast = (Exp_Cast *)data; - if (!cast->td->types || !cast->td->types->len) - ERR_N(exp_self(cast)->pos, "'Ptr' needs types to cast"); - DECL_ON(const Type, t, = known_type(env, cast->td)); - if (t->info->cdef && !tflag(t, tflag_check)) - CHECK_BN(ensure_traverse(env, t)); - const Type to = known_type(env, *mp_vector_at(cast->td->types, Type_Decl*, 0)); - exp_setvar(cast->exp, 1); - if (isa(cast->exp->type, to) > 0) return t; - ERR_N(exp_self(cast)->pos, "invalid pointer cast"); -} - -static OP_CHECK(opck_ptr_implicit) { - const struct Implicit *imp = (struct Implicit *)data; - const Exp e = imp->e; - const Type base = ptr_base(imp->t); - if (isa(e->type, base) > 0) { - const m_str access = exp_access(e); - if (access) ERR_N(e->pos, _("can't cast %s value to Ptr"), access); - exp_setvar(e, 1); - return imp->t; - } - return NULL; -} - -static INSTR(instr_ptr_deref) { - const m_bit *o = *(m_bit **)REG(-SZ_INT); - if (!o) { - handle(shred, _("EmptyPointerException")); - return; - } - if (instr->m_val2) - memcpy(REG(-SZ_INT), &o, SZ_INT); - else { - shred->reg -= SZ_INT - instr->m_val; - memcpy(REG(-instr->m_val), o, instr->m_val); - } -} - -static INSTR(Cast2Ptr) { - m_bit *o = *(m_bit **)REG(-SZ_INT); - *(m_bit **)REG(-SZ_INT) = o; -} - -static OP_EMIT(opem_ptr_cast) { - const Exp_Cast *cast = (Exp_Cast *)data; - const Instr instr = emit_add_instr(emit, Cast2Ptr); - instr->m_val = (m_uint)exp_self(cast)->type; - return GW_OK; -} - -static OP_EMIT(opem_ptr_implicit) { - const struct Implicit *imp = (struct Implicit *)data; - const Instr instr = emit_add_instr(emit, Cast2Ptr); - instr->m_val = (m_uint)imp->t; - return GW_OK; -} - -static OP_EMIT(opem_ptr_deref) { - const Exp_Unary *unary = (Exp_Unary *)data; - const Instr instr = emit_add_instr(emit, instr_ptr_deref); - instr->m_val = exp_self(unary)->type->size; - instr->m_val2 = exp_getvar(exp_self(unary)); - return GW_OK; -} - -ANN Type scan_class(const Env env, const Type t, const Type_Decl *td); - -static DTOR(ptr_object_dtor) { release(**(M_Object **)o, shred); } - -static DTOR(ptr_struct_dtor) { - const Type base = *(Type *)(shred->mem + SZ_INT); - const m_uint scope = env_push(shred->info->vm->gwion->env, - base->info->value->from->owner_class, - base->info->value->from->owner); - const Type t = known_type(shred->info->vm->gwion->env, - *mp_vector_at(base->info->cdef->base.tmpl->call, Type_Decl*, 0)); - env_pop(shred->info->vm->gwion->env, scope); - struct_release(shred, t, *(m_bit **)o); -} -#include "tmpl_info.h" -static OP_CHECK(opck_ptr_scan) { - struct TemplateScan *ts = (struct TemplateScan *)data; - struct tmpl_info info = { - .base = ts->t, .td = ts->td, .list = ts->t->info->cdef->base.tmpl->list}; - const Type exists = tmpl_exists(env, &info); - if (exists) return exists != env->gwion->type[et_error] ? exists : NULL; - const Type base = known_type(env, *mp_vector_at(ts->td->types, Type_Decl*, 0)); - const Type t = new_type(env->gwion->mp, s_name(info.name), base); - t->size = SZ_INT; - t->info->parent = env->gwion->type[et_ptr]; - SET_FLAG(t, abstract | ae_flag_final); - t->info->tuple = new_tupleform(env->gwion->mp, NULL); - t->nspc = new_nspc(env->gwion->mp, t->name); - vector_add(&t->info->tuple->types, (m_uint)base); - const m_uint scope = env_push(env, base->info->value->from->owner_class, - base->info->value->from->owner); - mk_class(env, t, (loc_t) {}); - env_pop(env, scope); - nspc_add_type_front(t->info->value->from->owner, info.name, t); - if (isa(base, env->gwion->type[et_compound]) > 0) { - t->nspc->dtor = - new_vmcode(env->gwion->mp, NULL, NULL, "@PtrDtor", SZ_INT, true, false); - if (!tflag(base, tflag_struct)) - t->nspc->dtor->native_func = (m_uint)ptr_object_dtor; - else - t->nspc->dtor->native_func = (m_uint)ptr_struct_dtor; - set_tflag(t, tflag_dtor); - } - return t; -} - -static OP_CHECK(opck_ptr_ref) { - const Exp_Binary *bin = (Exp_Binary *)data; - exp_setvar(bin->rhs, 1); - return bin->rhs->type; -} - -static GACK(gack_ptr) { INTERP_PRINTF("%p", *(m_str *)VALUE); } - -GWION_IMPORT(ptr) { - const Type t_ptr = gwi_struct_ini(gwi, "Ptr:[A]"); - gwi->gwion->type[et_ptr] = t_ptr; - GWI_BB(gwi_gack(gwi, t_ptr, gack_ptr)) - t_ptr->nspc->offset += SZ_INT; - GWI_BB(gwi_class_end(gwi)) - GWI_BB(gwi_oper_ini(gwi, "Ptr", NULL, NULL)) - GWI_BB(gwi_oper_add(gwi, opck_ptr_scan)) - GWI_BB(gwi_oper_end(gwi, "class", NULL)) - GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Ptr", NULL)) - GWI_BB(gwi_oper_add(gwi, opck_ptr_assign)) - GWI_BB(gwi_oper_emi(gwi, opem_ptr_assign)) - GWI_BB(gwi_oper_end(gwi, ":=>", NULL)) - GWI_BB(gwi_oper_add(gwi, opck_ptr_implicit)) - GWI_BB(gwi_oper_emi(gwi, opem_ptr_implicit)) - GWI_BB(gwi_oper_end(gwi, "@implicit", Cast2Ptr)) - GWI_BB(gwi_oper_add(gwi, opck_ptr_cast)) - GWI_BB(gwi_oper_emi(gwi, opem_ptr_cast)) - GWI_BB(gwi_oper_end(gwi, "$", Cast2Ptr)) - GWI_BB(gwi_oper_ini(gwi, NULL, "Ptr", NULL)) - GWI_BB(gwi_oper_add(gwi, opck_ptr_deref)) - GWI_BB(gwi_oper_emi(gwi, opem_ptr_deref)) - GWI_BB(gwi_oper_end(gwi, "*", instr_ptr_deref)) - GWI_BB(gwi_oper_ini(gwi, "Ptr", "Ptr", "Ptr")) - GWI_BB(gwi_oper_add(gwi, opck_ptr_ref)) - // GWI_BB(gwi_oper_emi(gwi, opem_ptr_ref)) - GWI_BB(gwi_oper_end(gwi, "::=>", int_r_assign)) - return GW_OK; -} diff --git a/tests/error/empty_ptr.gw b/tests/error/empty_ptr.gw deleted file mode 100644 index 9abb39ba..00000000 --- a/tests/error/empty_ptr.gw +++ /dev/null @@ -1,3 +0,0 @@ -#! [contains] EmptyPointerException -var Ptr:[int] t; -<<< *t >>>; diff --git a/tests/error/invalid_pointer_cast.gw b/tests/error/invalid_pointer_cast.gw deleted file mode 100644 index 393b1519..00000000 --- a/tests/error/invalid_pointer_cast.gw +++ /dev/null @@ -1,2 +0,0 @@ -#! [contains] invalid pointer cast -<<< 1 $ Ptr:[Object] >>>; diff --git a/tests/error/ptr_assign_const.gw b/tests/error/ptr_assign_const.gw deleted file mode 100644 index 52f7effe..00000000 --- a/tests/error/ptr_assign_const.gw +++ /dev/null @@ -1 +0,0 @@ -1 :=> var Ptr:[int] pd; diff --git a/tests/error/ptr_assign_invalid.gw b/tests/error/ptr_assign_invalid.gw deleted file mode 100644 index 0ac8fb4c..00000000 --- a/tests/error/ptr_assign_invalid.gw +++ /dev/null @@ -1,7 +0,0 @@ -#! [contains] can't assign to pointer -class C {} - -class D extends C {} - -var D d; -d :=> var Ptr:[int] pd; diff --git a/tests/error/ptr_from_const.gw b/tests/error/ptr_from_const.gw deleted file mode 100644 index 600b5b00..00000000 --- a/tests/error/ptr_from_const.gw +++ /dev/null @@ -1 +0,0 @@ -1 :=> var Ptr:[int] i; diff --git a/tests/error/ptr_implicit_const.gw b/tests/error/ptr_implicit_const.gw deleted file mode 100644 index aa172bb2..00000000 --- a/tests/error/ptr_implicit_const.gw +++ /dev/null @@ -1,3 +0,0 @@ -#! [contains] can't cast non-mutable value to Ptr -fun void test(Ptr:[int] i) { <<< *i>>>; } -1 => test; diff --git a/tests/new/typedef_func_tmpl_tmpl.gw b/tests/new/typedef_func_tmpl_tmpl.gw deleted file mode 100644 index 767be6d7..00000000 --- a/tests/new/typedef_func_tmpl_tmpl.gw +++ /dev/null @@ -1,2 +0,0 @@ -funptr void ptr_t:[A](myPtr ptr); -var ptr_t:[ Ptr:[A] ] t; -- 2.43.0