return envset_push(es, v->from->owner_class, v->from->owner);
}
ANN2(1) void envset_pop(struct EnvSet *, const Type);
-
-ANN static inline m_bool extend_push(const Env env, const Type t) {
- const Type owner = t->info->value->from->owner_class;
- if (owner) CHECK_BB(extend_push(env, owner));
- return env_push_type(env, t);
-}
-
-ANN static inline void extend_pop(const Env env, const Type t) {
- env_pop(env, 0);
- const Type owner = t->info->value->from->owner_class;
- if (owner) extend_pop(env, owner);
-}
#endif
const VM_Code code = finalyze(emit, EOC);
const VM_Shred shred = new_vm_shred(emit->gwion->mp, code);
vm_add_shred(emit->gwion->vm, shred);
-// shred->info->me->ref++;
+ shred->info->me->ref++;
vm_run(emit->gwion->vm);
emit->gwion->vm->bbq->is_running = true;
const m_float ret = *(m_float*)shred->reg;
.func = (_exp_func)emit_cdef,
.scope = scope,
.flag = tflag_emit};
- CHECK_BB(envset_push(&es, v->from->owner_class, v->from->owner));
+ CHECK_BB(envset_pushv(&es, v));
(void)emit_push(emit, v->from->owner_class, v->from->owner);
const m_bool ret = traverse_emit_func_def(emit, fdef);
- if (es.run) envset_pop(&es, v->from->owner_class);
emit_pop(emit, scope);
+ envset_pop(&es, v->from->owner_class);
emit->env->scope->shadowing = shadowing;
- if(ret > 0) set_fflag(fdef->base->func, fflag_tmpl);
return ret;
}
CHECK_BB(envset_pushv(&es, v));
(void)emit_push(emit, v->from->owner_class, v->from->owner);
const m_bool ret = emit_func_def(emit, f->def);
- if (es.run) envset_pop(&es, v->from->owner_class);
+ envset_pop(&es, v->from->owner_class);
emit_pop(emit, scope);
return ret > 0 ? push_func_code(emit, f) : GW_ERROR;
}
.flag = tflag_emit};
CHECK_BB(envset_pushv(&es, lambda->def->base->func->value_ref));
const m_bool ret = emit_lambda(emit, lambda);
- if (es.run) envset_pop(&es, lambda->owner);
+ envset_pop(&es, lambda->owner);
return ret;
}
#include "template.h"
ANN static void check(struct EnvSet *es, const Type t) {
+ es->_ctx = es->env->context;
+ es->_filename = es->env->name;
const Vector v = &es->env->scope->class_stack;
Type owner = t->info->value->from->owner_class;
for (vtype i = vector_size(v) + 1; owner && --i;) {
env_push(es->env, NULL,
t->info->value->from->ctx ? t->info->value->from->ctx->nspc
: es->env->curr);
- if (es->func && !(t->tflag & es->flag))
- CHECK_BB(es->func((void *)es->data, t));
- env_push_type((void *)es->env, t);
+ env_push_type((void *)es->env, t); // do not push if is a function?
if (tflag(t, tflag_tmpl))
CHECK_BB(template_push_types(
es->env, t->info->cdef->base.tmpl)); // incorrect templates?
- es->_ctx = es->env->context;
- es->_filename = es->env->name;
- es->env->context = t->info->value->from->ctx;
- es->env->name = t->info->value->from->filename;
return GW_OK;
}
}
ANN2(1) void envset_pop(struct EnvSet *es, const Type t) {
- _envset_pop(es, t);
+ if(es->run) _envset_pop(es, t);
// if(t && type_global(es->env, t))
// env_pop(es->env, es->scope);
if (es->_ctx) es->env->context = es->_ctx;
- if (es->_filename) es->env->name = es->_filename;
+ if (es->_filename) es->env->name = es->_filename;
}
ANN m_bool envset_run(struct EnvSet *es, const Type t) {
check(es, t);
const Type owner_class = t->info->value->from->owner_class;
if (es->run) CHECK_BB(push(es, owner_class));
+ es->env->context = t->info->value->from->ctx;
+ es->env->name = t->info->value->from->filename;
const m_bool ret =
t->info->cdef && !(t->tflag & es->flag) ? es->func(es->data, t) : GW_OK;
- if (es->run) envset_pop(es, owner_class);
+ envset_pop(es, owner_class);
return ret;
}
ANN void pop_global(const Gwion gwion) {
Nspc nspc = gwion->env->global_nspc->parent;
-// Nspc nspc = gwion->env->global_nspc, parent;
while (nspc) {
const Nspc parent = nspc->parent;
nspc_remref(nspc, gwion);
env_set_error(env, true);
return env->gwion->type[et_error];
}
+/*
if (!strncmp(base->name, "Option:[", 5)) {
gwerr_basic("Can't use option types as array base", NULL, NULL, "/dev/null",
(loc_t) {}, 0);
env_set_error(env, true);
return env->gwion->type[et_error];
}
+*/
const Symbol sym = array_sym(env, array_base_simple(base), base->array_depth + 1);
const Type type = nspc_lookup_type1(base->info->value->from->owner, sym);
if (type) return type;
nspc_pop_type(env->gwion->mp, env->curr);
owner = owner->info->value->from->owner_class;
}
- if (es.run) envset_pop(&es, owner);
+ envset_pop(&es, owner);
if(ret < 0) {
if(args) {
for(uint32_t i = 0; i < bases->len; i++) {
CHECK_BO(envset_pushv(&es, owner->info->value));
const m_bool ret = traverse_fptr_def(env, fdef);
const Type t = ret > 0 ? fdef->cdef->base.type : NULL;
- if (es.run) envset_pop(&es, owner->info->value->from->owner_class);
+ envset_pop(&es, owner->info->value->from->owner_class);
free_fptr_def(env->gwion->mp, fdef); // clean?
if(t) set_tflag(t, tflag_emit);
return t;
*(VM_Code *)(shred->reg - SZ_INT) = f->code;
return;
}
- const Emitter emit = shred->info->vm->gwion->emit;
const struct dottmpl_ *dt = (struct dottmpl_*)instr->m_val2;
- struct EnvSet es = {.env = emit->env,
- .data = emit,
-// .func = (_exp_func)emit_cdef,
- .func = (_exp_func)dummy_func,
- .scope = 0,
- .flag = tflag_emit};
- if(envset_push(&es, dt->type, dt->nspc) < 0) return;
foo(shred, o->type_ref, fbase, dt->tmpl_name);
- if (es.run) envset_pop(&es, dt->type);
}
#define VAL (*(m_uint *)(byte + SZ_INT))
env->name = env_filename;
env->context->name = ctx_filename;
if(local)env_pop(env, es.scope);
- if (es.run) envset_pop(&es, owner);
+ envset_pop(&es, owner);
return ret;
}
static MFUN(fork_join) {
if (*(m_int *)(o->data + o_fork_done)) return;
if (!ME(o)->tick) return;
- shreduler_remove(shred->tick->shreduler, shred, false);
+ shred->info->me->ref++;
vector_add(&EV_SHREDS(*(M_Object *)(o->data + o_fork_ev)), (vtype)shred);
+ shreduler_remove(shred->tick->shreduler, shred, false);
}
static MFUN(shred_cancel) {
static MFUN(string_atoi2) {
const M_Object obj = *(M_Object*)MEM(0);
const m_str str = STRING(obj);
-puts(str);
char *endptr = NULL;
if(!(*(m_int*)RETURN = strtol(str, &endptr, 10))) {
-printf("lkjlk j %i\n", errno);
if(errno == EINVAL) {
handle(shred, "ErrorInvalidValue");
return;
return;
}
}
-printf("ret: %li\n", *(m_int*)RETURN);
**(m_uint**)MEM(SZ_INT) = endptr - str;
}
ANN /*static inline*/ m_bool ensure_check(const Env env, const Type t) {
if (tflag(t, tflag_check) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef)))
return GW_OK;
+ if(!tflag(t, tflag_tmpl)) return GW_OK;
struct EnvSet es = {.env = env,
.data = env,
.func = (_exp_func)check_cdef,
CHECK_BO(envset_pushv(&es, v));
func->def->base->fbflag |= fbflag_internal;
const m_bool ret = check_traverse_fdef(env, func->def);
- if (es.run) envset_pop(&es, v->from->owner_class);
+ envset_pop(&es, v->from->owner_class);
CHECK_BO(ret);
}
exp->func->type = func->value_ref->type;
if (t == env->gwion->type[et_op]) return check_op_call(env, exp);
if (!t->info->func) // TODO: effects?
return check_lambda_call(env, exp);
+/*
if (fflag(t->info->func, fflag_ftmpl)) {
const Value value = t->info->func->value_ref;
if (value->from->owner_class)
CHECK_BO(ensure_traverse(env, value->from->owner_class));
}
+*/
if (exp->args) {
CHECK_OO(check_exp(env, exp->args));
Exp e = exp->args;
return check_exp_call_template(env, (Exp_Call *)exp); // TODO: effects?
const Func func = find_func_match(env, t->info->func, exp);
if (func) {
+/*
if (func != env->func && func->def && !fflag(func, fflag_valid)) {
if(func->value_ref->from->owner_class)
CHECK_BO(ensure_check(env, func->value_ref->from->owner_class));
if(in_tmpl)
nspc_pop_type(env->gwion->mp, env->curr);
env_pop(env, scope);
- if (es.run) envset_pop(&es, v->from->owner_class);
+ envset_pop(&es, v->from->owner_class);
env->func = former;
return m_func;
}
env_set_error(env, true);
return GW_ERROR;
}
+
+ if(!strcmp(s_name(fdef->base->xid), "new")) {
+ if(!env->class_def)
+ ERR_B(fdef->base->pos, _("{G+}new{0} operator must be set inside {C+}class{0}"));
+ SET_FLAG(env->class_def, abstract);
+ }
+
return ret;
}
(void)env_push(env, owner, owner->nspc); // TODO: is this needed?
const Type ret = known_type(env, td->next);
env_pop(env, es.scope);
- if (es.run) envset_pop(&es, owner);
+ envset_pop(&es, owner);
if (!td->array) return ret;
return array_type(env, ret, td->array->depth);
}