-Subproject commit 1d6209b5b7f19379d36440f70f9fdd2c90429953
+Subproject commit 971a79a2f613db01129d7e52b4f738640bee00a9
ANN static void clean_case_list(Clean *a, Stmt_List b) {
for(m_uint i = 0; i < b->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(b->ptr + offset);
+ const Stmt stmt = mp_vector_at(b, struct Stmt_, i);
clean_stmt_case(a, &stmt->d.stmt_match);
}
}
ANN static void clean_arg_list(Clean *a, Arg_List b) {
for(uint32_t i = 0; i < b->len; i++) {
- Arg *arg = (Arg*)(b->ptr + i * sizeof(Arg));
+ Arg *arg = mp_vector_at(b, Arg, i);
if (arg->td) clean_type_decl(a, arg->td);
clean_var_decl(a, &arg->var_decl);
}
ANN static void clean_stmt_list(Clean *a, Stmt_List b) {
for(m_uint i = 0; i < b->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(b->ptr + offset);
+ const Stmt stmt = mp_vector_at(b, struct Stmt_, i);
clean_stmt(a, stmt);
}
}
ANN static void clean_ast(Clean *a, Ast b) {
for(m_uint i = 0; i < b->len; i++) {
- const m_uint offset = i * sizeof(Section);
- clean_section(a, (Section*)(b->ptr + offset));
+ Section *section = mp_vector_at(b, Section, i);
+ clean_section(a, section);
}
}
ANN static m_bool me_arg(MemoizeEmitter *me) {
Arg_List args = me->fdef->base->args;
for(uint32_t i = 0; i < args->len; i++) {
- Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg));
+ Arg *arg = mp_vector_at(args, Arg, i);
const m_uint sz = arg->type->size;
(void)me_push(me, sz);
const Instr instr = me_push(me, sz);
(e->cast_to ? isa(e->cast_to, emit->gwion->type[et_object]) > 0 : 1) &&
e->exp_type == ae_exp_decl && GET_FLAG(e->d.exp_decl.td, late) &&
exp_getuse(e) && !exp_getvar(e) &&
- GET_FLAG((mp_vector_at(e->d.exp_decl.list, struct Var_Decl_, 0))->value, late)) {
+ GET_FLAG(mp_vector_at(e->d.exp_decl.list, struct Var_Decl_, 0)->value, late)) {
// GET_FLAG(e->d.exp_decl.list->self->value, late)) {
// e->exp_type == ae_exp_decl && !exp_getvar(e)) {
// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT);
ANN static m_bool emit_stmt_cases(const Emitter emit, Stmt_List list) {
for(m_uint i = 0; i < list->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(list->ptr + offset);
+ const Stmt stmt = mp_vector_at(list, struct Stmt_, i);
CHECK_BB(emit_stmt_match_case(emit, &stmt->d.stmt_match));
}
return GW_OK;
ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(l->ptr + offset);
+ const Stmt stmt = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(emit_stmt(emit, stmt, 1));
}
return GW_OK;
ANN static void emit_func_def_args(const Emitter emit, Arg_List args) {
for(uint32_t i = 0; i < args->len; i++) {
- Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg));
+ Arg *arg = mp_vector_at(args, Arg, i);
const Type type = arg->var_decl.value->type;
emit->code->stack_depth += type->size;
arg->var_decl.value->from->offset = emit_localn(emit, type);
ANN static inline m_bool emit_ast_inner(const Emitter emit, Ast ast) {
for(m_uint i = 0; i < ast->len; i++) {
- const m_uint offset = i * sizeof(struct Section_);
- CHECK_BB(emit_section(emit, (Section*)(ast->ptr + offset)));
+ Section * section = mp_vector_at(ast, Section, i);
+ CHECK_BB(emit_section(emit, section));
}
return emit_defers(emit);
}
void gwi_body(const Gwi gwi, const Section *section) {
const Class_Def cdef = gwi->gwion->env->class_def->info->cdef;
if (!cdef->body) {
- mp_vector_first(gwi->gwion->mp, a, Section, *section);
- cdef->body = a;
+ cdef->body = new_mp_vector(gwi->gwion->mp, sizeof(Section), 1);
+ mp_vector_set(cdef->body, Section, 0, *section);
} else {
mp_vector_add(gwi->gwion->mp, &cdef->body, Section, (*section));
}
}
ANN static m_int gwi_item_tmpl(const Gwi gwi) {
- mp_vector_first(gwi->gwion->mp, slist, struct Stmt_,
- ((struct Stmt_) {
+ Stmt_List slist = new_mp_vector(gwi->gwion->mp, sizeof(struct Stmt_), 1);
+ mp_vector_set(slist, struct Stmt_, 0, ((struct Stmt_) {
.stmt_type = ae_stmt_exp,
.d = { .stmt_exp = { .val = gwi->ck->exp } },
.pos = gwi->loc
if (env->class_def && tflag(env->class_def, tflag_tmpl))
return gwi_item_tmpl(gwi);
CHECK_BB(traverse_exp(env, gwi->ck->exp));
- const Value value = (mp_vector_at(gwi->ck->exp->d.exp_decl.list, struct Var_Decl_, 0))->value;
+ const Value value = mp_vector_at(gwi->ck->exp->d.exp_decl.list, struct Var_Decl_, 0)->value;
value->d = addr;
set_vflag(value, vflag_builtin);
if (!env->class_def) SET_FLAG(value, global);
def->base->func->value_ref->from->owner_class->info->cdef->base.tmpl);
if(bases) {
for(uint32_t i = 0; i < bases->len; i++) {
- Arg *base = (Arg*)(bases->ptr + i * sizeof(Arg));
- Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg));
+ Arg *base = mp_vector_at(bases, Arg, i);
+ Arg *arg = mp_vector_at(args, Arg, i);
arg->td = type2td(env->gwion, known_type(env, base->td), exp_self(l)->pos);
}
if(ret < 0) {
if(args) {
for(uint32_t i = 0; i < bases->len; i++) {
- Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg));
+ Arg *arg = mp_vector_at(args, Arg, i);
free_value(arg->var_decl.value, env->gwion);
arg->var_decl.value = NULL;
}
Arg_List args = func->def->base->args;
for(uint32_t i = 0; i < args->len; i++) {
- Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg));
+ Arg *arg = mp_vector_at(args, Arg, i);
if (!arg->type) arg->type = known_type(env, arg->td);
}
/*
new_prim_id(env->gwion->mp, larg1->var_decl.xid, impl->e->pos);
const Exp bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var,
rhs, impl->e->pos);
- mp_vector_first(env->gwion->mp, slist, struct Stmt_,
+ Stmt_List slist = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1);
+ mp_vector_set(slist, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = bin }},
.pos = impl->e->pos
ANN Type check_exp_unary_spork(const Env env, const Stmt code);
ANN static void fork_exp(const Env env, const Exp_Unary *unary) {
- mp_vector_first(env->gwion->mp, slist, struct Stmt_,
+ Stmt_List slist = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1);
+ mp_vector_set(slist, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = unary->exp, } },
.pos = unary->exp->pos
ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) {
struct tmpl_info info = {
.base = t, .td = td, .list = t->info->cdef->base.tmpl->list};
- const Type exists = tmpl_exists(env, &info);
+ const Type exists = t->info->cdef->base.tmpl->call ? t : tmpl_exists(env, &info);
if (exists) return exists != env->gwion->type[et_error] ? exists : NULL;
struct EnvSet es = {.env = env,
.data = env,
const m_bool ret = check_decl(env, decl);
if (global) env_pop(env, scope);
env_weight(env, 1 + isa(decl->type, env->gwion->type[et_object]) > 0);
- return ret > 0 ? (mp_vector_at(decl->list, struct Var_Decl_, 0))->value->type : NULL;
+ return ret > 0 ? mp_vector_at(decl->list, struct Var_Decl_, 0)->value->type : NULL;
}
ANN static m_bool check_collection(const Env env, Type type, const Exp e,
if (is_auto) {
assert(bin->rhs->type == bin->lhs->type);
// bin->rhs->type = bin->lhs->type;
- set_vflag((mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0))->value, vflag_assigned);
+ set_vflag(mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0)->value, vflag_assigned);
}
struct Op_Import opi = {.op = bin->op,
.lhs = bin->lhs->type,
exp_setuse(bin->rhs, 1);
const Type ret = op_check(env, &opi);
if (!ret && is_auto && exp_self(bin)->exp_type == ae_exp_binary)
- (mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0))->value->type = env->gwion->type[et_auto];
+ mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0)->value->type = env->gwion->type[et_auto];
return ret;
}
set_tflag(tdef->type, tflag_contract);
struct Var_Decl_ decl = { .xid = insert_symbol("self"), .pos = tdef->when->pos };
Type_Decl *td = cpy_type_decl(env->gwion->mp, tdef->ext);
- mp_vector_first(env->gwion->mp, args, Arg, ((Arg) { .td = td, .var_decl = decl }));
-// const Arg_List args = new_arg_list(
-// env->gwion->mp, cpy_type_decl(env->gwion->mp, tdef->ext), decl, NULL);
+ Arg_List args = new_mp_vector(env->gwion->mp, sizeof(Arg), 1);
+ mp_vector_set(args, Arg, 0, ((Arg) { .td = td, .var_decl = decl }));
Func_Base *fb = new_func_base(
env->gwion->mp, type2td(env->gwion, tdef->type, tdef->pos),
insert_symbol("@implicit"), args, ae_flag_none, tdef->pos);
tdef->when->pos);
const Exp when = cpy_exp(env->gwion->mp, tdef->when);
when->next = helper;
-// const Stmt stmt =
-// new_stmt_exp(env->gwion->mp, ae_stmt_exp, when, when->pos);
-// const Stmt_List body =
-// new_stmt_list(env->gwion->mp, stmt, NULL); // ret_list);
-// Stmt_List body;
- mp_vector_first(env->gwion->mp, body, struct Stmt_,
- ((struct Stmt_) {
- .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }},
- .pos = when->pos
- }));
+ Stmt_List body = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1);
+ mp_vector_set(body, struct Stmt_, 0,
+ ((struct Stmt_) {
+ .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }},
+ .pos = when->pos
+ }));
const Stmt code = new_stmt_code(env->gwion->mp, body, when->pos);
const Func_Def fdef = new_func_def(env->gwion->mp, fb, code);
if(traverse_func_def(env, fdef) < 0) {
ANN static m_bool case_loop(const Env env, const Stmt_Match stmt) {
for(m_uint i = 0; i < stmt->list->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(stmt->list->ptr + offset);
+ const Stmt s = mp_vector_at(stmt->list, struct Stmt_, i);
CHECK_BB(check_stmt_case(env, &s->d.stmt_match));
}
return GW_OK;
ANN static m_bool check_stmt_list(const Env env, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(l->ptr + offset);
+ const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(check_stmt(env, s));
}
return GW_OK;
// while (ast) {
// Section *section = ast->section;
for(m_uint i = 0; i < ast->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section * section = (Section*)(ast->ptr + offset);
+ Section * section = mp_vector_at(ast, Section, i);
if (section->section_type == ae_section_stmt) {
Stmt_List l = section->d.stmt_list;
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(l->ptr + offset);
-// Stmt_List list = section->d.stmt_list;
-// while (list) {
-// const Stmt stmt = list->stmt;
+ const Stmt stmt = mp_vector_at(l, struct Stmt_, i);
if (stmt->stmt_type == ae_stmt_exp) {
CHECK_BB(traverse_exp(env, stmt->d.stmt_exp.val));
Var_Decl_List list = stmt->d.stmt_exp.val->d.exp_decl.list;
ANN static bool class_def_has_body(const Env env, Ast ast) {
// do {
for(m_uint i = 0; i < ast->len; i++) {
- const m_uint offset = i * sizeof(Section);
-// const Section *section = ast->section;
- const Section *section = (Section*)(ast->ptr + offset);
+ const Section *section = mp_vector_at(ast, Section, i);
if (section->section_type == ae_section_stmt) {
Stmt_List l = section->d.stmt_list;
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(l->ptr + offset);
+ const Stmt stmt = mp_vector_at(l, struct Stmt_, i);
if (stmt->stmt_type == ae_stmt_pp) continue;
if (stmt->stmt_type == ae_stmt_exp) {
const Exp exp = stmt->d.stmt_exp.val;
ANN m_bool check_ast(const Env env, Ast *ast) {
Ast a = *ast;
for(m_uint i = 0; i < a->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section * section = (Section*)(a->ptr + offset);
+ Section * section = mp_vector_at(a, Section, i);
CHECK_BB(check_section(env, section));
}
check_unhandled(env);
if (GET_FLAG(udef, global)) context_global(env);
CHECK_BB(scan0_defined(env, udef->xid, udef->pos));
udef->type = union_type(env, udef->xid, udef->pos);
- Union_List l = udef->l;
-// do udef->type->nspc->offset += SZ_INT;
-// while ((l = l->next));
- udef->type->nspc->offset += SZ_INT;
SET_ACCESS(udef, udef->type);
if (udef->tmpl) union_tmpl(env, udef);
if (global) env_pop(env, 0);
ANN static m_bool scan0_stmt_list(const Env env, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt stmt = (Stmt)(l->ptr + offset);
+ const Stmt stmt = mp_vector_at(l, struct Stmt_, i);
if (stmt->stmt_type == ae_stmt_pp) {
if (stmt->d.stmt_pp.pp_type == ae_pp_include)
env->name = stmt->d.stmt_pp.data;
const Exp efunc = new_prim_id(p, base->xid, base->pos);
const Exp exp_arg = mk_default_args(p, args, len);
const Exp ecall = new_exp_call(p, efunc, exp_arg, base->pos);
- mp_vector_first(p, slist, struct Stmt_,
+ Stmt_List slist = new_mp_vector(p, sizeof(struct Stmt_), 1);
+ mp_vector_set(slist, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ecall }},
.pos = base_fdef->base->pos
ERR_B(xdef->td->pos, _("can't extend final type"))
Ast ast = xdef->body;
for(m_uint i = 0; i < ast->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section * section = (Section*)(ast->ptr + offset);
+ Section * section = mp_vector_at(ast, Section, i);
if (section->section_type == ae_section_func &&
GET_FLAG(section->d.func_def->base, abstract))
ERR_B(section->d.func_def->base->pos,
Ast ast = pdef->body;
if(!ast) return GW_OK; // ???
for(m_uint i = 0; i < ast->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section *section = (Section*)(ast->ptr + offset);
+ Section *section = mp_vector_at(ast, Section, i);
if (section->section_type == ae_section_func) {
const Func_Def fdef = section->d.func_def;
if (!trait->requested_funcs.ptr) vector_init(&trait->requested_funcs);
Ast a = *ast;
Ast acc = new_mp_vector(env->gwion->mp, sizeof(Section), 0);
for(m_uint i = 0; i < a->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section * section = (Section*)(a->ptr + offset);
+ Section * section = mp_vector_at(a, Section, i);
CHECK_BB(scan0_section(env, section));
if (section->section_type != ae_section_func ||
}
for(m_uint i = 0; i < acc->len; i++) {
- Section *section = (Section*)(acc->ptr + i * sizeof(Section));
+ Section * section = mp_vector_at(acc, Section, i);
mp_vector_add(env->gwion->mp, ast, Section, *section);
}
free_mp_vector(env->gwion->mp, sizeof(Section), acc);
set_vflag(v, vflag_inner); // file global
}
}
- ((Exp_Decl *)decl)->type = (mp_vector_at(decl->list, struct Var_Decl_, 0))->value->type;
+ ((Exp_Decl *)decl)->type = mp_vector_at(decl->list, struct Var_Decl_, 0)->value->type;
return GW_OK;
}
if (stmt->where) CHECK_BB(scan1_stmt(env, stmt->where));
Stmt_List l = stmt->list;
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(l->ptr + offset);
+ const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(scan1_stmt_match_case(env, &s->d.stmt_match));
}
return GW_OK;
ANN static m_bool scan1_stmt_list(const Env env, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(l->ptr + offset);
+ const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(scan1_stmt(env, s));
}
/*
ANN m_bool scan1_ast(const Env env, Ast *ast) {
Ast a = *ast;
for(m_uint i = 0; i < a->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section *section = (Section*)(a->ptr + offset);
+ Section *section = mp_vector_at(a, Section, i);
CHECK_BB(scan1_section(env, section));
}
return GW_OK;
if (stmt->where) CHECK_BB(scan2_stmt(env, stmt->where));
Stmt_List l = stmt->list;
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(l->ptr + offset);
+ const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(scan2_stmt_match_case(env, &s->d.stmt_match));
}
return GW_OK;
ANN static m_bool scan2_stmt_list(const Env env, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
- const m_uint offset = i * sizeof(struct Stmt_);
- const Stmt s = (Stmt)(l->ptr + offset);
+ const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(scan2_stmt(env, s));
}
return GW_OK;
ANN m_bool scan2_ast(const Env env, Ast *ast) {
Ast a = *ast;
for(m_uint i = 0; i < a->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section *section = (Section*)(a->ptr + offset);
+ Section *section = mp_vector_at(a, Section, i);
CHECK_BB(scan2_section(env, section));
}
return GW_OK;
ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) {
for(m_uint i = 0; i < b->len; i++) {
- const m_uint offset = i * sizeof(Section);
- Section *section = (Section*)(b->ptr + offset);
+ Section *section = mp_vector_at(b, Section, i);
CHECK_BB(f(e, section));
}
return GW_OK;
for(uint32_t i = 0; i < tl->len; i++) {
Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i);
DECL_OO(const Type, t, = known_type(env, td));
- Specialized *spec = mp_vector_at(sl, Specialized, i);
- if(spec->traits) {
- Symbol missing = miss_traits(t, spec);
- if (missing) {
- ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'",
- s_name(missing));
+ Specialized *spec = mp_vector_at(sl, Specialized, i);
+ if(spec->traits) {
+ Symbol missing = miss_traits(t, spec);
+ if (missing) {
+ ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'",
+ s_name(missing));
+ }
}
- }
}
struct Op_Import opi = {.op = insert_symbol("@scan"),
.lhs = t,
-Subproject commit 620ab68b3234178145f080e370b9ff5c0cede772
+Subproject commit 923e360e10f309a23cc36c50e9e0ca44f22bd2d4