if(!sporker.is_spork)
emit_local_exp(emit, exp_self(unary));
spork_ini(emit, &sporker);
-
-if(sporker.captures) {
+ // add this if needed
+ uint32_t offset = 0;
+ if(emit->env->class_def && sporker.code) {
+ struct Exp_ exp = {
+ .d = { .prim = {
+ .d = { .var = insert_symbol("this") },
+ .prim_type = ae_prim_id
+ }},
+ .type = emit->env->class_def,
+ .exp_type = ae_exp_primary
+ };
+ emit_exp(emit, &exp);
+ offset += SZ_INT;
+ }
+ if(sporker.captures) {
Capture_List caps = sporker.captures;
-// what about types?
- uint32_t offset = 0;
for (uint32_t i = 0; i < caps->len; i++) {
Capture *cap = mp_vector_at(caps, Capture, i);
const Value v = nspc_lookup_value1(emit->env->curr, cap->xid);
.type = v->type,
.exp_type = ae_exp_primary
};
-// handle emit var?
-//exp_setvar(&exp, false);
+ if(cap->is_ref) exp_setvar(&exp, true);
+ offset += exp_size(&exp);
emit_exp(emit, &exp);
}
-// pop_exp(emit, &exp);
-regpop(emit, SZ_INT);
+ }
+ if(offset) {
+ regpop(emit, offset);
const Instr args = emit_add_instr(emit, SporkCode);
- args->m_val = 8; //emit->code->stack_depth;
+ args->m_val = offset;
}
-
-// emit_local_exp(emit, exp_self(unary));
(unary->unary_type == unary_code ? spork_code : spork_func)(emit, &sporker);
return GW_OK;
}
ANN static m_bool emit_stmt_each(const Emitter emit, const Stmt_Each stmt) {
const uint n = emit->info->unroll;
+ nspc_push_value(emit->gwion->mp, emit->env->curr);
CHECK_BB(emit_exp(emit, stmt->exp)); // add ref?
regpop(emit, SZ_INT);
m_uint end_pc = 0;
const m_bool ret = _emit_stmt_each(emit, stmt, &end_pc);
emit_pop_stack(emit, end_pc);
+nspc_pop_value(emit->gwion->mp, emit->env->curr);
emit->info->unroll = 0;
return ret;
}
emit->code->stack_depth += type->size;
arg->var_decl.value->from->offset = emit_localn(emit, type);
emit_debug(emit, arg->var_decl.value);
+ nspc_add_value(emit->env->curr, insert_symbol(arg->var_decl.value->name), arg->var_decl.value);
}
}
const Func f = fdef->base->func;
if (f->memoize && fflag(f, fflag_pure))
CHECK_BB(emit_memoize(emit, fdef));
+ nspc_push_value(emit->gwion->mp, emit->env->curr); // handle
CHECK_BB(emit_func_def_body(emit, fdef));
emit_func_def_return(emit);
+ nspc_pop_value(emit->gwion->mp, emit->env->curr); // handle
return GW_OK;
}
}
if (unary->unary_type == unary_code) {
if(unary->captures) {
- uint32_t offset = 0;
+ uint32_t offset = !env->class_def ? 0 : SZ_INT;
for(uint32_t i = 0; i < unary->captures->len; i++) {
Capture *const cap = mp_vector_at(unary->captures, Capture, i);
DECL_OO(const Type, t, = upvalue_type(env, cap));
}
const Func f = env->func;
struct Value_ value = {};
- set_vflag(&value, vflag_member);
+ if(env->class_def)
+ set_vflag(&value, vflag_member);
struct Func_Base_ fbase = { .xid=insert_symbol("in spork"), .values = scope};
struct Func_Def_ fdef = { .base = &fbase};
struct Func_ func = { .name = "in spork", .def = &fdef, .value_ref = &value};
return v ? v->from->owner : env->curr;
}
-ANN bool not_upvalue(const Env env, const Value v) {
- return GET_FLAG(v, global) || vflag(v, vflag_fglobal) ||
- (v->from->owner_class && isa(v->from->owner_class, env->class_def) > 0) ||
- nspc_lookup_value1(env->curr, insert_symbol(v->name));
-}
-
ANN static m_bool check_upvalue(const Env env, const Exp_Primary *prim) {
const Value v = prim->value;
if(not_upvalue(env, v))
ANN static inline m_bool scan1_exp_unary(const restrict Env env,
Exp_Unary *const unary) {
if (unary->unary_type == unary_code) {
+/*
if(strcmp("fork", s_name(unary->op))) {
const loc_t pos = exp_self(unary)->pos;
const Symbol sym = lambda_name(env->gwion->st, pos.first);
mp_free(env->gwion->mp, Stmt, unary->code);
unary->exp = new_exp_call(env->gwion->mp, lambda, NULL, pos);
unary->unary_type = unary_exp;
-} else {
+} else */{
return scan1_stmt(env, unary->code);
}