#ifndef __NSPC
#define __NSPC
-struct Nspc_ {
- m_str name;
- Nspc parent;
- struct VM_Code_* pre_ctor;
- struct VM_Code_* dtor;
+struct NspcInfo_ {
m_bit* class_data;
struct Vector_ vtable;
struct Map_ op_map;
struct Scope_ func;
size_t offset;
size_t class_data_size;
+};
+
+struct Nspc_ {
+ m_str name;
+ Nspc parent;
+ struct VM_Code_* pre_ctor;
+ struct VM_Code_* dtor;
+ struct NspcInfo_* info;
HAS_OBJ
};
#define describe_lookup0(A, b) \
static inline ANN A nspc_lookup_##b##0(const Nspc n, const Symbol s){ \
- return (A)scope_lookup0(&n->b, (vtype)s); \
+ return (A)scope_lookup0(&n->info->b, (vtype)s); \
}
#define describe_lookup1(A, b) \
static inline ANN A nspc_lookup_##b##1(const Nspc n, const Symbol s) { \
- const A a = (A)scope_lookup1(&n->b, (vtype)s); \
+ const A a = (A)scope_lookup1(&n->info->b, (vtype)s); \
if(!a && n->parent) \
return nspc_lookup_##b##1(n->parent, s); \
return a; \
#define describe_nspc_func(A, b) \
static inline ANN void nspc_add_##b(const Nspc n, const Symbol s, const A a) { \
- scope_add(&n->b, (vtype)s, (vtype)a); \
+ scope_add(&n->info->b, (vtype)s, (vtype)a); \
} \
-ANN static inline void nspc_push_##b(const Nspc n) { scope_push(&n->b); } \
-ANN inline static void nspc_pop_##b (const Nspc n) { scope_pop (&n->b); } \
+ANN static inline void nspc_push_##b(const Nspc n) { scope_push(&n->info->b); }\
+ANN inline static void nspc_pop_##b (const Nspc n) { scope_pop (&n->info->b); }\
describe_lookups(A, b)
describe_nspc_func(Value, value)
ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const uint emit_var) { GWDEBUG_EXE
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, emit_var, dotstatic);
- instr->m_val = (m_uint)(v->owner_class->nspc->class_data + v->offset);
+ instr->m_val = (m_uint)(v->owner_class->nspc->info->class_data + v->offset);
instr->m_val2 = size;
return GW_OK;
}
ANN m_bool value_value(const Value v, m_int *value) {
if((!GET_FLAG(v, builtin) && !GET_FLAG(v, enum)) || GET_FLAG(v, member))
return 0;
- *value = v->d.ptr ? *(m_int*)v->d.ptr : v->owner->class_data[v->offset];
+ *value = v->d.ptr ? *(m_int*)v->d.ptr : v->owner->info->class_data[v->offset];
return GW_OK;
}
v->offset = emit_local(emit, SZ_INT, 0);
v->d.ptr = addr;
} else
- *(m_uint*)(emit->env->class_def->nspc->class_data + v->offset) = i;
+ *(m_uint*)(emit->env->class_def->nspc->info->class_data + v->offset) = i;
}
return GW_OK;
}
m_uint scope = emit->env->scope->depth;
const m_bool global = GET_FLAG(stmt, global);
if(stmt->xid) {
- if(stmt->value->type->nspc->class_data_size && !stmt->value->type->nspc->class_data)
- stmt->value->type->nspc->class_data =
- (m_bit*)xcalloc(1, stmt->value->type->nspc->class_data_size);
- stmt->value->type->nspc->offset = stmt->s;
+ if(stmt->value->type->nspc->info->class_data_size &&
+ !stmt->value->type->nspc->info->class_data)
+ stmt->value->type->nspc->info->class_data =
+ (m_bit*)xcalloc(1, stmt->value->type->nspc->info->class_data_size);
+ stmt->value->type->nspc->info->offset = stmt->s;
if(!stmt->value->type->p)
stmt->value->type->p = mp_ini((uint32_t)stmt->value->type->size);
Type_Decl *type_decl = new_type_decl(new_id_list(stmt->xid, stmt->self->pos),
}
scope = emit_push_type(emit, stmt->value->type);
} else if(stmt->type_xid) {
- if(stmt->type->nspc->class_data_size && !stmt->type->nspc->class_data)
- stmt->type->nspc->class_data =
- (m_bit*)xcalloc(1, stmt->type->nspc->class_data_size);
- stmt->type->nspc->offset = stmt->s;
+ if(stmt->type->nspc->info->class_data_size &&
+ !stmt->type->nspc->info->class_data)
+ stmt->type->nspc->info->class_data =
+ (m_bit*)xcalloc(1, stmt->type->nspc->info->class_data_size);
+ stmt->type->nspc->info->offset = stmt->s;
if(!stmt->type->p)
stmt->type->p = mp_ini((uint32_t)stmt->type->size);
scope = emit_push_type(emit, stmt->type);
if(!base->nspc->pre_ctor)
CHECK_BB(emit_class_def(emit, base->def))
}
- if(nspc->class_data_size)
- nspc->class_data = (m_bit*)xcalloc(1, nspc->class_data_size);
+ if(nspc->info->class_data_size)
+ nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size);
emit_class_push(emit, type);
emit_class_code(emit, type->name);
if(class_def->ext && class_def->ext->array)
if(dtor)
mk_xtor(type, (m_uint)dtor, ae_flag_dtor);
if(type->parent) {
- type->nspc->offset = type->parent->nspc->offset;
- if(type->parent->nspc->vtable.ptr)
- vector_copy2(&type->parent->nspc->vtable, &type->nspc->vtable);
+ type->nspc->info->offset = type->parent->nspc->info->offset;
+ if(type->parent->nspc->info->vtable.ptr)
+ vector_copy2(&type->parent->nspc->info->vtable, &type->nspc->info->vtable);
}
type->owner = env->curr;
SET_FLAG(type, checked);
if(td->array)
SET_FLAG(gwi->env->class_def, typedef);
gwi->env->class_def->parent = t;
- gwi->env->class_def->nspc->offset = t->nspc->offset;
- if(t->nspc->vtable.ptr)
- vector_copy2(&t->nspc->vtable, &gwi->env->class_def->nspc->vtable);
+ gwi->env->class_def->nspc->info->offset = t->nspc->info->offset;
+ if(t->nspc->info->vtable.ptr)
+ vector_copy2(&t->nspc->info->vtable, &gwi->env->class_def->nspc->info->vtable);
CHECK_OB((gwi->emit->code = emit_class_code(gwi->emit,
gwi->env->class_def->name)))
if(td->array)
if(!env->class_def)
ERR_B(0, "import: too many class_end called.")
const Nspc nspc = env->class_def->nspc;
- if(nspc->class_data_size && !nspc->class_data)
- nspc->class_data = (m_bit*)xcalloc(1, nspc->class_data_size);
+ if(nspc->info->class_data_size && !nspc->info->class_data)
+ nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size);
env_pop(env, 0);
return GW_OK;
}
ANN m_int gwi_class_end(const Gwi gwi) {
if(!gwi->env->class_def)return GW_ERROR;
const Type t = gwi->env->class_def;
- if(t->nspc && t->nspc->offset)
- t->p = mp_ini((uint32_t)t->nspc->offset);
+ if(t->nspc && t->nspc->info->offset)
+ t->p = mp_ini((uint32_t)t->nspc->info->offset);
return import_class_end(gwi->env);
}
CHECK_BB(traverse_stmt_union(gwi->env, &stmt->d.stmt_union))
emit_union_offset(stmt->d.stmt_union.l, stmt->d.stmt_union.o);
if(GET_FLAG((&stmt->d.stmt_union), member))
- gwi->env->class_def->nspc->offset =
+ gwi->env->class_def->nspc->info->offset =
stmt->d.stmt_union.o + stmt->d.stmt_union.s;
free_stmt(stmt);
gwi->union_data.list = NULL;
const M_Object a = mp_alloc(M_Object);
a->ref = 1;
a->type_ref = t;
- a->vtable = &t->nspc->vtable;
- if(t->nspc->offset) {
+ a->vtable = &t->nspc->info->vtable;
+ if(t->nspc->info->offset) {
Type type = t;
while(!type->p)
type = type->parent;
ANN void __release(const M_Object obj, const VM_Shred shred) {
Type t = obj->type_ref;
while(t->parent) {
- struct scope_iter iter = { &t->nspc->value, 0, 0 };\
+ struct scope_iter iter = { &t->nspc->info->value, 0, 0 };\
Value v;
while(scope_iter(&iter, &v) > 0) {
if(!GET_FLAG(v, static) && isa(v->type, t_object) > 0)
ANN m_bool env_add_op(const Env env, const struct Op_Import* opi) {
const Nspc nspc = env->curr;
- if(!nspc->op_map.ptr)
- map_init(&nspc->op_map);
+ if(!nspc->info->op_map.ptr)
+ map_init(&nspc->info->op_map);
return add_op(nspc, opi);
}
#include "gwion.h"
ANN void nspc_commit(const Nspc nspc) {
- scope_commit(&nspc->value);
- scope_commit(&nspc->func);
- scope_commit(&nspc->type);
+ scope_commit(&nspc->info->value);
+ scope_commit(&nspc->info->func);
+ scope_commit(&nspc->info->type);
}
ANN static void nspc_release_object(const Nspc a, Value value) {
- if(value->d.ptr || (GET_FLAG(value, static) && a->class_data) ||
+ if(value->d.ptr || (GET_FLAG(value, static) && a->info->class_data) ||
(value->d.ptr && GET_FLAG(value, builtin))) {
const VM_Code code = new_vm_code(NULL, 0, ae_flag_builtin, "in code dtor");
const VM_Shred s = new_vm_shred(code);
const M_Object obj = value->d.ptr ? (M_Object)value->d.ptr :
- *(M_Object*)(a->class_data + value->offset);
+ *(M_Object*)(a->info->class_data + value->offset);
s->info->vm = value->gwion->vm;
release(obj, s);
free_vm_shred(s);
}
ANN static void free_nspc_value(const Nspc a) {
- struct scope_iter iter = { &a->value, 0, 0 };
+ struct scope_iter iter = { &a->info->value, 0, 0 };
Value v;
while(scope_iter(&iter, &v) > 0) {
if(isa(v->type, t_object) > 0 ||
}
REM_REF(v);
}
- scope_release(&a->value);
+ scope_release(&a->info->value);
}
#define describe_nspc_free(A, b) \
ANN static void nspc_free_##b(Nspc n) {\
- struct scope_iter iter = { &n->b, 0, 0 };\
+ struct scope_iter iter = { &n->info->b, 0, 0 };\
A a;\
while(scope_iter(&iter, &a) > 0) \
REM_REF(a);\
- scope_release(&n->b);\
+ scope_release(&n->info->b);\
}
describe_nspc_free(Func, func)
nspc_free_type(a);
free_nspc_value(a);
- if(a->class_data)
- free(a->class_data);
- if(a->vtable.ptr)
- vector_release(&a->vtable);
+ if(a->info->class_data)
+ free(a->info->class_data);
+ if(a->info->vtable.ptr)
+ vector_release(&a->info->vtable);
+ if(a->info->op_map.ptr)
+ free_op_map(&a->info->op_map);
+ mp_free(NspcInfo, a->info);
if(a->pre_ctor)
REM_REF(a->pre_ctor);
if(a->dtor)
REM_REF(a->dtor);
- if(a->op_map.ptr)
- free_op_map(&a->op_map);
mp_free(Nspc, a);
}
ANN Nspc new_nspc(const m_str name) {
const Nspc a = mp_alloc(Nspc);
a->name = name;
- scope_init(&a->value);
- scope_init(&a->type);
- scope_init(&a->func);
+ a->info = mp_alloc(NspcInfo);
+ scope_init(&a->info->value);
+ scope_init(&a->info->type);
+ scope_init(&a->info->func);
INIT_OO(a, free_nspc);
return a;
}
#define describe_check_decl(a, b) \
ANN static inline void decl_##a(const Nspc nspc, const Value v) { \
SET_FLAG(v, a); \
- v->offset = nspc->b; \
- nspc->b += v->type->size; \
+ v->offset = nspc->info->b; \
+ nspc->info->b += v->type->size; \
}
describe_check_decl(member, offset)
describe_check_decl(static, class_data_size)
}
} else if(env->class_def) {
if(!GET_FLAG(stmt, static))
- stmt->o = env->class_def->nspc->offset;
+ stmt->o = env->class_def->nspc->info->offset;
else
decl_static(env->curr, stmt->value);
}
CHECK_BB(check_signature_match(f, parent_func))
if(!f->tmpl) {
f->func->vt_index = parent_func->vt_index;
- vector_set(&env->curr->vtable, f->func->vt_index, (vtype)f->func);
+ vector_set(&env->curr->info->vtable, f->func->vt_index, (vtype)f->func);
}
return GW_OK;
}
return match;
}
}
- if(!env->curr->vtable.ptr)
- vector_init(&env->curr->vtable);
- func->vt_index = vector_size(&env->curr->vtable);
- vector_add(&env->curr->vtable, (vtype)func);
+ if(!env->curr->info->vtable.ptr)
+ vector_init(&env->curr->info->vtable);
+ func->vt_index = vector_size(&env->curr->info->vtable);
+ vector_add(&env->curr->info->vtable, (vtype)func);
return GW_OK;
}
ANN static inline void inherit(const Type t) {
const Nspc nspc = t->nspc, parent = t->parent->nspc;
- nspc->offset = parent->offset;
- if(parent->vtable.ptr)
- vector_copy2(&parent->vtable, &nspc->vtable);
+ nspc->info->offset = parent->info->offset;
+ if(parent->info->vtable.ptr)
+ vector_copy2(&parent->info->vtable, &nspc->info->vtable);
}
ANN m_bool check_class_def(const Env env, const Class_Def class_def) { GWDEBUG_EXE
inherit(the_class);
if(class_def->body)
CHECK_BB(check_class_body(env, class_def))
- if(!the_class->p && the_class->nspc->offset)
- the_class->p = mp_ini((uint32_t)the_class->nspc->offset);
+ if(!the_class->p && the_class->nspc->info->offset)
+ the_class->p = mp_ini((uint32_t)the_class->nspc->info->offset);
SET_FLAG(the_class, checked | ae_flag_check);
return GW_OK;
}
}
ANN m_bool add_op(const Nspc nspc, const struct Op_Import* opi) {
- Vector v = (Vector)map_get(&nspc->op_map, (vtype)opi->op);
+ Vector v = (Vector)map_get(&nspc->info->op_map, (vtype)opi->op);
M_Operator* mo;
if(!v) {
v = new_vector();
- map_set(&nspc->op_map, (vtype)opi->op, (vtype)v);
+ map_set(&nspc->info->op_map, (vtype)opi->op, (vtype)v);
}
if((mo = operator_find(v, opi->lhs, opi->rhs)))
CHECK_BB((err_msg(0, "operator '%s', for type '%s' and '%s' already imported",
ANN Type op_check(const Env env, struct Op_Import* opi) {
Nspc nspc = env->curr;
do {
- if(nspc->op_map.ptr) {
+ if(nspc->info->op_map.ptr) {
Type l = opi->lhs;
do {
struct Op_Import opi2 = { .op=opi->op, .lhs=l, .rhs=opi->rhs, .data=opi->data };
- Type ret = op_check_inner(env, &nspc->op_map, &opi2);
+ Type ret = op_check_inner(env, &nspc->info->op_map, &opi2);
if(ret) {
if(ret == t_null)
break;
ANN m_bool operator_set_func(const struct Op_Import* opi) {
const Nspc nspc = ((Func)opi->data)->value_ref->owner;
- const Vector v = (Vector)map_get(&nspc->op_map, opi->op);
+ const Vector v = (Vector)map_get(&nspc->info->op_map, opi->op);
M_Operator* mo = operator_find(v, opi->lhs, opi->rhs);
CHECK_OB(mo)
mo->func = (Func)opi->data;
do {
Type r = opi->rhs;
do {
- if(!nspc->op_map.ptr)
+ if(!nspc->info->op_map.ptr)
continue;
- const Vector v = (Vector)map_get(&nspc->op_map, (vtype)opi->op);
+ const Vector v = (Vector)map_get(&nspc->info->op_map, (vtype)opi->op);
const M_Operator* mo = operator_find(v, l, r);
if(mo) {
if(mo->em)