-Subproject commit a51a9510d347dabad49ff8dc7eb0339aaae5192d
+Subproject commit 003e72af4ededf99627521dd0f61547ce26edcdb
}
ANN static inline Exp dot_this_exp(const Emitter emit, const Exp_Primary* prim, const Type t) {
- const Exp exp = this_exp(emit, t, prim->self->pos);
+ const Exp exp = this_exp(emit, t, exp_self(prim)->pos);
const Exp dot = new_exp_dot(emit->gwion->p, exp, prim->d.var);
dot->d.exp_dot.t_base = t;
return dot;
ANN static inline Exp dot_static_exp(const Emitter emit, const Exp_Primary* prim, const Type t) {
const Symbol s = insert_symbol(t->name);
- const Exp e = new_exp_prim_id(emit->gwion->p, s, prim->self->pos);
+ const Exp e = new_exp_prim_id(emit->gwion->p, s, exp_self(prim)->pos);
const Value val = nspc_lookup_value1(t->nspc->parent, s);
const Exp dot = new_exp_dot(emit->gwion->p, e, prim->d.var);
dot->d.exp_dot.t_base = val->type;
const Value v = prim->value;
const Exp dot = (!GET_FLAG(v, static) ? dot_this_exp : dot_static_exp)(emit, prim, v->owner_class);
dot->type = v->type;
- dot->emit_var = prim->self->emit_var;
+ dot->emit_var = exp_self(prim)->emit_var;
const m_bool ret = emit_exp_dot(emit, &dot->d.exp_dot);
free_exp(emit->gwion->p, dot);
return ret;
}
if(GET_FLAG(v, union)) {
const m_uint size = v->type->size;
- const Instr instr = emit_kind(emit, size, prim->self->emit_var, dotstatic);
+ const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, dotstatic);
instr->m_val = (m_uint)v->d.ptr;
} else {
const m_uint size = v->type->size;
- const Instr instr = emit_kind(emit, size, prim->self->emit_var, regpushimm);
- if(!prim->self->emit_var && size == SZ_INT) {
+ const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, regpushimm);
+ if(!exp_self(prim)->emit_var && size == SZ_INT) {
if(isa(v->type, t_object) > 0) {
instr->execute = RegPushImm;
instr->m_val = (m_uint)v->d.ptr;
if(GET_FLAG(v, builtin) || GET_FLAG(v, union) || GET_FLAG(v, enum))
return emit_symbol_builtin(emit, prim);
const m_uint size = v->type->size;
- const Instr instr = emit_kind(emit, size, prim->self->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase);
+ const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase);
instr->m_val = v->offset;
return GW_OK;
}
}
ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array* array) { GWDEBUG_EXE
- const m_uint is_var = array->self->emit_var;
- const m_uint depth = get_depth(array->base->type) - array->self->type->array_depth;
+ const m_uint is_var = exp_self(array)->emit_var;
+ const m_uint depth = get_depth(array->base->type) - exp_self(array)->type->array_depth;
CHECK_BB(emit_exp(emit, array->base, 0))
CHECK_BB(emit_exp(emit, array->array->exp, 0))
const Instr pop = emit_add_instr(emit, RegPop);
const Instr get = emit_add_instr(emit, is_var ? ArrayAddr : ArrayGet);
get->m_val = depth;
const Instr push = emit_add_instr(emit, ArrayValid);
- push->m_val = is_var ? SZ_INT : array->self->type->size;
+ push->m_val = is_var ? SZ_INT : exp_self(array)->type->size;
return GW_OK;
}
m_int n = (m_int)((t == ae_primary_vec ? 3 : 2) - vec->dim + 1);
while(--n > 0)
emit_add_instr(emit, RegPushImm2);
- if(primary->self->emit_var) {
- emit_local(emit, primary->self->type->size, 0);
+ if(exp_self(primary)->emit_var) {
+ emit_local(emit, exp_self(primary)->type->size, 0);
const m_uint offset = emit_local(emit, SZ_INT, 0);
const Instr cpy = emit_add_instr(emit, VecCpy);
cpy->m_val = offset;
- cpy->m_val2 = primary->self->type->size;
+ cpy->m_val2 = exp_self(primary)->type->size;
const Instr instr = emit_add_instr(emit, RegPushMem);
instr->m_val = offset;
}
}
ANN static m_bool prim_char(const Emitter emit, const Exp_Primary* prim) {
- const m_int c = str2char(emit, prim->d.chr, prim->self->pos);
+ const m_int c = str2char(emit, prim->d.chr, exp_self(prim)->pos);
CHECK_BB(c);
const Instr instr = emit_add_instr(emit, RegPushImm);
instr->m_val = (m_uint)c;
char c[strlen(prim->d.str) + 1];
if(strlen(prim->d.str)) {
strcpy(c, prim->d.str);
- CHECK_BB(escape_str(emit, c, prim->self->pos));
+ CHECK_BB(escape_str(emit, c, exp_self(prim)->pos));
} else c[0] = '\0';
const Instr instr = emit_add_instr(emit, RegPushStr);
instr->m_val = (m_uint)s_name(insert_symbol(c));
ANN static m_bool emit_exp_decl(const Emitter emit, const Exp_Decl* decl) { GWDEBUG_EXE
Var_Decl_List list = decl->list;
const uint ref = GET_FLAG(decl->td, ref) || type_ref(decl->type);
- const uint var = decl->self->emit_var;
+ const uint var = exp_self(decl)->emit_var;
if(GET_FLAG(decl->type, template))
CHECK_BB(emit_exp_decl_template(emit, decl))
}
ANN static m_bool emit_exp_cast(const Emitter emit, const Exp_Cast* cast) {
- struct Op_Import opi = { .op=op_cast, .lhs=cast->exp->type, .rhs=cast->self->type, .data=(uintptr_t)cast};
+ struct Op_Import opi = { .op=op_cast, .lhs=cast->exp->type, .rhs=exp_self(cast)->type, .data=(uintptr_t)cast};
CHECK_BB(emit_exp(emit, cast->exp, 0))
(void)op_emit(emit, &opi);
return GW_OK;
const m_uint depth) {
const m_uint member = GET_FLAG(code, member) ? SZ_INT : 0;
const Instr pop = emit_add_instr(emit, RegPop);
- pop->m_val = depth + member;
+ pop->m_val = depth + member;// + emit->code->stack_depth;
if(depth) {
const Instr spork = emit_add_instr(emit, SporkFunc);
spork->m_val = depth;
if(unary->code) {
const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd);
spork->m_val = emit->code->stack_depth;
-// emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd);
} else {
const Func f = unary->exp->d.exp_call.m_func;
const m_uint size = f->def->stack_depth - (GET_FLAG(f, member) ? SZ_INT : 0);
Instr op = NULL;
emit_push_stack(emit);
if(!stmt->is_do)
- op = _flow(emit, stmt->cond, stmt->self->stmt_type == ae_stmt_while);
+ op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type == ae_stmt_while);
CHECK_BB(scoped_stmt(emit, stmt->body, 1))
if(stmt->is_do) {
- CHECK_OB((op = _flow(emit, stmt->cond, stmt->self->stmt_type != ae_stmt_while)))
+ CHECK_OB((op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type != ae_stmt_while)))
op->m_val = index;
} else {
const Instr goto_ = emit_add_instr(emit, Goto);
if(!stmt->is_label)
stmt->data.instr = emit_add_instr(emit, Goto);
else {
- if(switch_inside(emit->env, stmt->self->pos) && !strcmp(s_name(stmt->name), "default")) {
+ if(switch_inside(emit->env, stmt_self(stmt)->pos) && !strcmp(s_name(stmt->name), "default")) {
if(!strcmp(s_name(stmt->name), "default"))
vector_release(&stmt->data.v);
- return switch_default(emit->env, emit_code_size(emit), stmt->self->pos);
+ return switch_default(emit->env, emit_code_size(emit), stmt_self(stmt)->pos);
}
if(!stmt->data.v.ptr)
- ERR_B(stmt->self->pos, "illegal case")
+ ERR_B(stmt_self(stmt)->pos, "illegal case")
const m_uint size = vector_size(&stmt->data.v);
if(!size) {
vector_release(&stmt->data.v);
- ERR_B(stmt->self->pos, "label '%s' defined but not used.", s_name(stmt->name))
+ ERR_B(stmt_self(stmt)->pos, "label '%s' defined but not used.", s_name(stmt->name))
}
LOOP_OPTIM
for(m_uint i = size + 1; --i;) {
const Stmt_Jump label = (Stmt_Jump)vector_at(&stmt->data.v, i - 1);
if(!label->data.instr) {
vector_release(&stmt->data.v);
- ERR_B(label->self->pos, "you are trying to use a upper label.")
+ ERR_B(stmt_self(label)->pos, "you are trying to use a upper label.")
}
label->data.instr->m_val = emit_code_size(emit);
}
}
ANN static m_bool emit_stmt_case(const Emitter emit, const Stmt_Exp stmt) { GWDEBUG_EXE
- CHECK_BB(switch_inside(emit->env, stmt->self->pos))
+ CHECK_BB(switch_inside(emit->env, stmt_self(stmt)->pos))
m_int value = 0;
const Value v = case_value(stmt->val);
if((!v && prim_value(stmt->val, &value)) || value_value(v, &value)) {
stmt->value->type->nspc->info->offset = stmt->s;
if(!stmt->value->type->p)
stmt->value->type->p = mp_ini(emit->gwion->p, (uint32_t)stmt->value->type->size);
- Type_Decl *type_decl = new_type_decl(emit->gwion->p, new_id_list(emit->gwion->p, stmt->xid, stmt->self->pos),
+ Type_Decl *type_decl = new_type_decl(emit->gwion->p, new_id_list(emit->gwion->p, stmt->xid, stmt_self(stmt)->pos),
emit->env->class_def ? ae_flag_member : 0);
type_decl->flag = stmt->flag;// ???
const Var_Decl var_decl = new_var_decl(emit->gwion->p, stmt->xid, NULL, 0);
CHECK_BB(emit_exp(emit, base, 0))
const m_bool is_complex = !strcmp((isa(base->type, t_complex) > 0 ? "re" : "phase") ,
s_name(member->xid));
- if(is_complex && member->self->emit_var)
+ if(is_complex && exp_self(member)->emit_var)
return GW_OK;
const Instr instr = emit_add_instr(emit, is_complex ? ComplexReal : ComplexImag);
- instr->m_val = member->self->emit_var;
+ instr->m_val = exp_self(member)->emit_var;
return GW_OK;
}
emit_vec_func(emit, v);
return GW_OK;
}
- if(!v->offset && member->self->emit_var)
+ if(!v->offset && exp_self(member)->emit_var)
return GW_OK;
const Instr instr = emit_add_instr(emit, VecMember);
instr->m_val2 = v->offset;
- instr->m_val = member->self->emit_var;
+ instr->m_val = exp_self(member)->emit_var;
return GW_OK;
}
return emit_vararg_end(emit, offset);
const Instr instr = emit_add_instr(emit, VarargMember);
instr->m_val = offset;
- instr->m_val2 = member->self->type->size;
+ instr->m_val2 = exp_self(member)->type->size;
return GW_OK;
}
emit_add_instr(emit, GWOP_EXCEPT);
}
const Value value = find_value(actual_type(member->t_base), member->xid);
- if(isa(member->self->type, t_function) > 0 && isa(member->self->type, t_fptr) < 0)
+ if(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0)
return emit_member_func(emit, member, value->d.func_ref);
- return (GET_FLAG(value, member) ? emit_member : emit_dot_static_import_data) (emit, value, member->self->emit_var);
+ return (GET_FLAG(value, member) ? emit_member : emit_dot_static_import_data) (emit, value, exp_self(member)->emit_var);
}
ANN static inline void emit_func_def_global(const Emitter emit, const Value value) { GWDEBUG_EXE
const Type l = get_array_type(bin->lhs->type); \
const Type r = get_array_type(bin->rhs->type); \
if(isa(l, r) < 0) \
- ERR_N(bin->self->pos, "array types do not match.")
+ ERR_N(exp_self(bin)->pos, "array types do not match.")
static OP_CHECK(opck_array_at) {
ARRAY_OPCK
if(bin->lhs->type->array_depth != bin->rhs->type->array_depth)
- ERR_N(bin->self->pos, "array depths do not match.")
+ ERR_N(exp_self(bin)->pos, "array depths do not match.")
bin->rhs->emit_var = 1;
return bin->rhs->type;
}
static OP_CHECK(opck_array_cast) {
const Exp_Cast* cast = (Exp_Cast*)data;
Type l = cast->exp->type;
- Type r = cast->self->type;
+ Type r = exp_self(cast)->type;
while(!l->d.base_type)
l = l->parent;
while(!r->d.base_type)
static OP_CHECK(opck_func_call) {
Exp_Binary* bin = (Exp_Binary*)data;
- Exp_Call call = { .func=bin->rhs, .args=bin->lhs, .self=bin->self };
- Exp e = bin->self;
+ Exp_Call call = { .func=bin->rhs, .args=bin->lhs };
+ Exp e = exp_self(bin);
e->exp_type = ae_exp_call;
memcpy(&e->d.exp_call, &call, sizeof(Exp_Call));
return check_exp_call1(env, &e->d.exp_call);
arg = arg->next;
}
if(base || arg)
- ERR_B(l->self->pos, "argument number does not match for lambda")
+ ERR_B(exp_self(l)->pos, "argument number does not match for lambda")
l->def = new_func_def(env->gwion->p, new_func_base(env->gwion->p, def->base->td, l->name, l->args), l->code, def->flag);
const m_bool ret = traverse_func_def(env, l->def);
arg = l->args;
const Func_Def r_fdef = r_func->def;
const Type r_type = r_func->value_ref->owner_class;
if(!r_type && l_type)
- ERR_N(bin->self->pos, "can't assign member function to non member function pointer")
+ ERR_N(exp_self(bin)->pos, "can't assign member function to non member function pointer")
else if(r_type && !l_type) {
if(!GET_FLAG(r_func, global))
- ERR_N(bin->self->pos, "can't assign non member function to member function pointer")
+ ERR_N(exp_self(bin)->pos, "can't assign non member function to member function pointer")
} else if(r_type && isa(r_type, l_type) < 0)
- ERR_N(bin->self->pos, "can't assign member function to member function pointer"
+ ERR_N(exp_self(bin)->pos, "can't assign member function to member function pointer"
" of an other class")
if(GET_FLAG(r_func, member)) {
if(!GET_FLAG(l_func, member))
- ERR_N(bin->self->pos, "can't assign static function to member function pointer")
+ ERR_N(exp_self(bin)->pos, "can't assign static function to member function pointer")
} else if(GET_FLAG(l_func, member))
- ERR_N(bin->self->pos, "can't assign member function to static function pointer")
+ ERR_N(exp_self(bin)->pos, "can't assign member function to static function pointer")
if(isa(r_fdef->base->ret_type, l_fdef->base->ret_type) < 0)
- ERR_N(bin->self->pos, "return type '%s' does not match '%s'\n\t... in pointer assignement",
+ ERR_N(exp_self(bin)->pos, "return type '%s' does not match '%s'\n\t... in pointer assignement",
r_fdef->base->ret_type->name, l_fdef->base->ret_type->name)
if(GET_FLAG(l_fdef, variadic) != GET_FLAG(r_fdef, variadic))
- ERR_N(bin->self->pos, "function must be of same argument kind.",
+ ERR_N(exp_self(bin)->pos, "function must be of same argument kind.",
r_fdef->base->ret_type->name, l_fdef->base->ret_type->name)
if(isa(bin->lhs->type, t_fptr) > 0 && isa(bin->lhs->type, bin->rhs->type) > 0)
return bin->rhs->type;
static OP_CHECK(opck_fptr_cast) {
Exp_Cast* cast = (Exp_Cast*)data;
- const Type t = cast->self->type;
+ const Type t = exp_self(cast)->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 ?
CHECK_BO(check_stmt(env, unary->code))
return unary->op == op_spork ? t_shred : t_fork;
} else
- ERR_O(unary->self->pos, "only function calls can be sporked...")
+ ERR_O(exp_self(unary)->pos, "only function calls can be sporked...")
return NULL;
}
v->exp.exp_type = ae_exp_decl;
v->exp.d.exp_decl.td = &v->t;
v->exp.d.exp_decl.list = &v->list;
- v->exp.d.exp_decl.self = &v->exp;
if(v->array_depth)
dl_var_new_exp_array(p, v);
}
if(bin->rhs->exp_type == ae_exp_decl)
SET_FLAG(bin->rhs->d.exp_decl.td, ref);
if(l != t_null && isa(l, r) < 0)
- ERR_N(bin->self->pos, "'%s' @=> '%s': not allowed", l->name, r->name)
+ ERR_N(exp_self(bin)->pos, "'%s' @=> '%s': not allowed", l->name, r->name)
bin->rhs->emit_var = 1;
return r;
}
static OP_CHECK(opck_object_cast) {
const Exp_Cast* cast = (Exp_Cast*)data;
const Type l = cast->exp->type;
- const Type r = cast->self->type;
+ const Type r = exp_self(cast)->type;
// return isa(l, r) > 0 ? r : t_null;
if(isa(l, r) > 0) {
const Type t = type_copy(env->gwion->p, r);
OP_CHECK(opck_basic_cast) {
const Exp_Cast* cast = (Exp_Cast*)data;
- return cast->self->type;
+ return exp_self(cast)->type;
}
OP_EMIT(opem_basic_cast) {
OP_CHECK(opck_const_rhs) {
const Exp_Binary* bin = (Exp_Binary*)data;
if(bin->rhs->meta != ae_meta_var)
- ERR_N(bin->self->pos, "cannot assign '%s' on types '%s' and '%s'.\n"
+ ERR_N(exp_self(bin)->pos, "cannot assign '%s' on types '%s' and '%s'.\n"
"\t...\t(reason: --- right-side operand is %s.)",
op2str(bin->op), bin->lhs->type->name, bin->rhs->type->name,
access(bin->rhs->meta))
OP_CHECK(opck_unary_meta) {
const Exp_Unary* unary = (Exp_Unary*)data;
- unary->self->meta = ae_meta_value;
+ exp_self(unary)->meta = ae_meta_value;
return unary->exp->type;
}
"unary operator '%s' cannot be used on %s data-types.",
op2str(unary->op), access(unary->exp->meta))
unary->exp->emit_var = 1;
- unary->self->meta = ae_meta_value;
+ exp_self(unary)->meta = ae_meta_value;
return unary->exp->type;
}
ERR_N(post->exp->pos, "post operator '%s' cannot be used on %s data-type.",
op2str(post->op), access(post->exp->meta))
post->exp->emit_var = 1;
- post->self->meta = ae_meta_value;
+ exp_self(post)->meta = ae_meta_value;
return post->exp->type;
}
OP_EMIT(opem_new) {
const Exp_Unary* unary = (Exp_Unary*)data;
- CHECK_BB(emit_instantiate_object(emit, unary->self->type,
+ CHECK_BB(emit_instantiate_object(emit, exp_self(unary)->type,
unary->td->array, GET_FLAG(unary->td, ref)))
CHECK_OB(emit_add_instr(emit, GcAdd))
return GW_OK;
OP_CHECK(opck_unary_meta2) {
const Exp_Unary* unary = (Exp_Unary*)data;
- unary->self->meta = ae_meta_value;
+ exp_self(unary)->meta = ae_meta_value;
return t_int;
}
static OP_CHECK(opck_chuck_now) {
Exp_Binary* bin = (Exp_Binary*)data;
- ERR_O(bin->self->pos, "can't assign 'now' to 'now'")
+ ERR_O(exp_self(bin)->pos, "can't assign 'now' to 'now'")
return NULL;
}
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
- unary->self->type = nspc_lookup_type1(unary->exp->type->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
- return unary->self->type;
+ 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)));
+ return exp_self(unary)->type;
}
static OP_CHECK(opck_implicit_ptr) {
static OP_EMIT(opem_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
const Instr instr = emit_add_instr(emit, instr_ptr_deref);
- instr->m_val = unary->self->type->size;
- instr->m_val2 = unary->self->emit_var;
+ instr->m_val = exp_self(unary)->type->size;
+ instr->m_val2 = exp_self(unary)->emit_var;
return GW_OK;
}
#define OP_RET(a, b)\
const Type op_ret = op_check(env, &opi);\
if(!op_ret)\
- ERR_O(a->self->pos, "in %s expression", b)\
+ ERR_O(exp_self(a)->pos, "in %s expression", b)\
return op_ret;
ANN static Type check_exp(const Env env, Exp exp);
const Array_Sub array = primary->d.array;
const Exp e = array->exp;
if(!e)
- ERR_O(primary->self->pos, "must provide values/expressions for array [...]")
+ ERR_O(exp_self(primary)->pos, "must provide values/expressions for array [...]")
CHECK_OO(check_exp(env, e))
return (array->type = prim_array_match(env, e));
}
if(env->class_def) {
const Value v = value ? value : find_value(env->class_def, primary->d.var);
if(v && SAFE_FLAG(env->func, static) && GET_FLAG(v, member))
- ERR_O(primary->self->pos,
+ ERR_O(exp_self(primary)->pos,
"non-static member '%s' used from static function.", s_name(primary->d.var))
return v;
} else if(env->func && GET_FLAG(env->func->def, global)) {
if(!SAFE_FLAG(value, abstract) && !SAFE_FLAG(value, arg))
- ERR_O(primary->self->pos,
+ ERR_O(exp_self(primary)->pos,
"non-global variable '%s' used from global function.", s_name(primary->d.var))
}
return value;
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)) {
- err_msg(primary->self->pos,
+ err_msg(exp_self(primary)->pos,
"variable %s not legit at this point.", s_name(primary->d.var));
did_you_mean(env->gwion->st, s_name(primary->d.var));
return NULL;
SET_FLAG(v, used);
((Exp_Primary*)primary)->value = v;
if(GET_FLAG(v, const) || !strcmp(s_name(primary->d.var), "maybe"))
- primary->self->meta = ae_meta_value;
+ exp_self(primary)->meta = ae_meta_value;
return v->type;
}
ANN static Type check_exp_prim_this(const Env env, const Exp_Primary* primary) {
if(!env->class_def)
- ERR_O(primary->self->pos, "keyword 'this' can be used only inside class definition...")
+ ERR_O(exp_self(primary)->pos, "keyword 'this' can be used only inside class definition...")
if(env->func && !GET_FLAG(env->func, member))
- ERR_O(primary->self->pos, "keyword 'this' cannot be used inside static functions...")
- primary->self->meta = ae_meta_value;
+ ERR_O(exp_self(primary)->pos, "keyword 'this' cannot be used inside static functions...")
+ exp_self(primary)->meta = ae_meta_value;
return env->class_def;
}
};
ANN static Type check_exp_primary(const Env env, const Exp_Primary* primary) { GWDEBUG_EXE
- return primary->self->type = prim_func[primary->primary_type](env, primary);
+ return exp_self(primary)->type = prim_func[primary->primary_type](env, primary);
}
ANN Type check_exp_array(const Env env, const Exp_Array* array) { GWDEBUG_EXE
depth, e->type->name)
} while((e = e->next) && ++depth);
if(depth != array->array->depth)
- ERR_O(array->self->pos, "invalid array acces expression.")
+ ERR_O(exp_self(array)->pos, "invalid array acces expression.")
while(t_base && array->array->depth > t_base->array_depth) {
depth -= t_base->array_depth;
if(t_base->parent)
t_base = t_base->parent;
else
- ERR_O(array->self->pos,
+ ERR_O(exp_self(array)->pos,
"array subscripts (%i) exceeds defined dimension (%i)",
array->array->depth, t_base->array_depth)
}
next:
t = t->parent;
}
- assert(exp->self);
- err_msg(exp->self->pos, "arguments do not match for template call");
+ assert(exp_self(exp));
+ err_msg(exp_self(exp)->pos, "arguments do not match for template call");
return NULL;
}
-
ANN static void print_current_args(Exp e) {
gw_err("and not\n\t");
do gw_err(" \033[32m%s\033[0m", e->type->name);
if(f) {
Tmpl_Call* tmpl = new_tmpl_call(env->gwion->p, func->tmpl->types);
tmpl->base = v->d.func_ref->def->tmpl->list;
- func->self->d.exp_call.tmpl = tmpl;
- return f;
+ ((Exp_Call*)func)->tmpl = tmpl;
+ return ((Exp_Call*)func)->m_func = f;
}
- assert(func->self);
- ERR_O(func->self->pos,
+ ((Exp_Call*)func)->tmpl = NULL;
+ assert(exp_self(func));
+ ERR_O(exp_self(func)->pos,
"function is template. automatic type guess not fully implemented yet.\n"
"\tplease provide template types. eg: '<type1, type2, ...>'")
}
ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) {
const Exp call = exp->func;
const Exp args = exp->args;
- const Exp base = exp->self;
m_uint args_number = 0;
const Value value = nspc_lookup_value1(call->type->owner, insert_symbol(call->type->name));
CHECK_OO(value)
if(args_number < type_number)
ERR_O(call->pos, "not able to guess types for template call.")
Tmpl_Call tmpl = { .types=tl[0] };
- const Exp_Call tmp_func = { .func=call, .args=args, .tmpl=&tmpl, .self=base };
- const Func func = get_template_func(env, &tmp_func, value);
- base->d.exp_call.m_func = func;
+ ((Exp_Call*)exp)->tmpl = &tmpl;
+ const Func func = get_template_func(env, exp, value);
return func ? func->def->base->ret_type : NULL;
}
e = e->next;
}
if(arg || e)
- ERR_O(exp->self->pos, "argument number does not match for lambda")
+ ERR_O(exp_self(exp)->pos, "argument number does not match for lambda")
l->def = new_func_def(env->gwion->p, new_func_base(env->gwion->p, NULL, l->name, l->args), l->code, 0);
CHECK_BO(traverse_func_def(env, l->def))
if(env->class_def)
SET_FLAG(l->def, member);
- exp->self->d.exp_call.m_func = l->def->base->func;
+ ((Exp_Call*)exp)->m_func = l->def->base->func;
return l->def->base->ret_type ?: (l->def->base->ret_type = t_void);
}
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);
- return (exp->self->d.exp_call.m_func = func) ?
+ return (exp_self(exp)->d.exp_call.m_func = func) ?
func->def->base->ret_type : function_alternative(exp->func->type, exp->args);
}
ANN static Type check_exp_cast(const Env env, const Exp_Cast* cast) { GWDEBUG_EXE
const Type t = check_exp(env, cast->exp);
CHECK_OO(t)
- CHECK_OO((cast->self->type = known_type(env, cast->td)))
- struct Op_Import opi = { .op=op_cast, .lhs=t, .rhs=cast->self->type, .data=(uintptr_t)cast };
+ CHECK_OO((exp_self(cast)->type = known_type(env, cast->td)))
+ struct Op_Import opi = { .op=op_cast, .lhs=t, .rhs=exp_self(cast)->type, .data=(uintptr_t)cast };
OP_RET(cast, "cast")
}
const Type t = actual_type(exp->func->type);
const Value v = nspc_lookup_value1(t->owner, insert_symbol(t->name));
if(!v)
- ERR_O(exp->self->pos, " template call of non-existant function.")
+ ERR_O(exp_self(exp)->pos, " template call of non-existant function.")
if(!GET_FLAG(v, func))
- ERR_O(exp->self->pos, "template call of non-function value.")
+ ERR_O(exp_self(exp)->pos, "template call of non-function value.")
if(!v->d.func_ref->def->tmpl)
- ERR_O(exp->self->pos, "template call of non-template function.")
+ ERR_O(exp_self(exp)->pos, "template call of non-template function.")
const Func ret = find_template_match(env, v, exp);
CHECK_OO((exp->m_func = ret))
return ret->def->base->ret_type;
const Type else_exp = check_exp(env, exp_if->else_exp);
CHECK_OO(else_exp)
if(isa(cond, t_int) < 0 && isa(cond, t_float) < 0 && isa(cond, t_object) < 0)
- ERR_O(exp_if->self->pos,
+ ERR_O(exp_self(exp_if)->pos,
"Invalid type '%s' in if expression condition.", cond->name)
const Type ret = find_common_anc(if_exp, else_exp);
if(!ret)
- ERR_O(exp_if->self->pos,
+ ERR_O(exp_self(exp_if)->pos,
"incompatible types '%s' and '%s' in if expression...",
if_exp->name, else_exp->name)
return ret;
"type '%s' does not have members - invalid use in dot expression of %s",
the_base->name, str)
if(!strcmp(str, "this") && base_static)
- ERR_O(member->self->pos,
+ ERR_O(exp_self(member)->pos,
"keyword 'this' must be associated with object instance...")
const Value value = find_value(the_base, member->xid);
if(!value)
"class '%s' has no member '%s'", the_base->name, str)
if(!env->class_def || isa(env->class_def, value->owner_class) < 0) {
if(GET_FLAG(value, private))
- ERR_O(member->self->pos,
+ ERR_O(exp_self(member)->pos,
"can't access private '%s' outside of class...", value->name)
else if(GET_FLAG(value, protect))
- member->self->meta = ae_meta_protect;
+ exp_self(member)->meta = ae_meta_protect;
}
if(base_static && GET_FLAG(value, member))
- ERR_O(member->self->pos,
+ ERR_O(exp_self(member)->pos,
"cannot access member '%s.%s' without object instance...",
the_base->name, str)
if(GET_FLAG(value, const) || GET_FLAG(value, enum))
- member->self->meta = ae_meta_value;
+ exp_self(member)->meta = ae_meta_value;
return value->type;
}
ANN static inline m_bool for_empty(const Stmt_For stmt) {
if(!stmt->c2 || !stmt->c2->d.stmt_exp.val)
- ERR_B(stmt->self->pos, "empty for loop condition...",
+ ERR_B(stmt_self(stmt)->pos, "empty for loop condition...",
"...(note: explicitly use 'true' if it's the intent)",
"...(e.g., 'for(; true;){ /*...*/ }')")
return GW_OK;
if(GET_FLAG(t, typedef))
t = t->parent;
if(!t || !ptr || isa(t, t_array) < 0)
- ERR_B(stmt->self->pos, "type '%s' is not array.\n"
+ ERR_B(stmt_self(stmt)->pos, "type '%s' is not array.\n"
" This is not allowed in auto loop", stmt->exp->type->name)
if(stmt->is_ptr) {
struct ID_List_ id0, id;
stmt->v = new_value(env->gwion->p, t, s_name(stmt->sym));
SET_FLAG(stmt->v, checked);
nspc_add_value(env->curr, stmt->sym, stmt->v);
- return check_conts(env, stmt->self, stmt->body);
+ return check_conts(env, stmt_self(stmt), stmt->body);
}
ANN static m_bool cond_type(const Exp e) {
(stmt->else_body && check_stmt(env, stmt->else_body) < 0)) ? 1 : -1)
stmt_func_xxx(flow, Stmt_Flow,,
!(!check_exp(env, stmt->cond) ||
- check_flow(stmt->cond, stmt->self->stmt_type == ae_stmt_while ? "while" : "until") < 0 ||
- check_conts(env, stmt->self, stmt->body) < 0) ? 1 : -1)
+ check_flow(stmt->cond, stmt_self(stmt)->stmt_type == ae_stmt_while ? "while" : "until") < 0 ||
+ check_conts(env, stmt_self(stmt), stmt->body) < 0) ? 1 : -1)
stmt_func_xxx(for, Stmt_For,, !(
for_empty(stmt) < 0 ||
check_stmt(env, stmt->c1) < 0 ||
check_stmt(env, stmt->c2) < 0 ||
check_flow(stmt->c2->d.stmt_exp.val, "for") < 0 ||
(stmt->c3 && !check_exp(env, stmt->c3)) ||
- check_conts(env, stmt->self, stmt->body) < 0) ? 1 : -1)
+ check_conts(env, stmt_self(stmt), stmt->body) < 0) ? 1 : -1)
stmt_func_xxx(loop, Stmt_Loop,, !(!check_exp(env, stmt->cond) ||
cond_type(stmt->cond) < 0 ||
- check_conts(env, stmt->self, stmt->body) < 0) ? 1 : -1)
+ check_conts(env, stmt_self(stmt), stmt->body) < 0) ? 1 : -1)
stmt_func_xxx(switch, Stmt_Switch,, !(!check_exp(env, stmt->val) ||
cond_type(stmt->val) < 0 || !switch_add(env, stmt) ||
- check_breaks(env, stmt->self, stmt->stmt) < 0 || !switch_pop(env)) ? 1 : -1)
+ check_breaks(env, stmt_self(stmt), stmt->stmt) < 0 || !switch_pop(env)) ? 1 : -1)
stmt_func_xxx(auto, Stmt_Auto,, do_stmt_auto(env, stmt))
ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { GWDEBUG_EXE
if(!env->func)
- ERR_B(stmt->self->pos, "'return' statement found outside function definition")
+ ERR_B(stmt_self(stmt)->pos, "'return' statement found outside function definition")
const Type ret_type = stmt->val ? check_exp(env, stmt->val) : t_void;
CHECK_OB(ret_type)
if(env->func->value_ref->type == t_lambda) {
if(env->func->def->base->ret_type &&
isa(ret_type, env->func->def->base->ret_type) < 0 &&
isa(env->func->def->base->ret_type, ret_type) < 0)
- ERR_B(stmt->self->pos, "return types do not match for lambda expression")
+ ERR_B(stmt_self(stmt)->pos, "return types do not match for lambda expression")
env->func->value_ref->type = ret_type;
return GW_OK;
}
isa(env->func->def->base->ret_type, t_object) > 0)
return GW_OK;
if(env->func->def->base->ret_type && isa(ret_type, env->func->def->base->ret_type) < 0)
- ERR_B(stmt->self->pos, "invalid return type '%s' -- expecting '%s'",
+ ERR_B(stmt_self(stmt)->pos, "invalid return type '%s' -- expecting '%s'",
ret_type->name, env->func->def->base->ret_type->name)
else //! set default return type for lambdas
env->func->def->base->ret_type = ret_type;
const Type t = check_exp(env, stmt->val);
CHECK_OB(t);
if(isa(t, t_int) < 0)
- ERR_B(stmt->self->pos, "invalid type '%s' case expression. should be 'int'", t->name)
+ ERR_B(stmt_self(stmt)->pos, "invalid type '%s' case expression. should be 'int'", t->name)
const Value v = case_value(stmt->val);
if(!v)
return GW_OK;
(m_uint*)env->class_def : (m_uint*)env->func;
const Map m = label->ptr ? (Map)map_get(label, (vtype)key) : NULL;
if(!m)
- ERR_B(stmt->self->pos, "label '%s' used but not defined", s_name(stmt->name))
+ ERR_B(stmt_self(stmt)->pos, "label '%s' used but not defined", s_name(stmt->name))
const Stmt_Jump ref = (Stmt_Jump)map_get(m, (vtype)stmt->name);
if(!ref) {
for(m_uint i = 0; i < map_size(m); ++i) {
const Stmt_Jump s = (Stmt_Jump)map_at(m, i);
vector_release(&s->data.v);
}
- ERR_B(stmt->self->pos, "label '%s' used but not defined", s_name(stmt->name))
+ ERR_B(stmt_self(stmt)->pos, "label '%s' used but not defined", s_name(stmt->name))
}
vector_add(&ref->data.v, (vtype)stmt);
return GW_OK;
if(stmt->xid) {
const Value v = nspc_lookup_value1(env->curr, stmt->xid);
if(v)
- ERR_B(stmt->self->pos, "'%s' already declared as variable of type '%s'.",
+ ERR_B(stmt_self(stmt)->pos, "'%s' already declared as variable of type '%s'.",
s_name(stmt->xid), v->type->name)
- CHECK_BB(scan0_defined(env, stmt->xid, stmt->self->pos)) // test for type ?
+ CHECK_BB(scan0_defined(env, stmt->xid, stmt_self(stmt)->pos)) // test for type ?
}
const Type t = type_copy(env->gwion->p, t_int);
t->xid = ++env->scope->type_xid;
ANN static m_bool scan0_stmt_union(const Env env, const Stmt_Union stmt) { GWDEBUG_EXE
CHECK_BB(env_storage(env, stmt->flag))
if(stmt->xid) {
- CHECK_BB(scan0_defined(env, stmt->xid, stmt->self->pos))
+ CHECK_BB(scan0_defined(env, stmt->xid, stmt_self(stmt)->pos))
const Nspc nspc = !GET_FLAG(stmt, global) ?
env->curr : env->global_nspc;
const Type t = union_type(env, nspc, stmt->type_xid ?: stmt->xid,
}
ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) {
- const Type t = void_type(env, decl->td, decl->self->pos);
+ const Type t = void_type(env, decl->td, exp_self(decl)->pos);
CHECK_OO(t);
if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref))
- ERR_O(decl->self->pos, "Type '%s' is abstract, declare as ref. (use @)", t->name)
+ 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)
- ERR_O(decl->self->pos, "can't use private type %s", t->name)
+ 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(decl->self->pos, "can't use protected type %s", t->name)
+ ERR_O(exp_self(decl)->pos, "can't use protected type %s", t->name)
if(GET_FLAG(decl->td, global) && env->class_def)
- ERR_O(decl->self->pos, "can't declare variable global inside class.")
+ ERR_O(exp_self(decl)->pos, "can't declare variable global inside class.")
if(env->class_def) {
if(!env->scope->depth) {
if(!env->func && !GET_FLAG(decl->td, static))
SET_FLAG(decl->td, member);
if(!GET_FLAG(decl->td, ref) && t == env->class_def)
- ERR_O(decl->self->pos, "...(note: object of type '%s' declared inside itself)", t->name)
+ ERR_O(exp_self(decl)->pos, "...(note: object of type '%s' declared inside itself)", t->name)
}
}
decl->base = t->def;
ANN m_bool scan1_stmt_enum(const Env env, const Stmt_Enum stmt) { GWDEBUG_EXE
ID_List list = stmt->list;
do {
- CHECK_BB(already_defined(env, list->xid, stmt->self->pos))
+ CHECK_BB(already_defined(env, list->xid, stmt_self(stmt)->pos))
const Value v = new_value(env->gwion->p, stmt->t, s_name(list->xid));
if(env->class_def) {
v->owner_class = env->class_def;
if(map_get(m, (vtype)stmt->name)) {
const Stmt_Jump l = (Stmt_Jump)map_get(m, (vtype)stmt->name);
vector_release(&l->data.v);
- ERR_B(stmt->self->pos, "label '%s' already defined", s_name(stmt->name))
+ ERR_B(stmt_self(stmt)->pos, "label '%s' already defined", s_name(stmt->name))
}
map_set(m, (vtype)stmt->name, (vtype)stmt);
vector_init(&stmt->data.v);
-Subproject commit 83e0acd944da2d54c63075a8a1b3c4fb964d8138
+Subproject commit c04fc5e07c3a53554221f7bc6b760fb63e9e2df1