nspc_free_value(a, gwion);
nspc_free_func(a, gwion);
nspc_free_trait(a, gwion);
- if (a->info->op_map.ptr) free_op_map(&a->info->op_map, gwion);
- if (a->info->op_tmpl.ptr) free_op_tmpl(&a->info->op_tmpl, gwion);
+ if(a->operators) {
+ if (a->operators->map.ptr) free_op_map(&a->operators->map, gwion);
+ if (a->operators->tmpl.ptr) free_op_tmpl(&a->operators->tmpl, gwion);
+ mp_free(gwion->mp, NspcOp, a->operators);
+ }
nspc_free_type(a, gwion);
if (a->class_data && a->class_data_size)
mp_free2(gwion->mp, a->class_data_size, a->class_data);
if (a->vtable.ptr) vector_release(&a->vtable);
mp_free(gwion->mp, NspcInfo, a->info);
- if (a->pre_ctor) vmcode_remref(a->pre_ctor, gwion);
if (a->dtor) vmcode_remref(a->dtor, gwion);
mp_free(gwion->mp, Nspc, a);
}
}
ANN void operator_suspend(const Nspc n, struct Op_Import *opi) {
- const m_int idx = map_index(&n->info->op_map, (vtype)opi->op);
- const Vector v = (Vector)&VVAL(&n->info->op_map, idx);
+ const m_int idx = map_index(&n->operators->map, (vtype)opi->op);
+ const Vector v = (Vector)&VVAL(&n->operators->map, idx);
for (m_uint i = vector_size(v) + 1; --i;) {
M_Operator *mo = (M_Operator *)vector_at(v, i - 1);
if (opi->lhs == mo->lhs && opi->rhs == mo->rhs) {
}
ANN static m_bool _op_exist(const struct OpChecker *ock, const Nspc n) {
- const m_int idx = map_index(&n->info->op_map, (vtype)ock->opi->op);
+ const m_int idx = map_index(&n->operators->map, (vtype)ock->opi->op);
if (idx == -1 || !operator_find2((Vector)&VVAL(ock->map, idx), ock->opi->lhs,
ock->opi->rhs))
return GW_OK;
}
ANN static m_bool op_exist(const struct OpChecker *ock, const Nspc n) {
- return n->info->op_map.ptr ? _op_exist(ock, n) : GW_OK;
+ return n->operators->map.ptr ? _op_exist(ock, n) : GW_OK;
}
ANN m_bool add_op(const Gwion gwion, const struct Op_Import *opi) {
Nspc n = gwion->env->curr;
do {
- struct OpChecker ock = {
- .env = gwion->env, .map = &n->info->op_map, .opi = opi};
- CHECK_BB(op_exist(&ock, n));
+ if (n->operators) {
+ struct OpChecker ock = {
+ .env = gwion->env, .map = &n->operators->map, .opi = opi};
+ CHECK_BB(op_exist(&ock, n));
+ }
} while ((n = n->parent));
- if (!gwion->env->curr->info->op_map.ptr)
- map_init(&gwion->env->curr->info->op_map);
+ if (!gwion->env->curr->operators)
+ gwion->env->curr->operators = mp_calloc(gwion->mp, NspcOp);
+ if (!gwion->env->curr->operators->map.ptr)
+ map_init(&gwion->env->curr->operators->map);
struct OpChecker ock = {
- .env = gwion->env, .map = &gwion->env->curr->info->op_map, .opi = opi};
+ .env = gwion->env, .map = &gwion->env->curr->operators->map, .opi = opi};
const Vector v = op_vector(&ock);
const M_Operator *mo = new_mo(gwion->mp, opi);
vector_add(v, (vtype)mo);
ANN static Type op_check_tmpl(const Env env, struct Op_Import *opi) {
Nspc nspc = env->curr;
do {
- if (!nspc->info->op_tmpl.ptr) continue;
- const Vector v = &nspc->info->op_tmpl;
+ if (!nspc->operators || !nspc->operators->tmpl.ptr) continue;
+ const Vector v = &nspc->operators->tmpl;
for (m_uint i = vector_size(v) + 1; --i;) {
const Func_Def fdef = (Func_Def)vector_at(v, i - 1);
if (opi->op != fdef->base->xid) continue;
Nspc nspc = env->curr;
do {
Type l = opi->lhs;
- if (!nspc->info->op_map.ptr) continue;
- const Map map = &nspc->info->op_map;
+ if (!nspc->operators) continue;
+ if (!nspc->operators->map.ptr) continue;
+ const Map map = &nspc->operators->map;
do {
Type r = opi->rhs;
do {
for (int i = 0; i < 2; ++i) {
Nspc nspc = env->curr;
do {
- if (!nspc->info->op_map.ptr) continue;
+ if (!nspc->operators) continue;
+ if (!nspc->operators->map.ptr) continue;
Type l = opi->lhs;
do {
struct Op_Import opi2 = {
.op = opi->op, .lhs = l, .rhs = opi->rhs, .data = opi->data};
struct OpChecker ock = {
- .env = env, .map = &nspc->info->op_map, .opi = &opi2};
+ .env = env, .map = &nspc->operators->map, .opi = &opi2};
const Type ret = op_check_inner(env, &ock, i);
if (ret) {
if (ret == env->gwion->type[et_error]) return NULL;
ANN m_bool operator_set_func(const struct Op_Import *opi) {
const Nspc nspc = ((Func)opi->data)->value_ref->from->owner;
- const m_int idx = map_index(&nspc->info->op_map, (vtype)opi->op);
- const Vector v = (Vector)&VVAL(&nspc->info->op_map, idx);
+ const m_int idx = map_index(&nspc->operators->map, (vtype)opi->op);
+ const Vector v = (Vector)&VVAL(&nspc->operators->map, idx);
DECL_OB(M_Operator *, mo, = operator_find(v, opi->lhs, opi->rhs));
mo->func = (Func)opi->data;
return GW_OK;
for (int i = 0; i < 2; ++i) {
Nspc nspc = emit->env->curr;
do {
- if (!nspc->info->op_map.ptr) continue;
+ if (!nspc->operators) continue;
+ if (!nspc->operators->map.ptr) continue;
Type l = opi->lhs;
do {
Type r = opi->rhs;
do {
- const m_int idx = map_index(&nspc->info->op_map, (vtype)opi->op);
+ const m_int idx = map_index(&nspc->operators->map, (vtype)opi->op);
if (idx == -1) continue;
- const Vector v = (Vector)&VVAL(&nspc->info->op_map, idx);
+ const Vector v = (Vector)&VVAL(&nspc->operators->map, idx);
const M_Operator *mo =
!i ? operator_find2(v, l, r) : operator_find(v, l, r);
if (mo) {
}
#undef CONVERT
-ANN static inline Map ensure_map(const Nspc nspc) {
- const Map map = &nspc->info->op_map;
+ANN static inline Map ensure_map(MemPool mp, const Nspc nspc) {
+ if (!nspc->operators) nspc->operators = mp_calloc(mp, NspcOp);
+ const Map map = &nspc->operators->map;
if (!map->ptr) map_init(map);
return map;
}
const struct Op_Import *opi, const Vector visited) {
if (vector_find(visited, (m_uint)nspc) != -1) return;
vector_add(visited, (m_uint)nspc);
- if (nspc->info->op_map.ptr) {
- const Map map = &nspc->info->op_map;
- const Map base_map = ensure_map(opi->rhs->info->value->from->owner);
+ if (nspc->operators && nspc->operators->map.ptr) {
+ const Map map = &nspc->operators->map;
+ const Map base_map = ensure_map(mp, opi->rhs->info->value->from->owner);
for (m_uint i = 0; i < map_size(map); i++) {
const Vector v = (Vector)&VVAL(map, i);
const m_uint sz = vector_size(v);