struct Map_ lbls;
HAS_OBJ
m_bool error;
+ m_bool global;
};
ANN2(2) ANEW Context new_context(MemPool p, const Ast, const m_str);
struct Vector_ contains;
struct TupleForm_* tuple;
struct VM_Code_ *gack;
+ struct Context_ *ctx;
};
struct Type_ {
#ifndef __VALUE
#define __VALUE
+struct ValueFrom_ {
+ Nspc owner;
+ Type owner_class;
+ struct Context_ *ctx;
+ size_t offset;
+};
+
struct Value_ {
Type type;
m_str name;
- Nspc owner;
- Type owner_class;
+ struct ValueFrom_ *from;
union value_data{
m_uint* ptr;
Func func_ref;
} d;
- size_t offset;
HAS_OBJ
ae_flag flag;
};
ANN static m_bool emit_symbol_owned(const Emitter emit, const Exp_Primary* prim) {
const Value v = prim->value;
- const Exp dot = (!GET_FLAG(v, static) ? dot_this_exp : dot_static_exp)(emit, prim, v->owner_class);
+ const Exp dot = (!GET_FLAG(v, static) ? dot_this_exp : dot_static_exp)(emit, prim, v->from->owner_class);
dot->type = exp_self(prim)->type;
dot->emit_var = exp_self(prim)->emit_var;
const m_bool ret = emit_exp_dot(emit, &dot->d.exp_dot);
ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) {
const Value v = prim->value;
- if(v->owner_class)
+ if(v->from->owner_class)
return emit_symbol_owned(emit, prim);
if(isa(v->type, emit->gwion->type[et_class]) > 0) {
regpushi(emit, (m_uint)actual_type(emit->gwion, v->type));
return emit_symbol_builtin(emit, prim);
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase);
- instr->m_val = v->offset;
+ instr->m_val = v->from->offset;
if(isa(v->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, v->type))
- instr->m_val = exp_self(prim)->type->e->d.func->value_ref->offset;
+ instr->m_val = exp_self(prim)->type->e->d.func->value_ref->from->offset;
return GW_OK;
}
const m_uint size = v->type->size;
if(isa(v->type, emit->gwion->type[et_class]) < 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_val = (m_uint)(v->from->owner->info->class_data + v->from->offset);
instr->m_val2 = size;
} else
regpushi(emit, (m_uint)v->type);
CHECK_BB(emit_instantiate_object(emit, type, array, is_ref))
f_instr *exec = (f_instr*)allocmember;
if(!GET_FLAG(v, member)) {
- v->offset = emit_local(emit, v->type->size, is_obj);
+ v->from->offset = emit_local(emit, v->type->size, is_obj);
exec = (f_instr*)(allocword);
if(GET_FLAG(var_decl->value, ref)) {
const Instr clean = emit_add_instr(emit, MemSetImm);
- clean->m_val = v->offset;
+ clean->m_val = v->from->offset;
}
}
const Instr instr = emit_kind(emit, v->type->size, emit_addr, exec);
- instr->m_val = v->offset;
+ instr->m_val = v->from->offset;
instr->m_val2 = v->type->size;
if(is_obj && (is_array || !is_ref)) {
emit_add_instr(emit, Assign);
const Instr instr = (Instr)vector_back(&emit->code->instr);
if(instr->opcode == eDotTmplVal) {
size_t len = strlen(f->name);
- size_t sz = len - strlen(f->value_ref->owner_class->name);
+ size_t sz = len - strlen(f->value_ref->from->owner_class->name);
char c[sz + 1];
memcpy(c, f->name, sz);
c[sz] = '\0';
ANN static m_bool emit_template_code(const Emitter emit, const Func f) {
const Value v = f->value_ref;
- size_t scope = emit_push(emit, v->owner_class, v->owner);
+ size_t scope = emit_push(emit, v->from->owner_class, v->from->owner);
const m_bool ret = emit_func_def(emit, f->def);
emit_pop(emit, scope);
return ret > 0 ? push_func_code(emit, f) : GW_ERROR;
if(f->def->base->tmpl) { // TODO: put in func
struct dottmpl_ *dt = (struct dottmpl_*)mp_calloc(emit->gwion->mp, dottmpl);
size_t len = strlen(f->name);
- size_t slen = strlen(f->value_ref->owner->name);
+ size_t slen = strlen(f->value_ref->from->owner->name);
assert(len > slen);
size_t sz = len - slen;
char c[sz + 1];
dt->name = s_name(insert_symbol(c));
dt->vt_index = f->def->base->tmpl->base;
dt->base = f->def;
- dt->owner = f->value_ref->owner;
- dt->owner_class = f->value_ref->owner_class;
+ dt->owner = f->value_ref->from->owner;
+ dt->owner_class = f->value_ref->from->owner_class;
const Instr gtmpl = emit_add_instr(emit, GTmpl);
gtmpl->m_val = (m_uint)dt;
gtmpl->m_val2 = strlen(c);
back->opcode = ePushStaticCode;
back->m_val = 0;
}
- } else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) {
+ } else if(emit->env->func != f && !f->value_ref->from->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) {
const Instr back = !GET_FLAG(f->def, op) ? emit_add_instr(emit, PushStaticCode) : (Instr)vector_back(&emit->code->instr);
back->m_val = (m_uint)f;
}
- } else if((f->value_ref->owner_class && is_special(emit, f->value_ref->owner_class) > 0) ||
- !f->value_ref->owner_class || (GET_FLAG(f, template) &&
+ } else if((f->value_ref->from->owner_class && is_special(emit, f->value_ref->from->owner_class) > 0) ||
+ !f->value_ref->from->owner_class || (GET_FLAG(f, template) &&
!is_fptr(emit->gwion, f->value_ref->type)))
push_func_code(emit, f);
else if(vector_size(&emit->code->instr)) {
const Instr loop = emit_add_instr(emit, stmt->is_ptr ? AutoLoopPtr : AutoLoop);
const Instr end = emit_add_instr(emit, BranchEqInt);
const m_uint offset = emit_local(emit, SZ_INT + stmt->v->type->size, 0);
- stmt->v->offset = offset + SZ_INT;
+ stmt->v->from->offset = offset + SZ_INT;
CHECK_BB(emit_stmt(emit, stmt->body, 1))
const m_uint end_pc = emit_code_size(emit);
if(stmt->is_ptr) {
loop->m_val2 = (m_uint)stmt->v->type;
- cpy->m_val = stmt->v->offset;
+ cpy->m_val = stmt->v->from->offset;
}
const Instr tgt = emit_add_instr(emit, Goto);
end->m_val = emit_code_size(emit);
const Value v = (Value)vector_at(&edef->values, i);
if(!emit->env->class_def) {
ALLOC_PTR(emit->gwion->mp, addr, m_uint, i);
- v->offset = emit_local(emit, SZ_INT, 0);
+ v->from->offset = emit_local(emit, SZ_INT, 0);
v->d.ptr = addr;
} else
- *(m_bit*)(emit->env->class_def->nspc->info->class_data + v->offset) = i;
+ *(m_bit*)(emit->env->class_def->nspc->info->class_data + v->from->offset) = i;
}
return GW_OK;
}
ANN void emit_union_offset(Decl_List l, const m_uint o) {
do {
Var_Decl_List v = l->self->d.exp_decl.list;
- do v->self->value->offset = o;
+ do v->self->value->from->offset = o;
while((v = v->next));
} while((l = l->next));
}
ANN static m_bool case_value(const Emitter emit, const Exp base, const Exp e) {
const Value v = e->d.exp_primary.value;
- v->offset = emit_local(emit, base->type->size, isa(base->type, emit->gwion->type[et_object]) > 0);
+ v->from->offset = emit_local(emit, base->type->size, isa(base->type, emit->gwion->type[et_object]) > 0);
CHECK_BB(emit_exp(emit, base, 1))
regpop(emit, base->type->size);
const Instr instr = emit_add_instr(emit, Reg2Mem4);
- instr->m_val = v->offset;
+ instr->m_val = v->from->offset;
instr->m_val2 = base->type->size;
return GW_OK;
}
regpushi(emit, (m_uint)v->d.func_ref->code);
return GW_OK;
}
- if(!v->offset && exp_self(member)->emit_var)
+ if(!v->from->offset && exp_self(member)->emit_var)
return GW_OK;
const Instr instr = emit_add_instr(emit, VecMember);
- instr->m_val2 = v->offset;
+ instr->m_val2 = v->from->offset;
instr->m_val = exp_self(member)->emit_var;
return GW_OK;
}
ANN static inline m_bool emit_member(const Emitter emit, const Value v, const uint emit_addr) {
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, emit_addr, dotmember);
- instr->m_val = v->offset;
+ instr->m_val = v->from->offset;
instr->m_val2 = size;
return GW_OK;
}
ANN static inline void emit_func_def_global(const Emitter emit, const Value value) {
const Instr set_mem = emit_add_instr(emit, MemSetImm);
- set_mem->m_val = value->offset;
+ set_mem->m_val = value->from->offset;
set_mem->m_val2 = (m_uint)value->d.func_ref->code;
}
const m_uint size = value->type->size;
const m_bool obj = isa(value->type, emit->gwion->type[et_object]) > 0;
emit->code->stack_depth += size;
- value->offset = emit_local(emit, size, obj);
+ value->from->offset = emit_local(emit, size, obj);
} while((a = a->next));
}
if(SAFE_FLAG(emit->env->class_def, builtin) && GET_FLAG(emit->env->class_def, template))
return GW_OK;
if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl && !emit->env->scope->depth)
- func->value_ref->offset = emit_local(emit, SZ_INT, 0);
+ func->value_ref->from->offset = emit_local(emit, SZ_INT, 0);
emit_func_def_init(emit, func);
if(GET_FLAG(func, member))
stack_alloc_this(emit);
}
ANN static m_bool fptr_check(const Env env, struct FptrInfo *info) {
- const Type l_type = info->lhs->value_ref->owner_class;
- const Type r_type = info->rhs->value_ref->owner_class;
+ const Type l_type = info->lhs->value_ref->from->owner_class;
+ const Type r_type = info->rhs->value_ref->from->owner_class;
if(!r_type && l_type)
ERR_B(info->pos, _("can't assign member function to non member function pointer"))
else if(!l_type && r_type) {
ANN static Type fptr_type(const Env env, struct FptrInfo *info) {
const Value v = info->lhs->value_ref;
- const Nspc nspc = v->owner;
+ const Nspc nspc = v->from->owner;
const m_str c = s_name(info->lhs->def->base->xid),
stmpl = !info->rhs->def->base->tmpl ? NULL : "template";
Type type = NULL;
- for(m_uint i = 0; i <= v->offset && !type; ++i) {
+ for(m_uint i = 0; i <= v->from->offset && !type; ++i) {
const Symbol sym = (!info->lhs->def->base->tmpl || i != 0) ?
func_symbol(env, nspc->name, c, stmpl, i) : info->lhs->def->base->xid;
if(isa(info->lhs->value_ref->type, env->gwion->type[et_class]) < 0)
ANN static m_bool fptr_lambda(const Env env, struct FptrInfo *info) {
Exp_Lambda *l = &info->exp->d.exp_lambda;
- const Type owner = info->rhs->value_ref->owner_class;
+ const Type owner = info->rhs->value_ref->from->owner_class;
return check_lambda(env, owner, l, info->rhs->def);
}
if(v->var.value->type->array_depth)
ADD_REF(v->var.value->type);
dl_var_release(gwi->gwion->mp, v);
- return (m_int)v->var.value->offset;
+ return (m_int)v->var.value->from->offset;
}
static Array_Sub make_dll_arg_list_array(MemPool p, Array_Sub array_sub,
def->base->tmpl->call = dt->tl;
def->base->tmpl->base = dt->vt_index;
dt->def = def;
- dt->owner = v->owner;
- dt->owner_class = v->owner_class;
+ dt->owner = v->from->owner;
+ dt->owner_class = v->from->owner_class;
SET_FLAG(def, template);
return def;
}
const Emitter emit = shred->info->vm->gwion->emit;
emit->env->name = "runtime";
m_str tmpl_name = tl2str(emit->env, dt->tl);
- for(m_uint i = 0 ; i <= f->value_ref->offset; ++i) {
- const Symbol sym = func_symbol(emit->env, f->value_ref->owner->name,
+ for(m_uint i = 0 ; i <= f->value_ref->from->offset; ++i) {
+ const Symbol sym = func_symbol(emit->env, f->value_ref->from->owner->name,
name, tmpl_name, i);
- const Func base = nspc_lookup_func0(f->value_ref->owner, sym);
+ const Func base = nspc_lookup_func0(f->value_ref->from->owner, sym);
if(base) {
free_mstr(emit->gwion->mp, tmpl_name);
assert(base->code);
}
free_mstr(emit->gwion->mp, tmpl_name);
dt->def = f->def;
- const Func_Def def = traverse_tmpl(emit, dt, f->value_ref->owner);
+ const Func_Def def = traverse_tmpl(emit, dt, f->value_ref->from->owner);
if(!def)
Except(shred, "MissigTmplPtrException[internal]");
*(VM_Code*)(shred->reg -SZ_INT) = def->base->func->code;
while(scope_iter(&iter, &v) > 0) {
if(!GET_FLAG(v, static) && !GET_FLAG(v, pure) &&
isa(v->type, shred->info->vm->gwion->type[et_object]) > 0)
- release(*(M_Object*)(o->data + v->offset), shred);
+ release(*(M_Object*)(o->data + v->from->offset), shred);
}
if(GET_FLAG(t, dtor) && t->nspc->dtor) {
if(GET_FLAG(t->nspc->dtor, builtin))
const Value value = te->e->d.exp_decl.list->self->value;
te->sz += value->type->size;
sz += value->type->size;
- value->offset = emit_local(emit, value->type->size, 0);
-printf("value->offset %lu\n", value->offset);
+ value->from->offset = emit_local(emit, value->type->size, 0);
} else {
sz += ((Type)vector_at(te->v, te->idx))->size;
break;
const Value v = new_value(env->gwion->mp, v_type, s_name(sym));
SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin);
nspc_add_value(env->curr, insert_symbol(type->name), v);
- v->owner = type->e->owner = env->curr;
- v->owner_class = env->class_def;
+ v->from->owner = type->e->owner = env->curr;
+ v->from->owner_class = env->class_def;
type->xid = ++env->scope->type_xid;
}
env_reset(env);
load_context(ctx, env);
const m_bool ret = traverse_ast(env, ast);
- if(ret > 0) {
+ if(ret > 0) //{
nspc_commit(env->curr);
+ if(ret || env->context->global)
vector_add(&env->scope->known_ctx, (vtype)ctx);
- } else //nspc_rollback(env->global_nspc);
+ else //nspc_rollback(env->global_nspc);
REM_REF(ctx, env->gwion);
unload_context(ctx, env);
return ret;
if((GET_FLAG(value, static) && a->info->class_data) ||
(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);
+ *(M_Object*)(a->info->class_data + value->from->offset);
release(obj, gwion->vm->cleaner_shred);
}
}
ANN static void free_value(Value a, Gwion gwion) {
const Type t = a->type;
if(!GET_FLAG(a, func) && a->d.ptr && !GET_FLAG(a, union) &&
- !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class)
+ !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class)
&& isa(t, gwion->type[et_object]) < 0)
_mp_free(gwion->mp, t->size, a->d.ptr);
if(isa(t, gwion->type[et_class]) > 0/* || isa(a->type, t_function) > 0*/)
REM_REF(t, gwion)
+ mp_free(gwion->mp, ValueFrom, a->from);
mp_free(gwion->mp, Value, a);
}
ANN Value new_value(MemPool p, const Type type, const m_str name) {
const Value a = mp_calloc(p, Value);
+ a->from = mp_calloc(p, ValueFrom);
a->type = type;
a->name = name;
a->ref = new_refcount(p, free_value);
#include "tuple.h"
#include "emit.h"
#include "specialid.h"
+#include "context.h"
ANN static Type check_exp(const Env env, Exp exp);
ANN static m_bool check_stmt_list(const Env env, Stmt_List list);
ERR_B(var->pos,
_("in class '%s': '%s' has already been defined in parent class '%s' ..."),
env->class_def->name, s_name(var->xid),
- value->owner_class ? value->owner_class->name : "?")
+ value->from->owner_class ? value->from->owner_class->name : "?")
return GW_OK;
}
#define describe_check_decl(a, b) \
-ANN static inline void decl_##a(const Env env, const Value v) { \
+ANN static inline void decl_##a(const Env env, const Value v) { \
const Nspc nspc = env->curr;\
SET_FLAG(v, a); \
- v->offset = nspc->info->b; \
+ v->from->offset = nspc->info->b; \
nspc->info->b += v->type->size; \
}
describe_check_decl(member, offset)
ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) {
const Value v = var->value;
const Func func = v->type->e->d.func;
- const Type type = func->value_ref->owner_class;
+ const Type type = func->value_ref->from->owner_class;
if(!env->class_def) {
if(!type || GET_FLAG(func, global))
return GW_OK;
ANN static inline m_bool not_from_owner_class(const Env env, const Type t,
const Value v, const loc_t pos) {
- if(!v->owner_class || isa(t, v->owner_class) < 0) {
+ if(!v->from->owner_class || isa(t, v->from->owner_class) < 0) {
ERR_B(pos,
_("'%s' from owner namespace '%s' used in '%s'."),
- v->name, v->owner ? v->owner->name : "?", t->name)
+ v->name, v->from->owner ? v->from->owner->name : "?", t->name)
}
return GW_OK;
}
if(env->class_def) {
const Value v = value ? value : find_value(env->class_def, primary->d.var);
if(v) {
- if(v->owner_class)
+ if(v->from->owner_class)
CHECK_BO(not_from_owner_class(env, env->class_def, v, exp_self(primary)->pos))
if(env->func && GET_FLAG(env->func->def, static) && GET_FLAG(v, member))
ERR_O(exp_self(primary)->pos,
ANN static Type prim_id_non_res(const Env env, const Exp_Primary* primary) {
const Value v = check_non_res_value(env, primary);
- if(!v || !GET_FLAG(v, checked)) {
+ if(!v || !GET_FLAG(v, checked) || (v->from->ctx && v->from->ctx->error)) {
env_err(env, exp_self(primary)->pos,
_("variable %s not legit at this point."), s_name(primary->d.var));
- if(v && v->owner_class)
- did_you_mean_type(v->owner_class, s_name(primary->d.var));
+ if(v && v->from->owner_class)
+ did_you_mean_type(v->from->owner_class, s_name(primary->d.var));
else
- did_you_mean_nspc(v ? v->owner : env->curr, s_name(primary->d.var));
+ did_you_mean_nspc(v ? v->from->owner : env->curr, s_name(primary->d.var));
return NULL;
}
- if(env->func && !GET_FLAG(v, const) && v->owner)
+ if(env->func && !GET_FLAG(v, const) && v->from->owner)
UNSET_FLAG(env->func, pure);
SET_FLAG(v, used);
((Exp_Primary*)primary)->value = v;
}
if(e1->type == env->gwion->type[et_undefined] ||
(func->def->base->tmpl && is_fptr(env->gwion, func->value_ref->type) > 0)) {
- if(SAFE_FLAG(func->value_ref->owner_class, template))
- CHECK_BO(template_push_types(env, func->value_ref->owner_class->e->def->base.tmpl))
+ if(SAFE_FLAG(func->value_ref->from->owner_class, template))
+ CHECK_BO(template_push_types(env, func->value_ref->from->owner_class->e->def->base.tmpl))
e1->type = known_type(env, e1->td);
- if(SAFE_FLAG(func->value_ref->owner_class, template))
+ if(SAFE_FLAG(func->value_ref->from->owner_class, template))
nspc_pop_type(env->gwion->mp, env->curr);
CHECK_OO(e1->type)
}
}
ANN static inline Value template_get_ready(const Env env, const Value v, const m_str tmpl, const m_uint i) {
- const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl, i);
- return v->owner_class ? find_value(v->owner_class, sym) :
- nspc_lookup_value1(v->owner, sym);
+ const Symbol sym = func_symbol(env, v->from->owner->name, v->name, tmpl, i);
+ return v->from->owner_class ? find_value(v->from->owner_class, sym) :
+ nspc_lookup_value1(v->from->owner, sym);
}
static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) {
const Type_List types = exp->tmpl->call;
Func m_func = NULL, former = env->func;
DECL_OO(const m_str, tmpl_name, = tl2str(env, types))
- const m_uint scope = env_push(env, v->owner_class, v->owner);
+ const m_uint scope = env_push(env, v->from->owner_class, v->from->owner);
if(is_fptr(env->gwion, v->type)) {
- const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl_name, 0);
- const Value value = nspc_lookup_value1(v->owner, sym);
+ const Symbol sym = func_symbol(env, v->from->owner->name, v->name, tmpl_name, 0);
+ const Value value = nspc_lookup_value1(v->from->owner, sym);
Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->type->e->d.func->def;
Func_Base *fbase = cpy_func_base(env->gwion->mp, base->base);
fbase->xid = sym;
m_func = find_func_match(env, fbase->func, exp->args);
nspc_pop_type(env->gwion->mp, env->curr);
if(!value && m_func)
- nspc_add_type_front(v->owner, sym, actual_type(env->gwion, m_func->value_ref->type));
+ nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, m_func->value_ref->type));
}
free_fptr_def(env->gwion->mp, fptr); // ???? related
}
} else {
- for(m_uint i = 0; i < v->offset + 1; ++i) {
+ for(m_uint i = 0; i < v->from->offset + 1; ++i) {
const Value exists = template_get_ready(env, v, tmpl_name, i);
if(exists) {
if(env->func == exists->d.func_ref) {
const Func f = _find_template_match(env, value, exp);
if(f)
return f;
- Type t = value->owner_class;
+ Type t = value->from->owner_class;
while(t) {
const Value v = nspc_lookup_value0(t->nspc, value->d.func_ref->def->base->xid);
if(!v)
if(tm->call) {
DECL_OO(const Func, func, = value->d.func_ref ?: predefined_func(env, value, exp, tm))
if(!func->def->base->ret_type) { // template fptr
- const m_uint scope = env_push(env, value->owner_class, value->owner);
+ const m_uint scope = env_push(env, value->from->owner_class, value->from->owner);
CHECK_BO(traverse_func_def(env, func->def))
env_pop(env, scope);
}
return check_lambda_call(env, exp);
if(GET_FLAG(exp->func->type->e->d.func, ref)) {
const Value value = exp->func->type->e->d.func->value_ref;
- if(value->owner_class)
- CHECK_BO(traverse_class_def(env, value->owner_class->e->def))
+ if(value->from->owner_class)
+ CHECK_BO(traverse_class_def(env, value->from->owner_class->e->def))
}
if(exp->args)
CHECK_OO(check_exp(env, exp->args))
return NULL;
}
CHECK_BO(not_from_owner_class(env, the_base, value, exp_self(member)->pos))
- if(!env->class_def || isa(env->class_def, value->owner_class) < 0) {
+ if(!env->class_def || isa(env->class_def, value->from->owner_class) < 0) {
if(GET_FLAG(value, private))
ERR_O(exp_self(member)->pos,
_("can't access private '%s' outside of class..."), value->name)
ANN static m_bool check_signature_match(const Env env, const Func_Def fdef, const Func parent) {
if(GET_FLAG(parent->def, static) != GET_FLAG(fdef, static)) {
- const m_str c_name = fdef->base->func->value_ref->owner_class->name;
- const m_str p_name = parent->value_ref->owner_class->name;
+ const m_str c_name = fdef->base->func->value_ref->from->owner_class->name;
+ const m_str p_name = parent->value_ref->from->owner_class->name;
const m_str f_name = s_name(fdef->base->xid);
ERR_B(td_pos(fdef->base->td),
_("function '%s.%s' ressembles '%s.%s' but cannot override...\n"
ANN static m_bool check_func_overload(const Env env, const Func_Def fdef) {
const Value v = fdef->base->func->value_ref;
- for(m_uint i = 0; i <= v->offset; ++i) {
+ for(m_uint i = 0; i <= v->from->offset; ++i) {
const Func f1 = get_overload(env, fdef, i);
- for(m_uint j = i + 1; f1 && j <= v->offset; ++j) {
+ for(m_uint j = i + 1; f1 && j <= v->from->offset; ++j) {
const Func f2 = get_overload(env, fdef, j);
if(f2 && compat_func(f1->def, f2->def) > 0)
ERR_B(td_pos(f2->def->base->td), _("global function '%s' already defined"
const Func func = fdef->base->func;
if(env->class_def && env->class_def->e->parent) {
const Value override = find_value(env->class_def->e->parent, fdef->base->xid);
- if(override && override->owner_class && isa(override->type, env->gwion->type[et_function]) < 0)
+ if(override && override->from->owner_class && isa(override->type, env->gwion->type[et_function]) < 0)
ERR_B(fdef->pos,
_("function name '%s' conflicts with previously defined value...\n"
" from super class '%s'..."),
- s_name(fdef->base->xid), override->owner_class->name)
+ s_name(fdef->base->xid), override->from->owner_class->name)
}
- if(func->value_ref->offset && (!fdef->base->tmpl || !fdef->base->tmpl->base))
+ if(func->value_ref->from->offset && (!fdef->base->tmpl || !fdef->base->tmpl->base))
CHECK_BB(check_func_overload(env, fdef))
return GW_OK;
}
}
ANN m_bool operator_set_func(const struct Op_Import* opi) {
- const Nspc nspc = ((Func)opi->data)->value_ref->owner;
+ const Nspc nspc = ((Func)opi->data)->value_ref->from->owner;
const Vector v = (Vector)map_get(&nspc->info->op_map, (vtype)opi->op);
DECL_OB(M_Operator*, mo, = operator_find(v, opi->lhs, opi->rhs))
mo->func = (Func)opi->data;
#include "operator.h"
#include "import.h"
+#include "context.h"
+
static inline void add_type(const Env env, const Nspc nspc, const Type t) {
nspc_add_type_front(nspc, insert_symbol(t->name), t);
}
+static inline Type scan0_type(const Env env, const m_uint xid,
+ const m_str name, const Type t) {
+ const Type type = new_type(env->gwion->mp, xid, name, t);
+ type->e->ctx = env->context;
+ return type;
+}
+
ANN static Value mk_class(const Env env, const Type base) {
const Symbol sym = insert_symbol(base->name);
const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]);
+t->e->ctx = env->context;
const Value v = new_value(env->gwion->mp, t, s_name(sym));
t->e->d.base_type = base;
- v->owner = base->e->owner;
+// set from
+ v->from->owner = base->e->owner;
SET_FLAG(v, const | ae_flag_checked);
nspc_add_value_front(base->e->owner, sym, v);
return v;
ANN static void fptr_assign(const Env env, const Fptr_Def fptr) {
const Func_Def def = fptr->type->e->d.func->def;
if(GET_FLAG(fptr->base->td, global)) {
+ env->context->global = 1;
SET_FLAG(fptr->value, global);
SET_FLAG(fptr->base->func, global);
SET_FLAG(def, global);
}
if(GET_FLAG(def, variadic))
def->stack_depth += SZ_INT;
- fptr->value->owner_class = env->class_def;
+ fptr->value->from->owner_class = env->class_def;
}
static void fptr_def(const Env env, const Fptr_Def fptr) {
CHECK_OB(known_type(env, fptr->base->td))
CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td)));
const m_str name = s_name(fptr->base->xid);
- const Type t = new_type(env->gwion->mp, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]);
+ const Type t = scan0_type(env, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]);
t->e->owner = !(!env->class_def && GET_FLAG(fptr->base->td, global)) ?
env->curr : env->global_nspc;
+ if(GET_FLAG(fptr->base->td, global))
+ env->context->global = 1;
t->nspc = new_nspc(env->gwion->mp, name);
t->flag = fptr->base->td->flag;
fptr->type = t;
fptr->value = mk_class(env, t);
- fptr->value->owner = env->curr;
- fptr->value->owner_class = env->class_def;
+// set owner ?
+ fptr->value->from->owner = env->curr;
+ fptr->value->from->owner_class = env->class_def;
fptr_def(env, fptr);
if(env->class_def)
fptr_assign(env, fptr);
}
ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type base) {
- const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(tdef->xid), base);
+ const Type t = scan0_type(env, ++env->scope->type_xid, s_name(tdef->xid), base);
t->size = base->size;
const Nspc nspc = (!env->class_def && GET_FLAG(tdef->ext, global)) ?
env->global_nspc : env->curr;
+ if(GET_FLAG(tdef->ext, global))
+ env->context->global = 1;
add_type(env, nspc, t);
t->e->owner = nspc;
tdef->type = t;
t->e->parent = env->gwion->type[et_int];
const Nspc nspc = GET_FLAG(edef, global) ? env->global_nspc : env->curr;
t->e->owner = nspc;
+ if(GET_FLAG(edef, global))
+ env->context->global = 1;
edef->t = t;
if(edef->xid) {
add_type(env, nspc, t);
CHECK_BB(env_storage(env, udef->flag, udef->pos))
const m_uint scope = !GET_FLAG(udef, global) ? env->scope->depth :
env_push_global(env);
+ if(GET_FLAG(udef, global))
+ env->context->global = 1;
if(udef->xid) {
CHECK_BB(scan0_defined(env, udef->xid, udef->pos))
const Nspc nspc = !GET_FLAG(udef, global) ?
const Type t = union_type(env, nspc, udef->type_xid ?: udef->xid,
!!udef->type_xid);
udef->value = new_value(env->gwion->mp, t, s_name(udef->xid));
- udef->value->owner_class = env->class_def;
- udef->value->owner = nspc;
+// set owner ?
+ udef->value->from->owner_class = env->class_def;
+ udef->value->from->owner = nspc;
+ udef->value->from->ctx = env->context;
nspc_add_value(nspc, udef->xid, udef->value);
add_type(env, nspc, t);
SET_FLAG(t, scan1 | ae_flag_union);
const Symbol sym = insert_symbol(name);
const Type t = union_type(env, nspc, sym, 1);
udef->value = new_value(env->gwion->mp, t, s_name(sym));
- udef->value->owner_class = env->class_def;
- udef->value->owner = nspc;
+ udef->value->from->owner_class = env->class_def;
+ udef->value->from->owner = nspc;
+ udef->value->from->ctx = env->context;
nspc_add_value(nspc, udef->xid, udef->value);
add_type(env, nspc, t);
SET_FLAG(udef->value, checked | udef->flag);
if(GET_FLAG(cdef, global)) {
vector_add(&env->scope->nspc_stack, (vtype)env->curr);
env->curr = env->global_nspc;
+ env->context->global = 1;
}
CHECK_BB(scan0_defined(env, cdef->base.xid, cdef->pos))
CHECK_BB(isres(env, cdef->base.xid, cdef->pos))
}
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), env->gwion->type[et_object]);
+ const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), env->gwion->type[et_object]);
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;
#include "traverse.h"
#include "template.h"
#include "parse.h"
+#include "context.h"
ANN static m_bool scan1_stmt_list(const Env env, Stmt_List list);
ANN static m_bool scan1_stmt(const Env env, Stmt stmt);
((Exp_Decl*)decl)->type = scan1_exp_decl_type(env, (Exp_Decl*)decl);
CHECK_OB(decl->type)
const m_bool global = GET_FLAG(decl->td, global);
+ if(env->context)
+ env->context->global = 1;
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
const Nspc nspc = !global ? env->curr : env->global_nspc;
do {
if(!env->scope->depth && !env->class_def)
SET_FLAG(v, global);
v->d.ptr = var->addr;
- v->owner = !env->func ? env->curr : NULL;
- v->owner_class = env->scope->depth ? NULL : env->class_def;
+// set from ?
+ v->from->owner = !env->func ? env->curr : NULL;
+ v->from->owner_class = env->scope->depth ? NULL : env->class_def;
+ v->from->ctx = env->context;
} while((list = list->next));
((Exp_Decl*)decl)->type = decl->list->self->value->type;
if(global)
CHECK_BB(already_defined(env, list->xid, edef->pos))
const Value v = new_value(env->gwion->mp, edef->t, s_name(list->xid));
if(env->class_def) {
- v->owner_class = env->class_def;
+ v->from->owner_class = env->class_def;
SET_FLAG(v, static);
SET_ACCESS(edef, v)
}
- v->owner = env->curr;
+// set from ?
+ v->from->owner = env->curr;
+ v->from->ctx = env->context;
SET_FLAG(v, const | ae_flag_enum | ae_flag_checked);
nspc_add_value(edef->t->e->owner, list->xid, v);
vector_add(&edef->values, (vtype)v);
if(var->array)
list->type = array_type(env, list->type, var->array->depth);
var->value = arg_value(env->gwion->mp, list);
- var->value->offset = f->stack_depth;
+ var->value->from->offset = f->stack_depth;
f->stack_depth += list->type->size;
} while((list = list->next));
return GW_OK;
ANN static Value scan2_func_assign(const Env env, const Func_Def d,
const Func f, const Value v) {
- v->owner = env->curr;
+// set from ?
+ v->from->owner = env->curr;
+ v->from->ctx = env->context;
SET_FLAG(v, func | ae_flag_const);
- if(!(v->owner_class = env->class_def))
+ if(!(v->from->owner_class = env->class_def))
SET_FLAG(v, global);
else {
if(GET_FLAG(f, member))
nspc_add_value(env->curr, f->base->xid, value);
nspc_add_func(env->curr, f->base->xid, func);
} else
- func->vt_index = ++overload->offset;
+ func->vt_index = ++overload->from->offset;
return GW_OK;
}
ANN2(1,2) static m_str func_name(const Env env, const Func_Def f, const Value v) {
if(!f->base->tmpl) {
- const Symbol sym = func_symbol(env, env->curr->name, s_name(f->base->xid), NULL, v ? ++v->offset : 0);
+ const Symbol sym = func_symbol(env, env->curr->name, s_name(f->base->xid), NULL, v ? ++v->from->offset : 0);
return s_name(sym);
}
return template_helper(env, f);
const Value value = new_value(env->gwion->mp, ret, s_name(sym));
func->flag = def->flag;
value->d.func_ref = func;
- value->owner = t->e->owner;
- value->owner_class = t->e->d.func->value_ref->owner_class;
+ value->from->owner = t->e->owner;
+ value->from->owner_class = t->e->d.func->value_ref->from->owner_class;
func->value_ref = value;
func->def->base->tmpl = mk_tmpl(env, t, t->e->d.func->def->base->tmpl, type->types);
def->base->func = func;
#include "traverse.h"
#include "parse.h"
+#include "context.h"
+
#define STR_NONNULL ":nonnull"
#define STRLEN_NONNULL strlen(STR_NONNULL)
ANN Type type_decl_resolve(const Env env, const Type_Decl* td) {
DECL_OO(const Type, base, = find_type(env, td->xid))
+ if(base->e->ctx && base->e->ctx->error)
+ ERR_O(td_pos(td), _("type '%s' is invalid"), base->name)
DECL_OO(const Type, t, = scan_type(env, base, td))
const Type ret = !td->array ? t : array_type(env, t, td->array->depth);
if(GET_FLAG(td, nonnull)) {
-Subproject commit 3d2be8fdf552bdded221ddb266d55043c288da4a
+Subproject commit dee77e5c3be6b2bcecd77929a21b5057ac5af5ce