]> Nishi Git Mirror - gwion.git/commitdiff
:art: More clean
authorfennecdjay <astor.jeremie@wanadoo.fr>
Wed, 3 Apr 2019 23:34:14 +0000 (01:34 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Wed, 3 Apr 2019 23:34:14 +0000 (01:34 +0200)
ast
include/parse.h
src/emit/emit.c
src/gwion.c
src/lib/instr.c
src/lib/object.c
src/oo/env.c
src/oo/switch.c
src/parse/scan1.c
src/vm/vm.c
util

diff --git a/ast b/ast
index 95d45403dd3a01edfe7dc5e817a931f5c62c98e6..fbd0bdbb2950dbfc8f62167c795390500d660cfa 160000 (submodule)
--- a/ast
+++ b/ast
@@ -1 +1 @@
-Subproject commit 95d45403dd3a01edfe7dc5e817a931f5c62c98e6
+Subproject commit fbd0bdbb2950dbfc8f62167c795390500d660cfa
index 0f9c07baac886c41d0b91eeccbb4f4022062f526..65baed41bd57016c9d48d09499d7a0887a8d646c 100644 (file)
@@ -34,8 +34,9 @@ static const _exp_func exp_func[] = {
 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**)&section->d);                            \
+ANN static inline m_bool prefix##_section(const void* a, /* const */ Section* section) { GWDEBUG_EXE    \
+  void* d = &section->d.stmt_list;                            \
+  return section_func[section->section_type](a, *(void**)d);                            \
 }
 
 #define HANDLE_EXP_FUNC(prefix, type, ret)                                                        \
index 11d4adcb562d8a6e562f5b3eca4e0f42d21f58ac..dbf53dc2c85d672aeceba9f3b39b24f14472fb8a 100644 (file)
@@ -317,7 +317,7 @@ ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) { GWD
   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);
@@ -451,9 +451,11 @@ ANN static m_bool prim_char(const Emitter emit, const Exp_Primary* prim) {
 }
 
 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;
@@ -1332,7 +1334,9 @@ ANN static m_bool emit_stmt_enum(const Emitter emit, const Stmt_Enum stmt) { GWD
       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;
 }
@@ -1654,6 +1658,7 @@ ANN static void emit_func_def_code(const Emitter emit, const Func func) { GWDEBU
     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)
   }
 }
index 8abcbb9446084107c253ed4d6376590d7b03d0be..13fe101d61ca66b1e75205c471b162a20b4d2364 100644 (file)
@@ -99,7 +99,7 @@ ANN void gwion_run(const Gwion gwion) {
 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);
index 4564ab386a0248eb3c04d032e4408205aff0430f..8eb7cfbbcb36de2ae8ff467fcfee0735c5ad1ebb 100644 (file)
 #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);
 }
 
index e43ff7b9a433164e63dd73c04b39c2fbc27d131f..44214a81dad673225866debb43b1dd125070b007 100644 (file)
@@ -59,19 +59,14 @@ ANN void instantiate_object(const VM_Shred shred, const Type type) {
 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 };\
index 3639126254b8eecc907756f6a7f5e0797f06521b..a535ad36a846fc3a7f29a9cd94d73e056a1a1f75 100644 (file)
@@ -23,7 +23,7 @@ ANN static struct Env_Scope_ *new_scope(MemPool p) {
   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;
 }
index cc5e0434eb221a13c91f3ff38394342e064083f9..e1859a5486bb45ba1fead714914b736a64e633eb 100644 (file)
 #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 ?
@@ -60,14 +65,14 @@ ANN Switch swinfo_get(const Env env, const struct SwInfo_ *info) {
 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) {
@@ -78,7 +83,7 @@ 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);
 }
 
@@ -89,12 +94,12 @@ ANN void switch_release(const Scope sw) {
 }
 
 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++);
 }
 
@@ -104,29 +109,29 @@ ANN m_bool switch_inside(const Env env, const uint pos) {
   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;
@@ -134,26 +139,26 @@ ANN m_bool switch_default(const Env env, const m_uint pc, const uint pos) {
 }
 
 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);
index 8a0c53a5c8651fbdc79f8166e080a296ae327fa1..8dd975be5f037ea44a0f590e6048d87d6f281789 100644 (file)
@@ -53,10 +53,10 @@ ANN m_bool scan1_exp_decl(const Env env, Exp_Decl* decl) { GWDEBUG_EXE
   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);
index 9b6a9f252c089021b95c23ce835a429416dace4f..560e2a83548a28538daa2ef2765c1a508dacb847 100644 (file)
@@ -86,6 +86,7 @@ ANN m_uint vm_add_shred(const VM* vm, const VM_Shred shred) {
   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);
@@ -232,8 +233,9 @@ __attribute__((hot))
     *(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()
@@ -344,13 +346,25 @@ regpushmemfloat:
   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;
@@ -543,7 +557,7 @@ firassign:
 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;
diff --git a/util b/util
index 30f6ebb77737c1542c8eb677bf2b4d6acc0d166a..df286d4a0bf588e8b02e6864ea12382137f3accc 160000 (submodule)
--- a/util
+++ b/util
@@ -1 +1 @@
-Subproject commit 30f6ebb77737c1542c8eb677bf2b4d6acc0d166a
+Subproject commit df286d4a0bf588e8b02e6864ea12382137f3accc