vector_release(&a->conts);
const Vector v = &a->effects;
for (m_uint i = 0; i < vector_size(v); i++) {
- m_uint _v = vector_at(v, i);
- if (_v) m_vector_release((M_Vector)&_v);
+ MP_Vector *eff = (MP_Vector*)vector_at(v, i);
+ if (eff) free_mp_vector(gwion->mp, sizeof(struct ScopeEffect), eff);
}
vector_release(&a->effects);
mp_free(gwion->mp, Env_Scope, a);
ANN void env_add_effect(const Env a, const Symbol effect, const loc_t pos) {
const Vector v = &a->scope->effects;
- const M_Vector w = (M_Vector)&VPTR(v, VLEN(v) - 1);
- if (!w->ptr) m_vector_init(w, sizeof(struct ScopeEffect), 0);
+ MP_Vector *w = (MP_Vector*)vector_back(v);
+ if (!w) {
+ w = new_mp_vector(a->gwion->mp, sizeof(struct ScopeEffect), 0);
+ VPTR(v, VLEN(v) - 1) = (vtype)w;
+ }
struct ScopeEffect eff = {effect, pos};
- m_vector_add(w, &eff);
+// mp_vector_add(a->gwion->mp, &w, struct ScopeEffect, eff);
+ mp_vector_add(a->gwion->mp, (MP_Vector**)&(VPTR(v, VLEN(v) - 1)) , struct ScopeEffect, eff);
}
ANN void free_env(const Env a) {
ANN void env_pop(const Env env, const m_uint scope) {
env->class_def = (Type)vector_pop(&env->scope->class_stack);
env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
- const m_uint _v = vector_pop(&env->scope->effects);
- if (_v) m_vector_release((M_Vector)&_v);
+ MP_Vector *const v = (MP_Vector*)vector_pop(&env->scope->effects);
+ if (v) free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), v);
env->scope->depth = scope;
}
}
#include "tmp_resolve.h"
+
static OP_CHECK(opck_op_impl) {
struct Implicit *impl = (struct Implicit *)data;
const Func func = impl->t->info->func;
vector_add(&env->scope->effects, 0);
DECL_ON(const Type, t, = op_check(env, &opi));
CHECK_BN(isa(t, func->def->base->ret_type)); // error message?
- const m_uint _eff = vector_back(&env->scope->effects);
- if (!check_effect_overload((Vector)&_eff, func))
- ERR_N(impl->pos, _("`{+Y}%s{0}` has effects not present in `{+G}%s{0}`\n"),
- s_name(impl->e->d.prim.d.var), func->name);
+ MP_Vector *const eff = (MP_Vector*)vector_back(&env->scope->effects);
+// if (eff && !check_effect_overload(eff, func))
+// ERR_N(impl->pos, _("`{+Y}%s{0}` has effects not present in `{+G}%s{0}`\n"),
+// s_name(impl->e->d.prim.d.var), func->name);
Value v = nspc_lookup_value0(opi.nspc, impl->e->d.prim.d.var);
if (v) {
const m_uint scope = env_push(env, NULL, opi.nspc);
const Func exists = (Func)find_func_match(env, v->d.func_ref, &call);
env_pop(env, scope);
if (exists) { // improve me
- if (_eff) {
- const M_Vector eff = (M_Vector)&_eff;
- m_vector_release(eff);
+ if (eff) {
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), eff);
ERR_N(impl->pos,
_("`{+Y}%s{0}` has effects not present in `{+G}%s{0}`\n"),
s_name(impl->e->d.prim.d.var), func->name);
Func_Base *base =
new_func_base(env->gwion->mp, type2td(env->gwion, t, impl->e->pos),
impl->e->d.prim.d.var, args, ae_flag_none, impl->e->pos);
- if (_eff) {
- const M_Vector eff = (M_Vector)&_eff;
- for (m_uint i = 0; i < m_vector_size(eff); i++) {
- struct ScopeEffect effect;
- m_vector_get(eff, i, &effect);
- vector_add(&base->effects, (m_uint)effect.sym);
+ if (eff) {
+ for (m_uint i = 0; i < eff->len; i++) {
+ struct ScopeEffect *effect = mp_vector_at(eff, struct ScopeEffect, i);
+ vector_add(&base->effects, (m_uint)effect->sym);
}
- m_vector_release(eff);
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), eff);
}
const Exp lhs =
new_prim_id(env->gwion->mp, larg0->var_decl.xid, impl->e->pos);
CHECK_BB(check_handler_list(env, stmt->handler));
vector_add(&env->scope->effects, 0);
const m_bool ret = check_stmt_try_start(env, stmt);
- const m_uint _v = vector_pop(&env->scope->effects);
- if (_v) {
- const M_Vector v = (M_Vector)&_v;
- for (m_uint i = 0; i < m_vector_size(v); i++) {
- struct ScopeEffect eff;
- m_vector_get(v, i, &eff);
- bool found = find_handler(stmt->handler, eff.sym);
- if (!found) env_add_effect(env, eff.sym, eff.pos);
+ MP_Vector *const v = (MP_Vector*)vector_pop(&env->scope->effects);
+ if (v) {
+ for (m_uint i = 0; i < v->len; i++) {
+ struct ScopeEffect *eff = mp_vector_at(v, struct ScopeEffect, i);
+ bool found = find_handler(stmt->handler, eff->sym);
+ if (!found) env_add_effect(env, eff->sym, eff->pos);
}
- m_vector_release(v);
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), v);
}
return ret;
}
return GW_OK;
}
-ANN bool check_effect_overload(const Vector base, const Func override) {
+ANN static bool check_effect_overload(const Vector base, const Func override) {
if (!base->ptr) return true;
- if (!override->def->base->effects.ptr) return false; // TODO: error message
+ if (!override->def->base->effects.ptr) return false;
const Vector v = &override->def->base->effects;
for (m_uint i = 0; i < vector_size(v); i++) {
- if (vector_find((Vector)base, vector_at(v, i)) == -1) return false;
+ if (vector_find(base, vector_at(v, i)) == -1) return false;
}
return true;
}
return GW_OK;
}
-ANN static bool effect_find(const M_Vector v, const Symbol sym) {
- for(m_uint i = 0; i < m_vector_size(v); i++) {
- struct ScopeEffect *eff = (struct ScopeEffect *)(ARRAY_PTR(v) + ARRAY_SIZE(v) * i);
+ANN static bool effect_find(const MP_Vector *v, const Symbol sym) {
+ for(m_uint i = 0; i < v->len; i++) {
+ struct ScopeEffect *eff = mp_vector_at(v, struct ScopeEffect, i);
if(eff->sym == sym) return true;
}
return false;
}
vector_add(&env->scope->effects, 0);
const m_bool ret = scanx_fdef(env, env, fdef, (_exp_func)check_fdef);
- const m_uint _v = vector_back(&env->scope->effects);
- if (_v) {
+ MP_Vector *v = (MP_Vector*)vector_back(&env->scope->effects);
+ if (v) {
if (fdef->base->xid == insert_symbol("@dtor"))
ERR_B(fdef->base->pos, _("can't use effects in destructors"));
- const M_Vector v = (M_Vector)&_v;
const Vector base = &fdef->base->effects;
if (!base->ptr) vector_init(base);
- for (m_uint i = 0; i < m_vector_size(v); i++) {
- struct ScopeEffect *eff = (struct ScopeEffect *)(ARRAY_PTR(v) + ARRAY_SIZE(v) * i);
+ for (uint32_t i = 0; i < v->len; i++) {
+ struct ScopeEffect *eff = mp_vector_at(v, struct ScopeEffect, i);
+//(struct ScopeEffect *)(ARRAY_PTR(v) + ARRAY_SIZE(v) * i);
if(!effect_find(v, eff->sym))
vector_add(base, (m_uint)eff->sym);
}
- m_vector_release(v);
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), v);
}
vector_pop(&env->scope->effects);
if (fbflag(fdef->base, fbflag_op)) operator_resume(&opi);
ANN static inline void ctor_effects(const Env env) {
const Vector v = &env->scope->effects;
- const m_uint _w = vector_back(v);
- if (!_w) return;
+ MP_Vector *const w = (MP_Vector*)vector_back(v);
+ if (!w) return;
vector_init(&env->class_def->effects);
- const M_Vector w = (M_Vector)&_w;
- for (m_uint j = 0; j < m_vector_size(w); j++) {
- struct ScopeEffect eff;
- m_vector_get(w, j, &eff);
- vector_add(&env->class_def->effects, (m_uint)eff.sym);
+ for (uint32_t j = 0; j < w->len; j++) {
+ struct ScopeEffect *eff = mp_vector_at(w, struct ScopeEffect, j);
+ vector_add(&env->class_def->effects, (m_uint)eff->sym);
}
- m_vector_release(w);
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), w);
vector_pop(v);
}
ANN static inline void check_unhandled(const Env env) {
const Vector v = &env->scope->effects;
- const m_uint _w = vector_back(v);
- if (!_w) return;
- const M_Vector w = (M_Vector)&_w;
- for (m_uint j = 0; j < m_vector_size(w); j++) {
- struct ScopeEffect eff;
- m_vector_get(w, j, &eff);
- if(s_name(eff.sym)[0] == '!')
+ MP_Vector *const w = (MP_Vector*)vector_back(v);
+ if(!w) return;
+ for (m_uint j = 0; j < w->len; j++) {
+ struct ScopeEffect *eff = mp_vector_at(w, struct ScopeEffect, j);
+ if(s_name(eff->sym)[0] == '!')
continue;
- gwerr_secondary("Unhandled effect", env->name, eff.pos);
+ gwerr_secondary("Unhandled effect", env->name, eff->pos);
env->context->error = false;
}
- m_vector_release(w);
+ free_mp_vector(env->gwion->mp, sizeof(struct ScopeEffect), w);
vector_pop(v);
}