-Subproject commit 3ef5bb688518c5b537eee6152f1cb81e8f477cdb
+Subproject commit c405f31eb2ffaf5a26b4ae92165d14784b2f2287
}
ANN m_bool check_stmt(const Env env, const Stmt stmt);
-ANN m_bool check_stmt_list(const Env env, const Stmt_List);
typedef m_bool (*_exp_func)(const void *, const void *);
ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f,
clean_exp(a, b->ctor.exp);
break;
case unary_code:
- clean_stmt_list(a, b->code);
+ clean_stmt(a, b->code);
break;
}
if(b->captures) clean_captures(a, b->captures);
++a->scope;
if (!b->builtin && b->d.code &&
!(b->base->func && safe_vflag(b->base->func->value_ref, vflag_builtin)))
- clean_stmt_list(a, b->d.code);
+ clean_stmt(a, b->d.code);
else
b->d.code = NULL;
--a->scope;
ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) {
if(emit->locale->def->d.code) {
- const Stmt stmt = mp_vector_at((emit->locale->def->d.code), struct Stmt_, 0);
+ const Stmt stmt = mp_vector_at((emit->locale->def->d.code->d.stmt_code.stmt_list), struct Stmt_, 0);
const Func f = stmt->d.stmt_exp.val->d.exp_call.func->type->info->func;
CHECK_OB(emit_ensure_func(emit, f));
}
}
struct Sporker {
- const Stmt_List code;
+ const Stmt code;
const Exp exp;
VM_Code vm_code;
const Type type;
const Capture_List captures;
- const loc_t pos;
const bool emit_var;
const bool is_spork;
};
const struct Sporker *sp) {
emit_add_instr(emit, RegPushImm);
push_spork_code(emit, sp->is_spork ? SPORK_CODE_PREFIX : FORK_CODE_PREFIX,
- sp->pos);
+ sp->code->pos);
if (emit->env->class_def) stack_alloc(emit);
if (emit->env->func && vflag(emit->env->func->value_ref, vflag_member))
stack_alloc(emit);
if(sp->captures) emit->code->frame->curr_offset += captures_sz(sp->captures);
-// return scoped_stmt(emit, sp->code);
- return emit_stmt_list(emit, sp->code);
+ return scoped_stmt(emit, sp->code);
}
ANN static m_bool spork_prepare_func(const Emitter emit,
.code = unary->unary_type == unary_code ? unary->code : NULL,
.type = exp_self(unary)->type,
.captures = unary->captures,
- .pos = exp_self(unary)->pos,
.is_spork = (unary->op == insert_symbol("spork")),
.emit_var = exp_getvar(exp_self(unary))};
CHECK_OB((sporker.vm_code = spork_prepare(emit, &sporker)));
if (fdef->base->xid == insert_symbol("@dtor")) emit_local(emit, emit->gwion->type[et_int]);
if (fdef->base->args) emit_func_def_args(emit, fdef->base->args);
if (fdef->d.code) {
- if(!fdef->builtin) {
- scoped_ini(emit);
- const m_bool ret = emit_stmt_list(emit, fdef->d.code);
- scoped_end(emit);
- CHECK_BB(ret);
- }
+ if(!fdef->builtin) CHECK_BB(scoped_stmt(emit, fdef->d.code));
else fdef->base->func->code = (VM_Code)vector_at(&fdef->base->func->value_ref->from->owner_class->nspc->vtable, fdef->vt_index);
}
emit_func_def_return(emit);
#include "tmp_resolve.h"
ANN static Exp uncurry(const Env env, const Exp_Binary *bin) {
- const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0);
+ const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code->d.stmt_code.stmt_list, struct Stmt_, 0);
const Exp ecall = stmt->d.stmt_exp.val;
const Exp_Call *call = &ecall->d.exp_call;
Exp args = call->args;
static OP_CHECK(opck_func_call) {
Exp_Binary *bin = (Exp_Binary *)data;
if(!strncmp(bin->rhs->type->name, "partial:", 8)) {
- const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0);
+ const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code->d.stmt_code.stmt_list, struct Stmt_, 0);
const Exp_Call *call = &stmt->d.stmt_exp.val->d.exp_call;
DECL_ON(const Exp, args, = uncurry(env, bin));
return mk_call(env, exp_self(bin), call->func, args);
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);
- Stmt_List code = new_mp_vector(env->gwion->mp, struct Stmt_, 1);
- mp_vector_set(code, struct Stmt_, 0,
+ Stmt_List slist = new_mp_vector(env->gwion->mp, 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
}));
+ const Stmt code = new_stmt_code(env->gwion->mp, slist, impl->e->pos);
const Func_Def def = new_func_def(env->gwion->mp, base, code);
def->base->xid = impl->e->d.prim.d.var;
// use envset
check_exp(env, cond);
const Stmt loop = new_stmt_flow(mp, ae_stmt_while, cond, stmt, false, func->pos);
- const Stmt_List code = new_mp_vector(mp, struct Stmt_, 1);
- mp_vector_set(code, struct Stmt_, 0, ((struct Stmt_) {
- .stmt_type = ae_stmt_while,
- .d = {
- .stmt_flow = {
- .cond = cond,
- .body = loop
- }
- },
- .pos = func->pos
- }));
exp->exp_type = ae_exp_unary;
exp->d.exp_unary.unary_type = unary_code;
- exp->d.exp_unary.code = code;
+ exp->d.exp_unary.code = loop;
exp->d.exp_unary.op = insert_symbol(env->gwion->st, "spork");
return env->gwion->type[et_shred];
}
static OP_CHECK(opck_sift) {
Exp_Binary *bin = (Exp_Binary*)data;
const Exp lhs = bin->lhs;
- Stmt stmt = mp_vector_at(lhs->d.exp_unary.code, struct Stmt_, 0);
+ Stmt stmt = lhs->d.exp_unary.code;
Stmt fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, struct Stmt_, 0);
const Symbol chuck = insert_symbol(env->gwion->st, "=>");
Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->pos);
- CHECK_BN(traverse_exp(env, next)); // how do we free it?
+ CHECK_BN(traverse_exp(env, next));
fst->d.stmt_exp.val = next;
const Exp exp = exp_self(bin);
exp->exp_type = lhs->exp_type;
const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->pos);
check_exp(env, cond);
- const Stmt_List code = new_mp_vector(mp, struct Stmt_, 1);
- mp_vector_set(code, struct Stmt_, 0, ((struct Stmt_) {
- .stmt_type = ae_stmt_while,
- .d = {
- .stmt_flow = {
- .cond = cond,
- .body = stmt
- }
- },
- .pos = func->pos
- }));
+ const Stmt loop = new_stmt_flow(mp, ae_stmt_while, cond, stmt, false, func->pos);
exp->exp_type = ae_exp_unary;
exp->d.exp_unary.unary_type = unary_code;
- exp->d.exp_unary.code = code;
+ exp->d.exp_unary.code = loop;
exp->d.exp_unary.op = insert_symbol(env->gwion->st, "spork");
+
return NULL;
}
struct Func_Def_ fdef = { .base = &fbase};
struct Func_ func = { .name = "in spork", .def = &fdef, .value_ref = &value};
env->func = &func;
-// scope depth?
- const m_bool ret = check_stmt_list(env, unary->code);
+ const m_bool ret = check_stmt(env, unary->code);
env->func = f;
free_scope(env->gwion->mp, env->curr->info->value);
env->curr->info->value = upvalues.values;
#include "partial.h"
#include "spread.h"
-ANN m_bool check_stmt_list(const Env env, Stmt_List list);
+ANN static m_bool check_stmt_list(const Env env, Stmt_List list);
ANN m_bool check_class_def(const Env env, const Class_Def class_def);
ANN static Type check_internal(const Env env, const Symbol sym, const Exp e,
const Exp when = tdef->when;
tdef->when = NULL;
when->next = helper;
- Stmt_List code = new_mp_vector(env->gwion->mp, struct Stmt_, 2);
- mp_vector_set(code, struct Stmt_, 0,
+ Stmt_List body = new_mp_vector(env->gwion->mp, struct Stmt_, 2);
+ mp_vector_set(body, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }},
.pos = when->pos
}));
- mp_vector_set(code, struct Stmt_, 1,
+ mp_vector_set(body, struct Stmt_, 1,
((struct Stmt_) {
.stmt_type = ae_stmt_exp,
.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);
tdef->when_def = fdef;
CHECK_BB(traverse_func_def(env, fdef));
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ret_id }},
.pos = when->pos
};
- mp_vector_set(fdef->d.code, struct Stmt_, 1, ret);
+ mp_vector_set(fdef->d.code->d.stmt_code.stmt_list, struct Stmt_, 1, ret);
ret_id->type = tdef->type;
}
if (tflag(tdef->type, tflag_cdef))
return check_stmt_func[stmt->stmt_type](env, &stmt->d);
}
-ANN m_bool check_stmt_list(const Env env, Stmt_List l) {
+ANN static m_bool check_stmt_list(const Env env, Stmt_List l) {
for(m_uint i = 0; i < l->len; i++) {
const Stmt s = mp_vector_at(l, struct Stmt_, i);
CHECK_BB(check_stmt(env, s));
ANN m_bool check_fdef(const Env env, const Func_Def fdef) {
if (fdef->base->args) CHECK_BB(check_func_args(env, fdef->base->args));
if(fdef->builtin) return GW_OK;
- if (fdef->d.code && fdef->d.code) {
- env->scope->depth++;
- nspc_push_value(env->gwion->mp, env->curr);
- const m_bool ret = check_stmt_list(env, fdef->d.code);
- nspc_pop_value(env->gwion->mp, env->curr);
- env->scope->depth--;
- return ret;
- }
+ if (fdef->d.code && fdef->d.code->d.stmt_code.stmt_list)
+ CHECK_BB(check_stmt_code(env, &fdef->d.code->d.stmt_code));
return GW_OK;
}
Arg *arg = mp_vector_at(args, Arg, args->len);
if(!arg->exp) break;
Func_Base *const base = cpy_func_base(p, base_fdef->base);
- Stmt_List code = strcmp("new", s_name(base->xid))
+ Stmt_List slist = strcmp("new", s_name(base->xid))
? std_code(env->gwion->mp, base, args, len)
: new_code(env, base, args, len);
-// const Stmt body = new_stmt_code(p, slist, base->pos);
- const Func_Def fdef = new_func_def(p, base, code);
+ const Stmt body = new_stmt_code(p, slist, base->pos);
+ const Func_Def fdef = new_func_def(p, base, body);
scan1_func_def(env, fdef);
scan2_func_def(env, fdef);
Section section = MK_SECTION(func, func_def, fdef);
return NULL;
}
-ANN static Stmt_List partial_code(const Env env, Arg_List args, const Exp efun, const Exp earg) {
+ANN static Stmt partial_code(const Env env, Arg_List args, const Exp efun, const Exp earg) {
const Exp arg = partial_call(env, args, earg);
const Exp exp = new_exp_call(env->gwion->mp, efun, arg, efun->pos);
- Stmt_List code = new_mp_vector(env->gwion->mp, struct Stmt_, 1);
- mp_vector_set(code, struct Stmt_, 0, ((struct Stmt_) {
- .stmt_type = ae_stmt_return,
- .d = { .stmt_exp = { .val = exp }}
- }));
-// stmt->stmt_type = ae_stmt_return;
-// stmt->d.stmt_exp.val = exp;
- return code;
-// return new_stmt_code(env->gwion->mp, slist, efun->pos);
+ Stmt_List slist = new_mp_vector(env->gwion->mp, struct Stmt_, 1);
+ Stmt stmt = mp_vector_at(slist, struct Stmt_, 0);
+ stmt->stmt_type = ae_stmt_return;
+ stmt->d.stmt_exp.val = exp;
+ return new_stmt_code(env->gwion->mp, slist, efun->pos);
}
ANN static uint32_t count_args_exp(Exp args) {
}
nspc_push_value(env->gwion->mp, env->curr);
Func_Base *const fbase = partial_base(env, f->def->base, call->args, call->func->pos);
- const Stmt_List code = partial_code(env, f->def->base->args, call->func, call->args);
+ const Stmt code = partial_code(env, f->def->base->args, call->func, call->args);
const Exp exp = exp_self(call);
exp->d.exp_lambda.def = new_func_def(env->gwion->mp, fbase, code);
exp->exp_type = ae_exp_lambda;
struct Func_ fake = {.name = s_name(fdef->base->xid), .def = fdef }, *const former =
env->func;
env->func = &fake;
- if(!fdef->builtin && fdef->d.code)
- scan0_stmt_list(env, fdef->d.code);
+ if(!fdef->builtin && fdef->d.code && fdef->d.code->d.stmt_code.stmt_list)
+ scan0_stmt_list(env, fdef->d.code->d.stmt_code.stmt_list);
if(env->context->extend)
- fdef->d.code = spread_func(env, fdef->d.code);
+ fdef->d.code->d.stmt_code.stmt_list = spread_func(env, fdef->d.code->d.stmt_code.stmt_list);
env->func = former;
env->context->extend = old_extend;
}}
if(unary->unary_type == unary_exp)
return scan1_exp(env, unary->exp);
if (unary->unary_type == unary_code)
- return scan1_stmt_list(env, unary->code);
+ return scan1_stmt(env, unary->code);
return GW_OK;
}
if (!env->func)
ERR_B(stmt_self(stmt)->pos,
_("'return' statement found outside function definition"))
- if (env->scope->depth == 1) env->func->memoize = 1;
+ if (env->scope->depth <= 2) env->func->memoize = 1;
if(stmt->val) scan1_exp(env, stmt->val);
return GW_OK;
}
CHECK_BB(scan1_fdef_args(env, fdef->base->args));
CHECK_BB(scan1_args(env, fdef->base->args));
}
- if (!fdef->builtin && fdef->d.code)
- CHECK_BB(scan1_stmt_list(env, fdef->d.code));
+ if (!fdef->builtin && fdef->d.code && fdef->d.code->d.stmt_code.stmt_list)
+ CHECK_BB(scan1_stmt_list(env, fdef->d.code->d.stmt_code.stmt_list));
return GW_OK;
}
struct Func_ fake = {.name = s_name(fdef->base->xid), .def = fdef }, *const former =
env->func;
env->func = &fake;
+ ++env->scope->depth;
const m_bool ret = scanx_fdef(env, env, fdef, (_exp_func)scan1_fdef);
+ --env->scope->depth;
env->func = former;
if (global) env_pop(env, scope);
if ((strcmp(s_name(fdef->base->xid), "@implicit") || fbflag(fdef->base, fbflag_internal)) && !fdef->builtin && fdef->base->ret_type &&
ANN static m_bool scan2_func_def_code(const Env env, const Func_Def f) {
const Func former = env->func;
env->func = f->base->func;
- env->scope->depth++;
- nspc_push_value(env->gwion->mp, env->curr);
- const m_bool ret = scan2_stmt_list(env, f->d.code); // scope depth?
- nspc_pop_value(env->gwion->mp, env->curr);
- env->scope->depth--;
+ CHECK_BB(scan2_stmt_code(env, &f->d.code->d.stmt_code));
env->func = former;
- return ret;
+ return GW_OK;
}
ANN static void scan2_func_def_flag(const Env env, const Func_Def f) {