CHECK_BB(emit_instantiate_object(emit, type, array, is_ref))
f_instr *exec = (f_instr*)dotstatic;
const Instr instr = emit_kind(emit, v->type->size, emit_addr, exec);
-v->d.ptr = _mp_alloc(v->type->size);
-// here union flag is more like 'treat as builtin'
-SET_FLAG(v, builtin | ae_flag_union);
+ v->d.ptr = _mp_alloc(v->type->size);
+ SET_FLAG(v, union);
instr->m_val = (m_uint)v->d.ptr;
instr->m_val2 = v->type->size;
if(is_obj && (is_array || !is_ref)) {
assign->m_val = (m_uint)emit_var;
if(is_array && !emit->env->scope)
ADD_REF(type)
+ const Instr instr = emit_add_instr(emit, RegAddRef);
+ instr->m_val = emit_var;
}
return GW_OK;
}
emit_func_def_code(emit, func);
emit->env->func = former;
emit_pop_code(emit);
-// if(!emit->env->class_def && !GET_FLAG(func_def, template))
- if(!emit->env->class_def)
+ if(!emit->env->class_def && !GET_FLAG(func_def, global))
emit_func_def_global(emit, func->value_ref);
MEMOIZE_INI
return GW_OK;
vector_init(&env->nspc_stack);
vector_init(&env->known_ctx);
env->type_xid = 0;
-// scope_init(&env->swi);
-// vector_pop((Vector)&env->swi);
vector_init((Vector)&env->swi);
map_init(&env->swi.map);
ANN void free_env(const Env a) {
const m_uint size = vector_size(&a->known_ctx);
- for(m_uint i = 0; i < size; i++)
- REM_REF((Context)vector_at(&a->known_ctx, i));
- REM_REF(a->global_nspc);
+ for(m_uint i = size + 1; --i;)
+ REM_REF((Context)vector_at(&a->known_ctx, i - 1));
vector_release(&a->known_ctx);
+ REM_REF(a->global_nspc);
vector_release(&a->nspc_stack);
vector_release(&a->class_stack);
vector_release(&a->breaks);
describe_nspc_free(Type, type)
ANN static void free_nspc(Nspc a) {
- free_nspc_value(a);
nspc_free_func(a);
nspc_free_type(a);
+ free_nspc_value(a);
if(a->class_data)
free(a->class_data);
ANN static void free_value(Value a) {
if(!GET_FLAG(a, func) && a->d.ptr &&
-!(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class)
-&& isa(a->type, t_object) < 0)
- _mp_free(a->type->size, a->d.ptr);
- if(isa(a->type, t_class) > 0 || isa(a->type, t_function) > 0)
- REM_REF(a->type)
- if(GET_FLAG(a->type, op))
+ !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class)
+ && isa(a->type, t_object) < 0)
+ _mp_free(a->type->size, a->d.ptr);
+ if(isa(a->type, t_class) > 0 || isa(a->type, t_function) > 0 || GET_FLAG(a->type, op))
REM_REF(a->type)
mp_free(Value, a);
}
decl_member(env->curr, v);
else if(GET_FLAG(decl->td, static))
decl_static(env->curr, v);
+ else if(global || (env->func && GET_FLAG(env->func->def, global)))
+ SET_FLAG(v, abstract);
if(isa(decl->type, t_fptr) > 0)
CHECK_BO(check_fptr_decl(env, var))
SET_FLAG(v, checked | ae_flag_used);
ERR_O(primary->self->pos,
"non-static member '%s' used from static function.", s_name(primary->d.var))
return v;
+ } else if(env->func && GET_FLAG(env->func->def, global)) {
+ if(!SAFE_FLAG(value, abstract) && !SAFE_FLAG(value, arg))
+ ERR_O(primary->self->pos,
+ "non-global variable '%s' used from global function.", s_name(primary->d.var))
}
return value;
}
CHECK_BB(check_func_def_override(env, f))
if(env->class_def)
CHECK_BB(check_parent_match(env, f))
+ else if(GET_FLAG(f, global))
+ env_push_global(env);
const Func former = env->func;
env->func = func;
++env->scope;
nspc_pop_value(env->curr);
--env->scope;
env->func = former;
+ if(GET_FLAG(f, global))
+ env_push_global(env);
return ret;
}
--i;
const Symbol sym = func_symbol(env->curr->name, func_name, "template", i);
nspc_add_value(env->curr, sym, value);
- nspc_add_value(env->curr, sym, value);
if(!overload) {
func->vt_index = i;
ADD_REF(value)
ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
Value value = NULL;
f->stack_depth = 0;
+ m_uint scope = env->scope;
+ if(GET_FLAG(f, global))
+ scope = env_push_global(env);
const Value overload = nspc_lookup_value0(env->curr, f->name);
m_str func_name = s_name(f->name);
if(overload)
}
const Func base = get_func(env, f);
if(!base) {
- m_uint scope = env->scope;
- if(GET_FLAG(f, global))
- scope = env_push_global(env);
CHECK_OB((value = func_create(env, f, overload, func_name)))
- if(GET_FLAG(f, global))
- env_pop(env, scope);
} else {
f->func = base;
}
CHECK_BB(scan2_func_def_op(env, f))
SET_FLAG(value, checked);
}
+ if(GET_FLAG(f, global))
+ env_pop(env, scope);
return GW_OK;
}
*(m_uint*) mem = pc; mem += SZ_INT;
pc = 0;
code = *(VM_Code*)reg;
-//puts(code->name);
-// assert(code);
ip = code->instr->ptr + OFFSET;
m_uint stack_depth = code->stack_depth;
if(stack_depth) {
if(overflow_(mem, shred))
Except(shred, "StackOverflow");
}
-//puts(code->name);
DISPATCH();
funcmember:
{