return GW_OK;
}
-ANN static m_bool emit_instantiate_new(const Emitter emit, const Exp_Decl *decl) {
- struct Exp_ e = {
- .d = { .exp_unary = {
- .op = insert_symbol("new"),
- .ctor = { .td = decl->td, .exp = decl->args },
- .unary_type = unary_td
- }},
- .exp_type = ae_exp_unary,
- .pos = decl->td->pos
- };
- CHECK_BB(traverse_exp(emit->env, &e));
- CHECK_BB(emit_exp(emit, &e));
- return GW_OK;
-}
-
ANN static m_bool _decl_static(const Emitter emit, const Exp_Decl *decl,
const Var_Decl *var_decl, const uint is_ref) {
const Value v = var_decl->value;
if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, v->type, decl->td, is_ref));
- else CHECK_BB(emit_instantiate_new(emit, decl));
+ else CHECK_BB(emit_exp(emit, decl->args));
CHECK_BB(emit_dot_static_data(emit, v, 1));
emit_add_instr(emit, Assign);
// if(get_depth(var_decl->value->type) && !is_ref)
if (is_obj && !is_ref && !exp_self(decl)->ref) {
// if (is_obj && ((is_array && !exp_self(decl)->ref) || !is_ref))
if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, is_ref));
- else CHECK_BB(emit_instantiate_new(emit, decl));
+ else CHECK_BB(emit_exp(emit, decl->args));
}
f_instr *exec = (f_instr *)allocmember;
if (!emit->env->scope->depth) emit_debug(emit, v);
const bool emit_addr = (!is_obj || is_ref) ? emit_var : true;
if (is_obj && !is_ref) {
if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, is_ref));
- else CHECK_BB(emit_instantiate_new(emit, decl));
+ else CHECK_BB(emit_exp(emit, decl->args));
}
const Instr instr =
emit_dotstatic(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1);
ERR_B(pos, _("can't infer type."))
}
-ANN Type check_exp_decl(const Env env, const Exp_Decl *decl) {
+ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) {
if (decl->td->array && decl->td->array->exp)
CHECK_OO(check_exp(env, decl->td->array->exp));
- if (decl->args) {
- struct Exp_ e = {
- .d = { .exp_unary = {
- .op = insert_symbol("new"),
- .ctor = { .td = decl->td, .exp = decl->args },
- .unary_type = unary_td
- }},
- .exp_type = ae_exp_unary,
- .pos = decl->td->pos
- };
- CHECK_OO(check_exp(env, &e));
+ if (decl->args && !decl->args->type) { // for some reason this can be parsed twice
+ Exp e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->td), decl->args, decl->td->pos);
+ CHECK_OO(check_exp(env, e));
+ Exp args = decl->args;
+ decl->args = e;
+ free_exp(env->gwion->mp, args);
}
if (decl->td->xid == insert_symbol("auto")) { // should be better
CHECK_BO(scan1_exp(env, exp_self(decl)));
const m_bool global = GET_FLAG(decl->td, global);
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
const m_bool ret = check_decl(env, decl);
- if (global) env_pop(env, scope);
+ if (global) {
+ env_pop(env, scope);
+ set_vflag(decl->vd.value, vflag_direct);
+ }
env_weight(env, 1 + isa(decl->type, env->gwion->type[et_object]) > 0);
return ret > 0 ? decl->vd.value->type : NULL;
}
}
const Value v = vd->value =
vd->value ?: new_value(env, t, s_name(vd->xid), vd->pos);
- nspc_add_value(env->curr, vd->xid, v);
- if (GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) SET_FLAG(v, late);
+ if (GET_FLAG(t, abstract) && !decl->args && !GET_FLAG(decl->td, late)) SET_FLAG(v, late);
v->type = t;
if (decl_ref) SET_FLAG(v, late);
v->flag |= decl->td->flag;
}
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
const m_bool ret = scan1_decl(env, decl);
+ valid_value(env, decl->vd.xid, decl->vd.value);
if (global) env_pop(env, scope);
return ret;
}
ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) {
edef->t->nspc = new_nspc(env->gwion->mp, edef->t->name);
- const Nspc nspc = edef->t->nspc;
const m_uint scope = env_push_type(env, edef->t);
ID_List list = edef->list;
for(uint32_t i = 0; i < list->len; i++) {
Symbol xid = *mp_vector_at(list, Symbol, i);
const Value v = new_value(env, edef->t, s_name(xid), edef->pos);
valuefrom(env, v->from);
+ valid_value(env, xid, v);
if (env->class_def) {
SET_FLAG(v, static);
SET_ACCESS(edef, v)
set_vflag(v, vflag_builtin);
SET_FLAG(v, const);
set_vflag(v, vflag_valid);
- nspc_add_value(nspc, xid, v);
vector_add(&edef->values, (vtype)v);
}
env_pop(env, scope);