struct VM_Code_* pre_ctor;
struct VM_Code_* dtor;
struct NspcInfo_* info;
+ uint ref;
HAS_OBJ
};
m_bit* data;
Type type_ref;
Vector vtable;
- volatile size_t ref;
+ /* volatile */size_t ref;
};
ANN void instantiate_object(const VM_Shred, const Type);
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, t_union) < 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;
- } else exit(2);
+ 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;
} else {
const Instr instr = emit_add_instr(emit, RegPushImm);
instr->m_val = (m_uint)v->type;
stmt->value->type->nspc->info->offset = stmt->s;
Type_Decl *type_decl = new_type_decl(emit->gwion->mp,
new_id_list(emit->gwion->mp, stmt->xid, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos)),
-// emit->env->class_def ? ae_flag_member : 0);
stmt->flag);
-//if(emit->env->class_def && !GET_FLAG(stmt, static))
-//SET_FLAG(type_decl, member);
-// type_decl->flag = stmt->flag;// ???
const Var_Decl var_decl = new_var_decl(emit->gwion->mp, stmt->xid, NULL, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos));
const Var_Decl_List var_decl_list = new_var_decl_list(emit->gwion->mp, var_decl, NULL);
const Exp exp = new_exp_decl(emit->gwion->mp, type_decl, var_decl_list);
#include "vm.h"
#include "env.h"
#include "instr.h"
+#include "nspc.h"
#include "type.h"
#include "object.h"
#include "import.h"
CHECK_OB((t_vec3 = gwi_mk_type(gwi, "Vec3", SZ_VEC3, NULL)))
CHECK_OB((t_vec4 = gwi_mk_type(gwi, "Vec4", SZ_VEC4, NULL)))
CHECK_BB(import_object(gwi))
- CHECK_BB(import_array(gwi))
CHECK_OB((t_union = gwi_mk_type(gwi, "@Union", SZ_INT, t_object)))
- CHECK_BB(gwi_add_type(gwi, t_union))
+ CHECK_BB(gwi_class_ini(gwi, t_union, NULL, NULL))
+ CHECK_BB(gwi_class_end(gwi))
+ CHECK_BB(import_array(gwi))
CHECK_BB(import_event(gwi))
CHECK_BB(import_ugen(gwi))
CHECK_BB(import_ptr(gwi))
(value->d.ptr && GET_FLAG(value, builtin))) {
const M_Object obj = value->d.ptr ? (M_Object)value->d.ptr :
*(M_Object*)(a->info->class_data + value->offset);
- release(obj, gwion->vm->cleaner_shred);
+ release(obj, gwion->vm->cleaner_shred);
}
}
ANN static void free_nspc_value(const Nspc a, Gwion gwion) {
struct scope_iter iter = { a->info->value, 0, 0 };
Value v;
- while(scope_iter(&iter, &v) > 0) {
- if(v->type && (isa(v->type, t_object) > 0 ||
- (isa(v->type, t_union) > 0 &&
- (GET_FLAG(v, static) || GET_FLAG(v, global))))) {
- nspc_release_object(a, v, gwion);
+ if(!a->ref) {
+ while(scope_iter(&iter, &v) > 0) {
+ if(isa(v->type, t_object) > 0)
+ nspc_release_object(a, v, gwion);
+ REM_REF(v, gwion);
}
- REM_REF(v, gwion);
}
free_scope(gwion->mp, a->info->value);
}
nspc->info->b += v->type->size; \
}
describe_check_decl(member, offset)
-//describe_check_decl(static, class_data_size)
-ANN static inline void decl_static(const Nspc nspc, const Value v) { \
- SET_FLAG(v, static);
- v->offset = nspc->info->class_data_size;
- nspc->info->class_data_size += v->type->size;
-}
+describe_check_decl(static, class_data_size)
ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) {
const Value v = var->value;
}
}
}
-// check m_func => maybe assert
- if(!m_func && sz != vector_size((Vector)env->curr->info->type))
+ if(sz != vector_size((Vector)env->curr->info->type))
nspc_pop_type(env->gwion->mp, env->curr);
SET_FLAG(base, template);
}
} else if(env->class_def) {
if(!GET_FLAG(stmt, static))
stmt->o = env->class_def->nspc->info->offset;
- else
- decl_static(env->curr, stmt->value);
+ else {
+ stmt->o = stmt->type->nspc->info->class_data_size;
+ stmt->type->nspc->info->class_data_size += SZ_INT;
+ }
}
const m_uint scope = union_push(env, stmt);
Decl_List l = stmt->l;
DECL_SECTION_FUNC(check)
-ANN static m_bool check_class_parent(const Env env, const Class_Def class_def) {
- if(class_def->base.ext->array) {
- CHECK_BB(check_exp_array_subscripts(env, class_def->base.ext->array->exp))
- if(!GET_FLAG(class_def->base.type, check) && class_def->tmpl)
- REM_REF(class_def->base.type->e->parent->nspc, env->gwion);
+ANN static m_bool check_class_parent(const Env env, const Class_Def cdef) {
+ const Type parent = cdef->base.type->e->parent;
+ const Type_Decl *td = cdef->base.ext;
+ if(td->array) {
+ CHECK_BB(check_exp_array_subscripts(env, td->array->exp))
+ if(!GET_FLAG(cdef->base.type, check) && cdef->tmpl)
+ REM_REF(parent->nspc, env->gwion);
}
- if(class_def->base.ext->types) {
- const Type t = class_def->base.type->e->parent->array_depth ?
- array_base(class_def->base.type->e->parent) : class_def->base.type->e->parent;
- if(!GET_FLAG(t, checked)) {
-// if(class_def->tmpl)
-// CHECK_BB(template_push_types(env, class_def->tmpl->list.list, class_def->tmpl->base))
+ if(td->types) {
+ const Type t = parent->array_depth ? array_base(parent) : parent;
+ if(!GET_FLAG(t, checked))
CHECK_BB(traverse_template(env, t->e->def))
-// if(class_def->tmpl)
-// nspc_pop_type(env->gwion->mp, env->curr);
- }
}
- if(!GET_FLAG(class_def->base.type->e->parent, checked))
- CHECK_BB(check_class_def(env, class_def->base.type->e->parent->e->def))
- if(GET_FLAG(class_def->base.type->e->parent, typedef))
- SET_FLAG(class_def->base.type, typedef);
+ if(!GET_FLAG(parent, checked))
+ CHECK_BB(check_class_def(env, parent->e->def))
+ if(GET_FLAG(parent, typedef))
+ SET_FLAG(cdef->base.type, typedef);
return GW_OK;
}
-ANN static m_bool check_class_body(const Env env, const Class_Def class_def) {
- const m_uint scope = env_push_type(env, class_def->base.type);
- Class_Body body = class_def->body;
+ANN static m_bool check_class_body(const Env env, const Class_Def cdef) {
+ const m_uint scope = env_push_type(env, cdef->base.type);
+ Class_Body body = cdef->body;
do CHECK_BB(check_section(env, body->section))
while((body = body->next));
env_pop(env, scope);
vector_copy2(&parent->info->vtable, &nspc->info->vtable);
}
-ANN m_bool check_class_def(const Env env, const Class_Def class_def) {
- if(tmpl_class_base(class_def->tmpl))
+ANN m_bool check_class_def(const Env env, const Class_Def cdef) {
+ if(tmpl_class_base(cdef->tmpl))
return GW_OK;
- if(class_def->base.type->e->parent == t_undefined) {
- class_def->base.type->e->parent = check_td(env, class_def->base.ext);
- return traverse_class_def(env, class_def);
+ const Type type = cdef->base.type;
+ if(type->e->parent == t_undefined) {
+ type->e->parent = check_td(env, cdef->base.ext);
+ return traverse_class_def(env, cdef);
}
- const Type the_class = class_def->base.type;
- if(class_def->base.ext)
- CHECK_BB(check_class_parent(env, class_def))
- else
- the_class->e->parent = t_object;
- inherit(the_class);
- if(class_def->body)
- CHECK_BB(check_class_body(env, class_def))
- SET_FLAG(the_class, checked | ae_flag_check);
+ if(cdef->base.ext)
+ CHECK_BB(check_class_parent(env, cdef))
+ else if(!type->e->parent)
+ type->e->parent = t_object;
+ inherit(type);
+ if(cdef->body)
+ CHECK_BB(check_class_body(env, cdef))
+ SET_FLAG(type, checked | ae_flag_check);
return GW_OK;
}
const ae_flag flag = base->e->def ? base->e->def->flag : 0;
const Class_Def cdef = new_class_def(env->gwion->mp, flag, stmt->xid, stmt->ext, NULL,
loc_cpy(env->gwion->mp, td_pos(stmt->ext)));
-//const Type parent = known_type(env, stmt->ext);
-//if(!parent->array_depth && !GET_FLAG(parent, builtin) && !GET_FLAG(parent, scan0)) {
-//puts(parent->name);
-//exit(9);
-//}
-//printf("%p\n", stmt->ext->types);exit(6);
-//if(stmt->ext->types)
-// cdef->tmpl = new_tmpl_class(, $2, -1);
CHECK_BB(scan0_class_def(env, cdef))
stmt->type = cdef->base.type;
}
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);
-//t->e->parent = t_union;
t->xid = ++env->scope->type_xid;
t->name = name;
t->nspc = new_nspc(env->gwion->mp, name);
t->nspc->parent = nspc;
+ t->nspc->ref = 1;
t->e->owner = nspc;
+ t->e->parent = t_union;
if(add) {
nspc_add_type(nspc, s, t);
mk_class(env, t);
const Nspc nspc = !GET_FLAG(stmt, global) ?
env->curr : env->global_nspc;
stmt->type = union_type(env, nspc, stmt->type_xid, 1);
+ SET_FLAG(stmt->type, checked);
} else {
const Nspc nspc = !GET_FLAG(stmt, global) ?
env->curr : env->global_nspc;
decl->base = t->e->def;
return decl->type = t;
}
-//#include "loc.h"
ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) {
CHECK_BB(env_storage(env, decl->td->flag, exp_self(decl)->pos))
Var_Decl_List list = decl->list;
if(!overload) {
ADD_REF(v);
nspc_add_value(env->curr, f->def->base->xid, v);
- } else /* if(!GET_FLAG(f->def, template)) */ {
-// f->next = overload->d.func_ref->next;
-if(overload->d.func_ref) {
- f->next = overload->d.func_ref->next;
- overload->d.func_ref->next = f;
-} else
- overload->d.func_ref = f;
+ } else {
+ if(overload->d.func_ref) {
+ f->next = overload->d.func_ref->next;
+ overload->d.func_ref->next = f;
+ } else
+ overload->d.func_ref = f;
}
return v;
}
#endif
ANN static inline m_bool overflow_(const m_bit* mem, const VM_Shred c) {
- return mem > (((m_bit*)c + sizeof(struct VM_Shred_) + SIZEOF_REG) + (SIZEOF_MEM) - (MEM_STEP));
+ return mem > (((m_bit*)c + sizeof(struct VM_Shred_) + SIZEOF_REG) + (SIZEOF_MEM) - (MEM_STEP*16));
}
ANN static inline VM_Shred init_spork_shred(const VM_Shred shred, const Instr instr) {
*(m_uint*)(mem+instr->m_val) = *(m_uint*)(reg+instr->m_val2);
DISPATCH()
overflow:
- if(overflow_(mem + SZ_INT*8, shred)) {
+ if(overflow_(mem, shred)) {
exception(shred, "StackOverflow");
continue;
}