-Subproject commit 95d45403dd3a01edfe7dc5e817a931f5c62c98e6
+Subproject commit fbd0bdbb2950dbfc8f62167c795390500d660cfa
static const _exp_func section_func[] = { \
(_exp_func)prefix##_stmt_list, (_exp_func)prefix##_func_def, (_exp_func)prefix##_class_def \
}; \
-ANN static inline m_bool prefix##_section(const void* a, const Section* section) { GWDEBUG_EXE \
- return section_func[section->section_type](a, *(void**)§ion->d); \
+ANN static inline m_bool prefix##_section(const void* a, /* const */ Section* section) { GWDEBUG_EXE \
+ void* d = §ion->d.stmt_list; \
+ return section_func[section->section_type](a, *(void**)d); \
}
#define HANDLE_EXP_FUNC(prefix, type, ret) \
const Value v = prim->value;
if(v->owner_class)
return emit_symbol_owned(emit, prim);
- if(GET_FLAG(v, builtin) || GET_FLAG(v, union))
+ if(GET_FLAG(v, builtin) || GET_FLAG(v, union) || GET_FLAG(v, enum))
return emit_symbol_builtin(emit, prim);
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, prim->self->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase);
}
ANN static m_bool prim_str(const Emitter emit, const Exp_Primary* prim) { GWDEBUG_EXE
- char c[strlen(prim->d.str)];
- strcpy(c, prim->d.str);
- CHECK_BB(escape_str(c, prim->self->pos));
+ char c[strlen(prim->d.str) + 1];
+ if(strlen(prim->d.str)) {
+ strcpy(c, prim->d.str);
+ CHECK_BB(escape_str(c, prim->self->pos));
+ } else c[0] = '\0';
const Instr instr = emit_add_instr(emit, RegPushStr);
instr->m_val = (m_uint)s_name(insert_symbol(c));
return GW_OK;
v->offset = emit_local(emit, SZ_INT, 0);
v->d.ptr = addr;
} else
- *(m_uint*)(emit->env->class_def->nspc->info->class_data + v->offset) = i;
+// *(m_uint*)(emit->env->class_def->nspc->info->class_data + v->offset) = i;
+// alignement
+ *(m_bit*)(emit->env->class_def->nspc->info->class_data + v->offset) = i;
}
return GW_OK;
}
Instr instr = (Instr)vector_back(func->code->instr);
instr->opcode = eOP_MAX;
instr->execute = DTOR_EOC;
+ instr->m_val = (m_uint)emit->gwion->p;
ADD_REF(func->code)
}
}
ANN void gwion_end(const Gwion gwion) {
const VM_Code code = new_vm_code(gwion->p, NULL, 0, ae_flag_builtin, "in code dtor");
gwion->vm->cleaner_shred = new_vm_shred(gwion->p, code);
- gwion->vm->cleaner_shred->info->vm = gwion->vm;
+ vm_add_shred(gwion->vm, gwion->vm->cleaner_shred);
free_env(gwion->env);
free_vm_shred(gwion->vm->cleaner_shred);
free_emitter(gwion->emit);
#include "func.h"
#include "array.h"
#include "nspc.h"
+#include "shreduler_private.h"
INSTR(EOC) { GWDEBUG_EXE
vm_shred_exit(shred);
}
-
+#include "gwion.h"
INSTR(DTOR_EOC) { GWDEBUG_EXE
+ // TODO: we should be able to use shred->info->mp directly
+ shred->info->mp = (MemPool)instr->m_val;
const M_Object o = *(M_Object*)MEM(0);
o->type_ref = o->type_ref->parent;
- _release(o, shred);
- if(shred->info->me->ref > 1) // ???
- _release(shred->info->me, shred);
+printf("'obj %p %p %s\n", o, shred->info->me, shred->info->me->type_ref->name);
+//free_object(
+ __release(o, shred);
+//shreduler_remove(shred->tick->shreduler, shred, 0);
+//vector_rem2(&shred->tick->shreduler->shreds, shred);
+//++shred->info->me->ref;
+//REM_REF(shred->code, shred->info->vm->gwion);
+// _release(shred->info->me, shred);
+// _release(shred->info->me, shred);
+//free_vm_shred(shred);
vm_shred_exit(shred);
}
ANN static void handle_dtor(const M_Object object, const VM_Shred shred) {
const Type t = object->type_ref;
const VM_Shred sh = new_vm_shred(shred->info->mp, t->nspc->dtor);
- ADD_REF(t->nspc->dtor);
sh->base = shred->base;
- memcpy(sh->reg, shred->reg, SIZEOF_REG);
*(M_Object*)sh->mem = object;
vm_add_shred(shred->info->vm, sh);
- ++sh->info->me->ref;
}
__attribute__((hot))
ANN void __release(const M_Object obj, const VM_Shred shred) {
- // TODO: find what's going on here
- // we should be able to use shred->info->mp directly
- MemPool p = shred->info->mp= shred->info->vm->gwion->p;
+ MemPool p = shred->info->mp;// = shred->info->vm->gwion->p;
Type t = obj->type_ref;
while(t->parent) {
struct scope_iter iter = { &t->nspc->info->value, 0, 0 };\
vector_init(&a->class_stack);
vector_init(&a->nspc_stack);
vector_init(&a->known_ctx);
- vector_init((Vector)&a->swi);
+ _scope_init(&a->swi);
map_init(&a->swi.map);
return a;
}
#include "context.h"
#include "nspc.h"
+static inline void _scope_add(Scope s, Switch sw) { vector_add((Vector)(void*)s, (vtype)sw); }
+static inline vtype _scope_pop(Scope s) { return vector_pop((Vector)(void*)s); }
+static inline vtype _scope_back(Scope s) { return vector_back((Vector)(void*)s); }
+static inline void _scope_clear(Scope s) { vector_clear((Vector)(void*)s); }
+
static Switch new_switch(MemPool p) {
Switch sw = mp_alloc(p, Switch);
sw->cases = new_map(p); // could be struct ?
ANN m_bool switch_add(const Env env, const Stmt_Switch stmt) {
const struct SwInfo_ info = { stmt, env->class_def, env->func };
Switch sw = (Switch)swinfo_get(env, &info) ?: new_swinfo(env, stmt);
- vector_add((Vector)&env->scope->swi, (vtype)sw);
+ _scope_add(&env->scope->swi, sw);
return GW_OK;
}
ANN void switch_get(const Env env, const Stmt_Switch stmt) {
const struct SwInfo_ info = { stmt, env->class_def, env->func };
const Switch sw = swinfo_get(env, &info);
- vector_add((Vector)&env->scope->swi, (vtype)sw);
+ _scope_add(&env->scope->swi, sw);
}
void switch_reset(const Env env) {
free_map(env->gwion->p, sw->cases);
free_switch(env->gwion->p, sw);
}
- vector_clear((Vector)&env->scope->swi);
+ _scope_clear(&env->scope->swi);
map_clear(&env->scope->swi.map);
}
}
ANN void switch_expset(const Env env, const Exp e) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
vector_add(&sw->exp, (vtype)e);
}
ANN Exp switch_expget(const Env env) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
return (Exp)vector_at(&sw->exp, sw->iter++);
}
return GW_OK;
}
ANN m_bool switch_dup(const Env env, const m_int value, const uint pos) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
if(map_get(sw->cases, (vtype)value))
ERR_B(pos, "duplicated cases value %i", value)
return GW_OK;
}
ANN void switch_pc(const Env env, const m_uint pc) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
vector_add(sw->vec, pc);
}
ANN void switch_dynpc(const Env env, const m_int val, const m_uint pc) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
map_set(sw->cases, val, pc);
}
ANN m_bool switch_dyn(const Env env) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
return vector_size(&sw->exp);
}
ANN m_bool switch_default(const Env env, const m_uint pc, const uint pos) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
if(sw->default_case_index)
ERR_B(pos, "default case already defined")
sw->default_case_index = pc;
}
ANN Map switch_map(const Env env) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
return sw->cases;
}
ANN Vector switch_vec(const Env env) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
return vector_copy(env->gwion->p, sw->vec); // new_vector(); // dyn only
}
ANN m_uint switch_idx(const Env env) {
- const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(&env->scope->swi);
return sw->default_case_index;
}
ANN void switch_pop(const Env env) {
- vector_pop((Vector)&env->scope->swi);
+ _scope_pop(&env->scope->swi);
}
ANN void switch_end(const Env env) {
- const Switch sw = (Switch)vector_pop((Vector)&env->scope->swi);
+ const Switch sw = (Switch)_scope_pop(&env->scope->swi);
const vtype index = VKEY(&env->scope->swi.map, VLEN(&env->scope->swi.map) - 1);
map_remove(&env->scope->swi.map, index);
free_switch(env->gwion->p, sw);
CHECK_BB(env_access(env, decl->td->flag))
env_storage(env, &decl->td->flag);
Var_Decl_List list = decl->list;
- m_uint scope;
((Exp_Decl*)decl)->type = scan1_exp_decl_type(env, (Exp_Decl*)decl);
CHECK_OB(decl->type)
const m_bool global = GET_FLAG(decl->td, global);
+ m_uint scope = !global ? env->scope->depth : env_push_global(env);
const Nspc nspc = !global ? env->curr : env->global_nspc;
if(global)
scope = env_push_global(env);
shredule(vm->shreduler, shred, .5);
return shred->tick->xid;
}
+
#include "gwion.h"
ANN m_uint vm_fork(const VM* src, const VM_Shred shred) {
VM* vm = shred->info->vm = gwion_cpy(src);
*(m_int*)(reg + SZ_FLOAT-SZ_INT)); \
DISPATCH()
-#define FI_R(op) \
+#define FI_R(op, ...) \
reg -= SZ_FLOAT; \
+ __VA_ARGS__ \
*(m_int*)(reg-SZ_INT) = (**(m_int**)(reg+SZ_FLOAT -SZ_INT) op##= \
(m_int)(*(m_float*)(reg-SZ_INT))); \
DISPATCH()
DISPATCH();
regpushmemother:
// LOOP_OPTIM
- for(m_uint i = 0; i <= instr->m_val2; i+= SZ_INT)
- *(m_uint*)(reg+i) = *(m_uint*)((mem + instr->m_val) + i);
+ for(m_uint i = 0; i <= instr->m_val2; i+= SZ_INT) {
+ m_uint* m0 = __builtin_assume_aligned((m_bit*)mem+i, SZ_INT);
+printf("%p\n", m0);
+// m_uint* m = __builtin_assume_aligned((m_bit*)mem+instr->m_val+i, SZ_INT);
+ m_uint* r = __builtin_assume_aligned(reg+i, SZ_INT);
+// *(m_uint*)(reg+i) = *(m_uint*)((m_bit*)(mem + instr->m_val) + i);
+// *(m_uint*)(r) = *(m_uint*)(m);
+ *(m_uint*)(r) = *(m_uint*)(m0+instr->m_val);
+ }
reg += instr->m_val2;
DISPATCH();
-regpushmemaddr:
- *(m_bit**)reg = (mem + instr->m_val);
+regpushmemaddr: {
+m_bit* r0 __attribute__((aligned(SZ_INT))) = __builtin_assume_aligned(reg, SZ_INT);
+m_bit* m0 __attribute__((aligned(SZ_INT))) = mem + instr->m_val;
+// m_uint* r __attribute__((aligned(SZ_INT))) = r0;//__builtin_assume_aligned(reg, SZ_INT);
+// *(m_bit**)reg = __builtin_assume_aligned(mem + instr->m_val, SZ_INT);
+ *(void**)r0 = m0;
reg += SZ_INT;
+ }
DISPATCH()
pushnow:
*(m_float*)reg = vm->bbq->pos;
firadd: FI_R(+)
firsub: FI_R(-)
firmul: FI_R(*)
-firdiv: FI_R(/)
+firdiv: FI_R(/, TEST0(m_int, -SZ_INT))
itof:
reg -= SZ_INT - SZ_FLOAT;
-Subproject commit 30f6ebb77737c1542c8eb677bf2b4d6acc0d166a
+Subproject commit df286d4a0bf588e8b02e6864ea12382137f3accc