#ifndef __TYPE
#define __TYPE
+ struct TypeInfo_ {
+ Type parent;
+ Nspc owner;
+ Class_Def def;
+ union type_data {
+ Func func;
+ Type base_type;
+ } d;
+ };
+
struct Type_ {
m_str name;
Nspc nspc;
- Type parent;
- Nspc owner;
- Class_Def def;
- union type_data {
- Func func;
- Type base_type;
- } d;
+ struct TypeInfo_ *e;
size_t xid;
size_t size;
size_t array_depth;
__attribute__((returns_nonnull))
ANN Type template_parent(const Env, const Type type);
static inline Type actual_type(const Type t) {
- return isa(t, t_class) > 0 ? t->d.base_type : t;
+ return isa(t, t_class) > 0 ? t->e->d.base_type : t;
}
ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); }
#endif
}
ANN static void emit_pre_ctor(const Emitter emit, const Type type) {
- if(type->parent)
- emit_pre_ctor(emit, type->parent);
+ if(type->e->parent)
+ emit_pre_ctor(emit, type->e->parent);
if(type->nspc->pre_ctor)
emit_ext_ctor(emit, type->nspc->pre_ctor);
if(GET_FLAG(type, template) && GET_FLAG(type, builtin)) {
ANN static m_uint get_depth(Type t) {
m_uint depth = 0;
do depth += t->array_depth;
- while((t = t->parent));
+ while((t = t->e->parent));
return depth;
}
ANN static m_bool emit_exp_decl_template(const Emitter emit, const Exp_Decl* decl) {
const Type t = typedef_base(decl->type);
if(!GET_FLAG(t, emit)) {
- CHECK_BB(template_push_types(emit->env, t->def->tmpl->list.list, t->def->tmpl->base))
- CHECK_BB(emit_class_def(emit, t->def))
+ CHECK_BB(template_push_types(emit->env, t->e->def->tmpl->list.list, t->e->def->tmpl->base))
+ CHECK_BB(emit_class_def(emit, t->e->def))
emit_pop_type(emit);
}
return GW_OK;
ANN static m_bool emit_template_code(const Emitter emit, const Func f) {
if(GET_FLAG(f, ref))
- CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->def))
+ CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->e->def))
const Value v = f->value_ref;
size_t scope = emit_push(emit, v->owner_class, v->owner);
CHECK_BB(emit_func_def(emit, f->def))
instr->m_val = exp->emit_var;
}
if(emit->env->func && isa(exp->type, t_lambda) < 0 && isa(exp->type, t_function) > 0 &&
- !GET_FLAG(exp->type->d.func->value_ref->d.func_ref, pure))
+ !GET_FLAG(exp->type->e->d.func->value_ref->d.func_ref, pure))
UNSET_FLAG(emit->env->func, pure);
} while((exp = exp->next));
return GW_OK;
}
ANN static m_bool emit_stmt_type(const Emitter emit, const Stmt_Type stmt) {
- return stmt->type->def ? emit_class_def(emit, stmt->type->def) : 1;
+ return stmt->type->e->def ? emit_class_def(emit, stmt->type->e->def) : 1;
}
ANN static m_bool emit_stmt_enum(const Emitter emit, const Stmt_Enum stmt) {
const Nspc nspc = type->nspc;
if(tmpl_class_base(class_def->tmpl))
return GW_OK;
- if(class_def->base.ext && ((/*!GET_FLAG(type->parent, emit) &&*/
+ if(class_def->base.ext && ((/*!GET_FLAG(type->e->parent, emit) &&*/
GET_FLAG(class_def->base.ext, typedef)) || class_def->base.ext->types)) {
const Type base = class_def->base.ext->array ?
- array_base(type->parent) : type->parent;
+ array_base(type->e->parent) : type->e->parent;
if(!base->nspc->pre_ctor)
- CHECK_BB(emit_class_def(emit, base->def))
+ CHECK_BB(emit_class_def(emit, base->e->def))
}
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->base.ext && class_def->base.ext->array)
- CHECK_BB(emit_array_extend(emit, type->parent, class_def->base.ext->array->exp))
+ CHECK_BB(emit_array_extend(emit, type->e->parent, class_def->base.ext->array->exp))
if(class_def->body) {
Class_Body body = class_def->body;
do CHECK_BB(emit_section(emit, body->section))
}
ANN static Type get_array_type(Type t) {
- while(t->d.base_type)
- t = t->d.base_type;
+ while(t->e->d.base_type)
+ t = t->e->d.base_type;
return t;
}
const Exp_Cast* cast = (Exp_Cast*)data;
Type l = cast->exp->type;
Type r = exp_self(cast)->type;
- while(!l->d.base_type)
- l = l->parent;
- while(!r->d.base_type)
- r = r->parent;
- if(l->array_depth == r->array_depth || isa(l->d.base_type, r->d.base_type) > 0)
+ while(!l->e->d.base_type)
+ l = l->e->parent;
+ while(!r->e->d.base_type)
+ r = r->e->parent;
+ if(l->array_depth == r->array_depth || isa(l->e->d.base_type, r->e->d.base_type) > 0)
return l;
return t_null;
}
static OP_EMIT(opem_func_assign) {
Exp_Binary* bin = (Exp_Binary*)data;
emit_add_instr(emit, int_r_assign);
- if((bin->lhs->type != t_lambda && isa(bin->lhs->type, t_fptr) < 0) && GET_FLAG(bin->rhs->type->d.func, member)) {
+ if((bin->lhs->type != t_lambda && isa(bin->lhs->type, t_fptr) < 0) && GET_FLAG(bin->rhs->type->e->d.func, member)) {
const Instr instr = emit_add_instr(emit, LambdaAssign);
instr->m_val = SZ_INT;
}
}
ANN static Type fptr_type(const Env env, Exp_Binary* bin) {
- const Func l_func = bin->lhs->type->d.func;
- const Func r_func = bin->rhs->type->d.func;
+ const Func l_func = bin->lhs->type->e->d.func;
+ const Func r_func = bin->rhs->type->e->d.func;
const Nspc nspc = l_func->value_ref->owner;
const m_str c = s_name(l_func->def->base->xid);
const Value v = l_func->value_ref;
const Func f = nspc_lookup_func1(nspc, sym); // was lookup2
CHECK_OO(f)
if(compat_func(r_func->def, f->def) > 0)
- return r_func->value_ref->type->d.base_type;
+ return r_func->value_ref->type->e->d.base_type;
}
return NULL;
}
bin->rhs->emit_var = 1;
if(isa(bin->lhs->type, t_lambda) > 0) {
Exp_Lambda *l = &bin->lhs->d.exp_lambda;
- const Type owner = nspc_lookup_type1(bin->rhs->type->owner->parent,
- insert_symbol(bin->rhs->type->owner->name));
- CHECK_BO(check_lambda(env, owner, l, bin->rhs->type->d.func->def))
+ const Type owner = nspc_lookup_type1(bin->rhs->type->e->owner->parent,
+ insert_symbol(bin->rhs->type->e->owner->name));
+ CHECK_BO(check_lambda(env, owner, l, bin->rhs->type->e->d.func->def))
return bin->rhs->type;
}
- const Func l_func = bin->lhs->type->d.func;
+ const Func l_func = bin->lhs->type->e->d.func;
const Func_Def l_fdef = l_func->def;
const Type l_type = l_func->value_ref->owner_class;
- const Func r_func = bin->rhs->type->d.func;
+ const Func r_func = bin->rhs->type->e->d.func;
const Func_Def r_fdef = r_func->def;
const Type r_type = r_func->value_ref->owner_class;
if(!r_type && l_type)
const Value v = nspc_lookup_value1(env->curr, cast->exp->d.exp_primary.d.var);
CHECK_OO(v)
const Func f = isa(v->type, t_fptr) > 0 ?
- v->type->d.func :
+ v->type->e->d.func :
nspc_lookup_func1(env->curr, insert_symbol(v->name));
CHECK_OO(f)
- CHECK_BO(compat_func(t->d.func->def, f->def))
+ CHECK_BO(compat_func(t->e->d.func->def, f->def))
cast->func = f;
return t;
}
static OP_EMIT(opem_fptr_cast) {
CHECK_BB(opem_basic_cast(emit, data))
Exp_Cast* cast = (Exp_Cast*)data;
- if(GET_FLAG(cast->exp->type->d.func, member)) {
+ if(GET_FLAG(cast->exp->type->e->d.func, member)) {
const Instr instr = emit_add_instr(emit, RegPop);
instr->m_val = SZ_INT*2;
const Instr dup = emit_add_instr(emit, Reg2Reg);
free(name);
if(GET_FLAG(type, typedef)) {
gw_out(" aka ");
- print_type(type->parent);
+ print_type(type->e->parent);
}
}
}
ANN static inline void print_func(const Type type, const m_bit* stack) {
- if(type->d.func) {
+ if(type->e->d.func) {
const VM_Code code = isa(type, t_fptr) > 0 ?
- *(VM_Code*)stack : type->d.func->code;
+ *(VM_Code*)stack : type->e->d.func->code;
gw_out("%s %s %p", type->name, (void*)code ? code->name : NULL, code);
} else
gw_out("%s %p", type->name, NULL);
else if(type == t_class)
print_type(type);
else if(isa(type, t_class) > 0)
- print_type(type->d.base_type);
+ print_type(type->e->d.base_type);
else if(isa(type, t_void) > 0)
print_string1("void");
else
mk_xtor(env->gwion->mp, type, (m_uint)pre_ctor, ae_flag_ctor);
if(dtor)
mk_xtor(env->gwion->mp, type, (m_uint)dtor, ae_flag_dtor);
- if(type->parent) {
- 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);
+ if(type->e->parent) {
+ type->nspc->info->offset = type->e->parent->nspc->info->offset;
+ if(type->e->parent->nspc->info->vtable.ptr)
+ vector_copy2(&type->e->parent->nspc->info->vtable, &type->nspc->info->vtable);
}
- type->owner = env->curr;
+ type->e->owner = env->curr;
SET_FLAG(type, checked);
env_push_type(env, type);
}
GWI_ERR_B("during import: class '%s' already imported.", type->name)
if(gwi->templater.n) {
const ID_List types = templater_def(gwi->gwion->st, gwi);
- type->def = new_class_def(gwi->gwion->mp, 0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, loc_cpy(gwi->gwion->mp, gwi->loc));
- type->def->tmpl = new_tmpl_class(gwi->gwion->mp, types, -1);
- type->def->base.type = type;
+ type->e->def = new_class_def(gwi->gwion->mp, 0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, loc_cpy(gwi->gwion->mp, gwi->loc));
+ type->e->def->tmpl = new_tmpl_class(gwi->gwion->mp, types, -1);
+ type->e->def->base.type = type;
SET_FLAG(type, template);
} else
SET_FLAG(type, scan1 | ae_flag_scan2 | ae_flag_check | ae_flag_emit);
if(!gwi->gwion->env->class_def)
GWI_ERR_B("gwi_class_ext invoked before gwi_class_ini")
const VM_Code ctor = gwi->gwion->env->class_def->nspc->pre_ctor;
- if(gwi->gwion->env->class_def->parent ||
- (gwi->gwion->env->class_def->def && gwi->gwion->env->class_def->def->base.ext))
+ if(gwi->gwion->env->class_def->e->parent ||
+ (gwi->gwion->env->class_def->e->def && gwi->gwion->env->class_def->e->def->base.ext))
GWI_ERR_B("class extend already set")
if(td->array && !td->array->exp)
GWI_ERR_B("class extend array can't be empty")
- if(!gwi->gwion->env->class_def->def) {
+ if(!gwi->gwion->env->class_def->e->def) {
const Type t = known_type(gwi->gwion->env, td);
CHECK_OB(t)
if(td->array)
SET_FLAG(gwi->gwion->env->class_def, typedef);
- gwi->gwion->env->class_def->parent = t;
+ gwi->gwion->env->class_def->e->parent = t;
gwi->gwion->env->class_def->nspc->info->offset = t->nspc->info->offset;
if(t->nspc->info->vtable.ptr)
vector_copy2(&t->nspc->info->vtable, &gwi->gwion->env->class_def->nspc->info->vtable);
free_type_decl(gwi->gwion->mp, td);
} else {
SET_FLAG(td, typedef);
- gwi->gwion->env->class_def->def->base.ext = td;
+ gwi->gwion->env->class_def->e->def->base.ext = td;
}
return GW_OK;
}
#undef gwi_item_end
static void gwi_body(const Gwi gwi, const Class_Body body) {
- if(!gwi->gwion->env->class_def->def->body)
- gwi->gwion->env->class_def->def->body = body;
+ if(!gwi->gwion->env->class_def->e->def->body)
+ gwi->gwion->env->class_def->e->def->body = body;
else
gwi->body->next = body;
gwi->body = body;
*/
INSTR(DTOR_EOC) {
const M_Object o = *(M_Object*)MEM(0);
- o->type_ref = o->type_ref->parent;
+ o->type_ref = o->type_ref->e->parent;
__release(o, shred);
shred->info->me->ref = 1;
vm_shred_exit(shred);
return;
}
}
- } while((t = t->parent));
+ } while((t = t->e->parent));
Except(shred, "MissigTmplException[internal]"); //unreachable
}
ANN void __release(const M_Object o, const VM_Shred shred) {
MemPool p = shred->info->mp;// = shred->info->vm->gwion->mp;
Type t = o->type_ref;
- while(t->parent) {
+ while(t->e->parent) {
struct scope_iter iter = { t->nspc->info->value, 0, 0 };\
Value v;
while(scope_iter(&iter, &v) > 0) {
return;
}
}
- t = t->parent;
+ t = t->e->parent;
}
free_object(p, o);
}
static inline Type new_force_type(MemPool p, const Type t, const Symbol sym) {
const Type ret = type_copy(p, t);
SET_FLAG(ret, force);
- nspc_add_type(t->owner, sym, ret);
+ nspc_add_type(t->e->owner, sym, ret);
return ret;
}
strcpy(name, t->name);
strcpy(name + len, STR_FORCE);
const Symbol sym = insert_symbol(env->gwion->st, name);
- return nspc_lookup_type0(t->owner, sym) ?: new_force_type(env->gwion->mp, t, sym);
+ return nspc_lookup_type0(t->e->owner, sym) ?: new_force_type(env->gwion->mp, t, sym);
}
static OP_CHECK(opck_object_cast) {
bin->lhs->emit_var = 1;
return bin->lhs->type;
}
- } while((t = t->parent));
+ } while((t = t->e->parent));
return t_null;
}
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
- exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
+ exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
return exp_self(unary)->type;
}
ANN void env_add_type(const Env env, const Type type) {
const Type v_type = type_copy(env->gwion->mp, t_class);
- v_type->d.base_type = type;
+ v_type->e->d.base_type = type;
SET_FLAG(type, builtin);
nspc_add_type(env->curr, insert_symbol(type->name), type);
const Value v = new_value(env->gwion->mp, v_type, type->name);
SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin);
nspc_add_value(env->curr, insert_symbol(type->name), v);
- type->owner = env->curr;
+ type->e->owner = env->curr;
type->xid = ++env->scope->type_xid;
}
const Symbol xid = path->xid;
if(nspc) {
Type t = nspc_lookup_type1(nspc, xid);
- while(!t && type && type->parent && type->parent) {
- t = nspc_lookup_type1(type->parent->nspc, xid); // was lookup2
- type = type->parent;
+ while(!t && type && type->e->parent && type->e->parent) {
+ t = nspc_lookup_type1(type->e->parent->nspc, xid); // was lookup2
+ type = type->e->parent;
}
if(!t)
ERR_O(path->pos, "...(cannot find class '%s' in nspc '%s')", s_name(xid), nspc->name)
ANN static void free_type(Type a, Gwion gwion) {
if(GET_FLAG(a, template))
- free_class_def(gwion->mp, a->def);
+ free_class_def(gwion->mp, a->e->def);
if(a->nspc)
REM_REF(a->nspc, gwion);
mp_free(gwion->mp, Type, a);
const Type type = mp_alloc(p, Type);
type->xid = xid;
type->name = name;
- type->parent = parent;
- if(type->parent)
+ type->e = mp_alloc(p, TypeInfo);
+ type->e->parent = parent;
+ if(type->e->parent)
type->size = parent->size;
INIT_OO(p, type, free_type);
return type;
}
ANN Type type_copy(MemPool p, const Type type) {
- const Type a = new_type(p, type->xid, type->name, type->parent);
+ const Type a = new_type(p, type->xid, type->name, type->e->parent);
a->nspc = type->nspc;
- a->owner = type->owner;
+ a->e->owner = type->e->owner;
a->size = type->size;
- a->d.base_type = type->d.base_type;
+ a->e->d.base_type = type->e->d.base_type;
a->array_depth = type->array_depth;
- a->def = type->def;
+ a->e->def = type->e->def;
return a;
}
ANN m_bool isa(const restrict Type var, const restrict Type parent) {
- return (var->xid == parent->xid) ? 1 : var->parent ? isa(var->parent, parent) : -1;
+ return (var->xid == parent->xid) ? 1 : var->e->parent ? isa(var->e->parent, parent) : -1;
}
ANN Type find_common_anc(const restrict Type lhs, const restrict Type rhs) {
return isa(lhs, rhs) > 0 ? rhs : isa(rhs, lhs) > 0 ? lhs : NULL;
}
-#define describe_find(name, t) \
-ANN t find_##name(const Type type, const Symbol xid) { \
- if(type->nspc) { \
- const t val = nspc_lookup_##name##0(type->nspc, xid); \
- if(val) \
- return val; \
- } \
- return type->parent ? find_##name(type->parent, xid) : NULL; \
+#define describe_find(name, t) \
+ANN t find_##name(const Type type, const Symbol xid) { \
+ if(type->nspc) { \
+ const t val = nspc_lookup_##name##0(type->nspc, xid); \
+ if(val) \
+ return val; \
+ } \
+ return type->e->parent ? find_##name(type->e->parent, xid) : NULL; \
}
describe_find(value, Value)
describe_find(func, Func)
ANN Type typedef_base(Type t) {
while(GET_FLAG(t, typedef))
- t = t->parent;
+ t = t->e->parent;
return t;
}
ANN Type array_base(Type type) {
const Type t = typedef_base(type);
- return t->d.base_type;
+ return t->e->d.base_type;
}
ANN Type array_type(const Env env, const Type base, const m_uint depth) {
len += 2;
}
const Symbol sym = insert_symbol(name);
- const Type type = nspc_lookup_type1(base->owner, sym);
+ const Type type = nspc_lookup_type1(base->e->owner, sym);
if(type)
return type;
const Type t = new_type(env->gwion->mp, t_array->xid, base->name, t_array);
t->name = s_name(sym);
t->size = SZ_INT;
t->array_depth = depth + base->array_depth;
- t->d.base_type = base;
+ t->e->d.base_type = base;
t->nspc = t_array->nspc;
ADD_REF(t->nspc);
SET_FLAG(t, checked);
- t->owner = base->owner;
- nspc_add_type(base->owner, sym, t);
+ t->e->owner = base->e->owner;
+ nspc_add_type(base->e->owner, sym, t);
return t;
}
do {
if(GET_FLAG(t, empty))
return GW_OK;
- if(GET_FLAG(t, typedef) && t->def)
- if(t->def->base.ext && t->def->base.ext->array && !t->def->base.ext->array->exp)
+ if(GET_FLAG(t, typedef) && t->e->def)
+ if(t->e->def->base.ext && t->e->def->base.ext->array && !t->e->def->base.ext->array->exp)
return GW_OK;
- } while((t = t->parent));
+ } while((t = t->e->parent));
return 0;
}
}
ANN static inline m_bool check_exp_decl_parent(const Env env, const Var_Decl var) {
- const Value value = find_value(env->class_def->parent, var->xid);
+ const Value value = find_value(env->class_def->e->parent, var->xid);
if(value)
ERR_B(var->pos,
"in class '%s': '%s' has already been defined in parent class '%s' ...",
ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) {
const Value v = var->value;
- const Func func = v->type->d.func;
+ const Func func = v->type->e->d.func;
const Type type = func->value_ref->owner_class;
if(!env->class_def) {
if(!type || GET_FLAG(func, global))
ERR_O(td_pos(decl->td), "can't infer type.");
if(GET_FLAG(decl->type , template)) {
const Type t = typedef_base(decl->type);
- CHECK_BO(traverse_template(env, t->def))
+ CHECK_BO(traverse_template(env, t->e->def))
}
const m_bool global = GET_FLAG(decl->td, global);
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
do {
const Var_Decl var = list->self;
const Value v = var->value;
- if(env->class_def && !env->scope->depth && env->class_def->parent)
+ if(env->class_def && !env->scope->depth && env->class_def->e->parent)
CHECK_BO(check_exp_decl_parent(env, var))
if(var->array && var->array->exp)
CHECK_BO(check_exp_array_subscripts(env, var->array->exp))
while(t_base && array->array->depth > t_base->array_depth) {
depth -= t_base->array_depth;
- if(t_base->parent)
- t_base = t_base->parent;
+ if(t_base->e->parent)
+ t_base = t_base->e->parent;
else
ERR_O(exp_self(array)->pos,
"array subscripts (%i) exceeds defined dimension (%i)",
struct Vector_ v;
vector_init(&v);
vector_add(&v, (vtype)insert_symbol(type->name));
- Nspc nspc = type->owner;
+ Nspc nspc = type->e->owner;
while(nspc && nspc != env->curr && nspc != env->global_nspc) {
const Type t = nspc_lookup_type0(nspc->parent, insert_symbol(nspc->name));
vector_add(&v, (vtype)insert_symbol(t->name));
array_base(e->type) == array_base(t);
if(!match) {
if(e->type == t_lambda && isa(t, t_fptr) > 0) {
- const Type owner = nspc_lookup_type1(t->owner->parent,
- insert_symbol(t->owner->name));
- return check_lambda(env, owner, &e->d.exp_lambda, t->d.func->def);
+ const Type owner = nspc_lookup_type1(t->e->owner->parent,
+ insert_symbol(t->e->owner->name));
+ return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def);
}
if(implicit) {
const struct Implicit imp = { e, t };
if(f)
return f;
next:
- t = t->parent;
+ t = t->e->parent;
}
assert(exp_self(exp));
ERR_O(exp_self(exp)->pos, "arguments do not match for template call")
ANN2(1) static void* function_alternative(const Env env, const Type f, const Exp args, const loc_t pos){
env_err(env, pos, "argument type(s) do not match for function. should be :");
- Func up = f->d.func;
+ Func up = f->e->d.func;
do {
gw_err("(%s)\t", up->name);
const Arg_List e = up->def->base->args;
const Exp call = exp->func;
const Exp args = exp->args;
m_uint args_number = 0;
- const Value value = nspc_lookup_value1(call->type->owner, insert_symbol(call->type->name));
+ const Value value = nspc_lookup_value1(call->type->e->owner, insert_symbol(call->type->name));
CHECK_OO(value)
const m_uint type_number = get_type_number(value->d.func_ref->def->tmpl->list);
Type_List tl[type_number];
CHECK_BO(check_exp_call1_check(env, exp->func))
if(exp->func->type == t_lambda)
return check_lambda_call(env, exp);
- if(GET_FLAG(exp->func->type->d.func, ref)) {
- const Value value = exp->func->type->d.func->value_ref;
- CHECK_BO(traverse_template(env, value->owner_class->def))
+ if(GET_FLAG(exp->func->type->e->d.func, ref)) {
+ const Value value = exp->func->type->e->d.func->value_ref;
+ CHECK_BO(traverse_template(env, value->owner_class->e->def))
}
if(exp->args)
CHECK_OO(check_exp(env, exp->args))
if(GET_FLAG(exp->func->type, func))
return check_exp_call_template(env, exp);
- const Func func = find_func_match(env, exp->func->type->d.func, exp->args);
+ const Func func = find_func_match(env, exp->func->type->e->d.func, exp->args);
return (exp_self(exp)->d.exp_call.m_func = func) ?
func->def->base->ret_type : function_alternative(env, exp->func->type, exp->args, exp_self(exp)->pos);
}
if(exp->tmpl) {
CHECK_OO(check_exp(env, exp->func))
const Type t = actual_type(exp->func->type);
- const Value v = nspc_lookup_value1(t->owner, insert_symbol(t->name));
+ const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name));
if(!v)
ERR_O(exp_self(exp)->pos, " template call of non-existant function.")
if(!GET_FLAG(v, func))
const m_str str = s_name(member->xid);
CHECK_OO((member->t_base = check_exp(env, member->base)))
const m_bool base_static = isa(member->t_base, t_class) > 0;
- const Type the_base = base_static ? member->t_base->d.base_type : member->t_base;
+ const Type the_base = base_static ? member->t_base->e->d.base_type : member->t_base;
if(!the_base->nspc)
ERR_O(member->base->pos,
"type '%s' does not have members - invalid use in dot expression of %s",
}
ANN m_bool check_stmt_type(const Env env, const Stmt_Type stmt) {
- return stmt->type->def ? check_class_def(env, stmt->type->def) : 1;
+ return stmt->type->e->def ? check_class_def(env, stmt->type->e->def) : 1;
}
ANN static Type check_exp_lambda(const Env env NUSED,
const Exp_If* exp_if NUSED) { return t_lambda; }
ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) {
const Type t = check_exp(env, exp->exp);
CHECK_OO(t)
- const Value v = nspc_lookup_value1(t->owner, insert_symbol(t->name));
+ const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name));
CHECK_OO(v)
return v->type;
}
do {
CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d)))
if(env->func && isa(curr->type, t_lambda) < 0 && isa(curr->type, t_function) > 0 &&
- !GET_FLAG(curr->type->d.func, pure))
+ !GET_FLAG(curr->type->e->d.func, pure))
UNSET_FLAG(env->func, pure);
} while((curr = curr->next));
return exp->type;
Type ptr = array_base(t);
const m_uint depth = t->array_depth - 1;
if(GET_FLAG(t, typedef))
- t = t->parent;
+ t = t->e->parent;
if(!t || !ptr || isa(t, t_array) < 0)
ERR_B(stmt_self(stmt)->pos, "type '%s' is not array.\n"
" This is not allowed in auto loop", stmt->exp->type->name)
}
ptr = type_decl_resolve(env, &td);
if(!GET_FLAG(ptr, checked))
- check_class_def(env, ptr->def);
+ check_class_def(env, ptr->e->def);
}
t = depth ? array_type(env, ptr, depth) : ptr;
stmt->v = new_value(env->gwion->mp, t, s_name(stmt->sym));
ANN static m_bool check_parent_match(const Env env, const Func_Def f) {
const Func func = f->base->func;
- const Type parent = env->class_def->parent;
+ const Type parent = env->class_def->e->parent;
if(parent) {
const Value v = find_value(parent, f->base->xid);
if(v && isa(v->type, t_function) > 0) {
ANN static m_bool check_func_def_override(const Env env, const Func_Def f) {
const Func func = f->base->func;
- if(env->class_def && env->class_def->parent) {
- const Value override = find_value(env->class_def->parent, f->base->xid);
+ if(env->class_def && env->class_def->e->parent) {
+ const Value override = find_value(env->class_def->e->parent, f->base->xid);
if(override && override->owner_class && isa(override->type, t_function) < 0)
ERR_B(f->pos,
"function name '%s' conflicts with previously defined value...\n"
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->parent->nspc, env->gwion);
+ REM_REF(class_def->base.type->e->parent->nspc, env->gwion);
}
if(class_def->base.ext->types) {
- const Type t = class_def->base.type->parent->array_depth ?
- array_base(class_def->base.type->parent) : class_def->base.type->parent;
+ 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))
- CHECK_BB(traverse_template(env, t->def))
+ 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->parent, checked))
- CHECK_BB(check_class_def(env, class_def->base.type->parent->def))
- if(GET_FLAG(class_def->base.type->parent, typedef))
+ 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);
return GW_OK;
}
}
ANN static inline void inherit(const Type t) {
- const Nspc nspc = t->nspc, parent = t->parent->nspc;
+ const Nspc nspc = t->nspc, parent = t->e->parent->nspc;
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) {
if(tmpl_class_base(class_def->tmpl))
return GW_OK;
- if(class_def->base.type->parent == t_undefined) {
- class_def->base.type->parent = check_td(env, class_def->base.ext);
+ 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 the_class = class_def->base.type;
if(class_def->base.ext)
CHECK_BB(check_class_parent(env, class_def))
else
- the_class->parent = t_object;
+ the_class->e->parent = t_object;
inherit(the_class);
if(class_def->body)
CHECK_BB(check_class_body(env, class_def))
struct Vector_ v;
vector_init(&v);
do ressembles(&v, t->nspc, name);
- while((t = t->parent) && t->nspc);
+ while((t = t->e->parent) && t->nspc);
for(m_uint i = 0; i < vector_size(&v); ++i)
gw_err("\t(did you mean '%s'?)\n", (m_str)vector_at(&v, i));
did_you_mean_nspc(type->nspc, name);
c[len] = 0;
return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, c));
}
- return t->parent;
+ return t->e->parent;
}
static m_bool op_match(const restrict Type t, const restrict Type mo) {
ANN static Nspc get_nspc(const struct Op_Import* opi) {
if(opi->op == op_impl)
- return opi->rhs->owner;
+ return opi->rhs->e->owner;
if(opi->op == op_cast)
return ((Exp_Cast*)opi->data)->nspc;
if(opi->lhs) {
ANN static Value mk_class(const Env env, const Type base) {
const Type t = type_copy(env->gwion->mp, t_class);
const Value v = new_value(env->gwion->mp, t, base->name);
- t->d.base_type = base;
- v->owner = base->owner;
+ t->e->d.base_type = base;
+ v->owner = base->e->owner;
SET_FLAG(v, const | ae_flag_checked);
- nspc_add_value(base->owner, insert_symbol(base->name), v);
+ nspc_add_value(base->e->owner, insert_symbol(base->name), v);
return v;
}
CHECK_BB(scan0_defined(env, stmt->base->xid, td_pos(stmt->base->td)));
const m_str name = s_name(stmt->base->xid);
const Type t = new_type(env->gwion->mp, t_fptr->xid, name, t_fptr);
- t->owner = !(!env->class_def && GET_FLAG(stmt->base->td, global)) ?
+ t->e->owner = !(!env->class_def && GET_FLAG(stmt->base->td, global)) ?
env->curr : env->global_nspc;
t->nspc = new_nspc(env->gwion->mp, name);
t->flag = stmt->base->td->flag;
stmt->type = t;
- nspc_add_type(t->owner, stmt->base->xid, t);
+ nspc_add_type(t->e->owner, stmt->base->xid, t);
stmt->value = mk_class(env, t);
return GW_OK;
}
const Nspc nspc = (!env->class_def && GET_FLAG(stmt->ext, global)) ?
env->global_nspc : env->curr;
nspc_add_type(nspc, stmt->xid, t);
- t->owner = nspc;
+ t->e->owner = nspc;
stmt->type = t;
t->flag = stmt->ext->flag | ae_flag_checked;
if(stmt->ext->array && !stmt->ext->array->exp)
SET_FLAG(t, empty);
} else {
- const ae_flag flag = base->def ? base->def->flag : 0;
+ 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)));
CHECK_BB(scan0_class_def(env, cdef))
const Type t = type_copy(env->gwion->mp, t_int);
t->xid = ++env->scope->type_xid;
t->name = stmt->xid ? s_name(stmt->xid) : "int";
- t->parent = t_int;
+ t->e->parent = t_int;
const Nspc nspc = GET_FLAG(stmt, global) ? env->global_nspc : env->curr;
- t->owner = nspc;
+ t->e->owner = nspc;
stmt->t = t;
if(stmt->xid) {
nspc_add_type(nspc, stmt->xid, t);
t->name = name;
t->nspc = new_nspc(env->gwion->mp, name);
t->nspc->parent = nspc;
- t->owner = nspc;
+ t->e->owner = nspc;
if(add) {
nspc_add_type(nspc, s, t);
mk_class(env, t);
ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) {
const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), t_object);
- t->owner = env->curr;
+ t->e->owner = env->curr;
t->nspc = new_nspc(env->gwion->mp, t->name);
t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr;
- t->def = cdef;
+ t->e->def = cdef;
t->flag = cdef->flag;
if(!strstr(t->name, "<"))
nspc_add_type(env->curr, cdef->base.xid, t);
return decl->type;
if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref))
ERR_O(exp_self(decl)->pos, "Type '%s' is abstract, declare as ref. (use @)", t->name)
- if(GET_FLAG(t, private) && t->owner != env->curr)
+ if(GET_FLAG(t, private) && t->e->owner != env->curr)
ERR_O(exp_self(decl)->pos, "can't use private type %s", t->name)
if(GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0))
ERR_O(exp_self(decl)->pos, "can't use protected type %s", t->name)
ERR_O(exp_self(decl)->pos, "...(note: object of type '%s' declared inside itself)", t->name)
}
}
- decl->base = t->def;
+ decl->base = t->e->def;
return decl->type = t;
}
SET_ACCESS(stmt, v)
}
SET_FLAG(v, const | ae_flag_enum | ae_flag_checked);
- nspc_add_value(stmt->t->owner, list->xid, v);
+ nspc_add_value(stmt->t->e->owner, list->xid, v);
vector_add(&stmt->values, (vtype)v);
} while((list = list->next));
return GW_OK;
ANN m_bool scan1_stmt_type(const Env env, const Stmt_Type stmt) {
if(!stmt->type)
CHECK_BB(scan0_stmt_type(env, stmt))
- return stmt->type->def ? scan1_class_def(env, stmt->type->def) : 1;
+ return stmt->type->e->def ? scan1_class_def(env, stmt->type->e->def) : 1;
}
ANN m_bool scan1_stmt_union(const Env env, const Stmt_Union stmt) {
const loc_t pos = td_pos(cdef->base.ext);
if(cdef->base.ext->array)
CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp))
- const Type parent = cdef->base.type->parent = known_type(env, cdef->base.ext);
+ const Type parent = cdef->base.type->e->parent = known_type(env, cdef->base.ext);
CHECK_OB(parent)
if(parent == t_undefined)
return GW_OK;
while(t) {
if(cdef->base.type == t)
ERR_B(pos, "recursive (%s <= %s) class declaration.", cdef->base.type->name, t->name);
- t = t->parent;
+ t = t->e->parent;
}
if(parent == cdef->base.type)
ERR_B(pos, "class '%s' cannot extend itself", cdef->base.type->name);
- if(isa(cdef->base.type->parent, t_object) < 0)
+ if(isa(cdef->base.type->e->parent, t_object) < 0)
ERR_B(pos, "cannot extend primitive type '%s'",
- cdef->base.type->parent->name)
- if(!GET_FLAG(parent, scan1) && parent->def)
- CHECK_BB(scan1_class_def(env, parent->def))
+ cdef->base.type->e->parent->name)
+ if(!GET_FLAG(parent, scan1) && parent->e->def)
+ CHECK_BB(scan1_class_def(env, parent->e->def))
if(type_ref(parent))
ERR_B(pos, "can't use ref type in class extend")
return GW_OK;
ANN static m_bool scan2_exp_decl_template(const Env env, const Exp_Decl* decl) {
CHECK_BB(template_push_types(env, decl->base->tmpl->list.list, decl->td->types));
- CHECK_BB(scan1_class_def(env, decl->type->def))
- CHECK_BB(scan2_class_def(env, decl->type->def))
+ CHECK_BB(scan1_class_def(env, decl->type->e->def))
+ CHECK_BB(scan2_class_def(env, decl->type->e->def))
nspc_pop_type(env->gwion->mp, env->curr);
return GW_OK;
}
ptr->base->func = new_func(env->gwion->mp, s_name(ptr->base->xid), def);
ptr->value->d.func_ref = ptr->base->func;
ptr->base->func->value_ref = ptr->value;
- ptr->type->d.func = ptr->base->func;
+ ptr->type->e->d.func = ptr->base->func;
SET_FLAG(ptr->value, func | ae_flag_checked);
if(ptr->base->args)
CHECK_BB(scan2_args(env, def))
ptr->value->owner_class = env->class_def;
}
nspc_add_value(env->curr, ptr->base->xid, ptr->value);
- nspc_add_func(ptr->type->owner, ptr->base->xid, ptr->base->func);
+ nspc_add_func(ptr->type->e->owner, ptr->base->xid, ptr->base->func);
return GW_OK;
}
ANN m_bool scan2_stmt_type(const Env env, const Stmt_Type stmt) {
- return stmt->type->def ? scan2_class_def(env, stmt->type->def) : 1;
+ return stmt->type->e->def ? scan2_class_def(env, stmt->type->e->def) : 1;
}
ANN static inline Value prim_value(const Env env, const Symbol s) {
ANN static Type func_type(const Env env, const Func func) {
const Type t = type_copy(env->gwion->mp, t_function);
t->name = func->name;
- t->owner = env->curr;
+ t->e->owner = env->curr;
if(GET_FLAG(func, member))
t->size += SZ_INT;
- t->d.func = func;
+ t->e->d.func = func;
return t;
}
}
} while((ff = ff->next) && ++i);
}
- } while(type && (type = type->parent) && (nspc = type->nspc));
+ } while(type && (type = type->e->parent) && (nspc = type->nspc));
--i;
const Symbol sym = func_symbol(env, env->curr->name, func_name, "template", i);
nspc_add_value(env->curr, sym, value);
DECL_SECTION_FUNC(scan2)
ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) {
- const Type t = cdef->base.type->parent->array_depth ?
- array_base(cdef->base.type->parent) : cdef->base.type->parent;
+ const Type t = cdef->base.type->e->parent->array_depth ?
+ array_base(cdef->base.type->e->parent) : cdef->base.type->e->parent;
if(!GET_FLAG(t, scan2) && GET_FLAG(cdef->base.ext, typedef))
- CHECK_BB(scan2_class_def(env, t->def))
+ CHECK_BB(scan2_class_def(env, t->e->def))
if(cdef->base.ext->array)
CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp))
return GW_OK;
ANEW ANN static Vector get_types(const Env env, Type t) {
const Vector v = new_vector(env->gwion->mp);
do if(GET_FLAG(t, template))
- vector_add(v, (vtype)t->def->tmpl->list.list);
+ vector_add(v, (vtype)t->e->def->tmpl->list.list);
while((t = owner_type(env, t)));
return v;
}
ANN static ID_List get_total_type_list(const Env env, const Type t) {
const Type parent = owner_type(env, t);
if(!parent)
- return t->def->tmpl ? t->def->tmpl->list.list : NULL;
+ return t->e->def->tmpl ? t->e->def->tmpl->list.list : NULL;
const Vector v = get_types(env, parent);
const ID_List base = (ID_List)vector_pop(v);
if(!base) {
free_vector(env->gwion->mp, v);
- return t->def->tmpl ? t->def->tmpl->list.list : NULL;
+ return t->e->def->tmpl ? t->e->def->tmpl->list.list : NULL;
}
const ID_List types = id_list_copy(env->gwion->mp, base);
ID_List list, tmp = types;
list = (ID_List)vector_pop(v);
tmp = (tmp->next = id_list_copy(env->gwion->mp, list));
}
- tmp->next = t->def->tmpl->list.list;
+ tmp->next = t->e->def->tmpl->list.list;
free_vector(env->gwion->mp, v);
return types;
}
str = tmpl_get(info, str);
*str++ = (info->index < size - 1) ? ',' : '>';
}
- if(info->cdef->base.type->owner == env->global_nspc)
+ if(info->cdef->base.type->e->owner == env->global_nspc)
sprintf(str, "%p", (void*)env->curr);
else
*str = '\0';
ANN static Class_Def template_class(const Env env, const Class_Def def, const Type_List call) {
const Symbol name = template_id(env, def, call);
const Type t = nspc_lookup_type1(env->curr, name);
- return t ? t->def : new_class_def(env->gwion->mp, def->flag, name, def->base.ext, def->body,
+ return t ? t->e->def : new_class_def(env->gwion->mp, def->flag, name, def->base.ext, def->body,
loc_cpy(env->gwion->mp, def->pos));
}
if(!type->types)
ERR_O(type->xid->pos,
"you must provide template types for type '%s'", t->name)
- if(template_match(t->def->tmpl->list.list, type->types) < 0)
+ if(template_match(t->e->def->tmpl->list.list, type->types) < 0)
ERR_O(type->xid->pos, "invalid template types number")
- CHECK_BO(template_push_types(env, t->def->tmpl->list.list, type->types))
- const Class_Def a = template_class(env, t->def, type->types);
+ CHECK_BO(template_push_types(env, t->e->def->tmpl->list.list, type->types))
+ const Class_Def a = template_class(env, t->e->def, type->types);
SET_FLAG(a, ref);
if(a->base.type)
POP_RET(a->base.type);
CHECK_BO(scan0_class_def(env, a))
SET_FLAG(a->base.type, template | ae_flag_ref);
- a->base.type->owner = t->owner;
+ a->base.type->e->owner = t->e->owner;
if(GET_FLAG(t, builtin))
SET_FLAG(a->base.type, builtin);
CHECK_BO(scan1_class_def(env, a))
}
a->tmpl = new_tmpl_class(env->gwion->mp, get_total_type_list(env, t), 0);
a->tmpl->base = type->types;
- nspc_add_type(t->owner, insert_symbol(a->base.type->name), a->base.type);
+ nspc_add_type(t->e->owner, insert_symbol(a->base.type->name), a->base.type);
return a->base.type;
} else if(type->types)
ERR_O(type->xid->pos,