]> Nishi Git Mirror - gwion.git/commitdiff
:art: Split Env
authorfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 4 Mar 2019 09:10:07 +0000 (10:10 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 4 Mar 2019 09:10:07 +0000 (10:10 +0100)
13 files changed:
include/env.h
include/parse.h
src/emit/emit.c
src/lib/func.c
src/oo/context.c
src/oo/env.c
src/oo/env_utils.c
src/oo/switch.c
src/parse/check.c
src/parse/scan0.c
src/parse/scan1.c
src/parse/scan2.c
src/parse/stage.c

index 53ae30f96dfa8402d392a0c0caa38928e1411d13..ca4339e0be5c9ece523084b9fe40993d1e488483 100644 (file)
@@ -14,6 +14,17 @@ struct Switch_ {
   unsigned ok : 1;
 };
 
+struct Env_Scope_ {
+  struct Vector_    nspc_stack;
+  struct Vector_    class_stack;
+  struct Vector_    breaks;
+  struct Vector_    conts;
+  struct Vector_    known_ctx;
+  struct Scope_ swi;
+  size_t depth;
+  size_t type_xid;
+};
+
 typedef struct Env_       * Env;
 struct Env_ {
   m_str name;
@@ -23,14 +34,7 @@ struct Env_ {
   Type      class_def;
   Func      func;
   struct Gwion_ *gwion;
-  struct Vector_    nspc_stack;
-  struct Vector_    class_stack;
-  struct Vector_    breaks;
-  struct Vector_    conts;
-  struct Vector_    known_ctx;
-  struct Scope_ swi;
-  size_t scope;
-  size_t type_xid;
+  struct Env_Scope_* scope;
 };
 
 ANEW Env new_env();
index 8fa50e4e0c0cf86583bd40c2c0c8beefc024c271..bf79aa3e0561894f8b04c6518088ef159e8ada81 100644 (file)
@@ -1,11 +1,11 @@
 #ifndef __PARSE
 #define __PARSE
 #define RET_NSPC(exp)       \
-++env->scope;               \
+++env->scope->depth;        \
 nspc_push_value(env->curr); \
 const m_bool ret = exp;     \
 nspc_pop_value(env->curr);  \
---env->scope;               \
+--env->scope->depth;        \
 return ret;
 
 #define SET_ACCESS(a,b)       \
index 08b88153697650a1708d7774192db106a1b623d4..16534f2744123f22e2bebb117e826928b52dbd98 100644 (file)
@@ -496,7 +496,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Var_Decl va
   if(is_obj && (is_array || !is_ref)) {
     const Instr assign = emit_add_instr(emit, ObjectAssign);
     assign->m_val = (m_uint)emit_var;
-    if(is_array && !emit->env->scope)
+    if(is_array && !emit->env->scope->depth)
       ADD_REF(type)
   }
   return GW_OK;
@@ -522,7 +522,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de
   if(is_obj && (is_array || !is_ref)) {
     const Instr assign = emit_add_instr(emit, ObjectAssign);
     assign->m_val = (m_uint)emit_var;
-    if(is_array && !emit->env->scope)
+    if(is_array && !emit->env->scope->depth)
       ADD_REF(type)
     const Instr instr = emit_add_instr(emit, RegAddRef);
     instr->m_val = emit_var;
@@ -816,7 +816,7 @@ static inline void stack_alloc_this(const Emitter emit) {
 }
 
 static m_bool scoped_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) {
-  ++emit->env->scope;
+  ++emit->env->scope->depth;
   emit_push_scope(emit);
   const m_bool pure = SAFE_FLAG(emit->env->func, pure);
   if(!pure)
@@ -825,7 +825,7 @@ static m_bool scoped_stmt(const Emitter emit, const Stmt stmt, const m_bool pop)
   if(!pure)
     emit_add_instr(emit, GcEnd);
   emit_pop_scope(emit);
-  --emit->env->scope;
+  --emit->env->scope->depth;
   return GW_OK;
 }
 
@@ -904,7 +904,7 @@ ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If* exp_if) { GWDEBU
 ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda) { GWDEBUG_EXE
   if(lambda->def) {
   const m_uint scope = !lambda->owner ?
-    emit->env->scope : emit_push_type(emit, lambda->owner);
+    emit->env->scope->depth : emit_push_type(emit, lambda->owner);
   CHECK_BB(emit_func_def(emit, lambda->def))
   const Instr instr = emit_add_instr(emit, RegPushImm);
   instr->m_val = (m_uint)lambda->def->func->code;
@@ -950,9 +950,9 @@ ANN static m_bool emit_stmt_if(const Emitter emit, const Stmt_If stmt) { GWDEBUG
 }
 
 ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) { GWDEBUG_EXE
-  ++emit->env->scope;
+  ++emit->env->scope->depth;
   const m_bool ret = stmt->stmt_list ? emit_stmt_list(emit, stmt->stmt_list) : 1;
-  --emit->env->scope;
+  --emit->env->scope->depth;
   return ret;
 }
 
@@ -1272,7 +1272,7 @@ ANN void emit_union_offset(Decl_List l, const m_uint o) { GWDEBUG_EXE
 
 ANN static m_bool emit_stmt_union(const Emitter emit, const Stmt_Union stmt) { GWDEBUG_EXE
   Decl_List l = stmt->l;
-  m_uint scope = emit->env->scope;
+  m_uint scope = emit->env->scope->depth;
   const m_bool global = GET_FLAG(stmt, global);
   if(stmt->xid) {
     if(stmt->value->type->nspc->class_data_size && !stmt->value->type->nspc->class_data)
@@ -1644,12 +1644,12 @@ ANN inline void emit_class_finish(const Emitter emit, const Nspc nspc) { GWDEBUG
 }
 
 ANN static inline void emit_class_push(const Emitter emit, const Type type) { GWDEBUG_EXE
-  vector_add(&emit->env->class_stack, (vtype)emit->env->class_def);
+  vector_add(&emit->env->scope->class_stack, (vtype)emit->env->class_def);
   emit->env->class_def = type;
 }
 
 ANN static inline void emit_class_pop(const Emitter emit) { GWDEBUG_EXE
-  emit->env->class_def = (Type)vector_pop(&emit->env->class_stack);
+  emit->env->class_def = (Type)vector_pop(&emit->env->scope->class_stack);
   emit_pop_code(emit);
 }
 
index 24cc059c934b88535a60306d54ba437a04dfa4a1..c2961db174e698b87e922d6a48ab688fd8b9650d 100644 (file)
@@ -67,7 +67,7 @@ ANN static Type fptr_type(Exp_Binary* bin) {
 ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner,
     Exp_Lambda *l, const Func_Def def) {
   const m_uint scope = ((l->owner = owner)) ?
-    env_push_type(env, owner) : env->scope;
+    env_push_type(env, owner) : env->scope->depth;
   Arg_List base = def->arg_list, arg = l->arg;
   while(base && arg) {
     arg->td = base->td;
index 370b3b6325dcc26f19c80bfc900d5e61aacf81f9..cf32a9f55284fc8d0c39da6f8058d4df4408b91a 100644 (file)
@@ -22,7 +22,7 @@ ANN2(2) Context new_context(const Ast ast, const m_str str) {
 
 ANN void load_context(const Context context, const Env env) {
   ADD_REF((env->context = context))
-  vector_add(&env->nspc_stack, (vtype)env->curr);
+  vector_add(&env->scope->nspc_stack, (vtype)env->curr);
   context->nspc->parent = env->curr;
   env->curr = context->nspc;
 }
@@ -35,5 +35,5 @@ ANN void unload_context(const Context context, const Env env) {
     map_release(&context->lbls);
   }
   REM_REF(context);
-  env->curr = (Nspc)vector_pop(&env->nspc_stack);
+  env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
 }
index de50af360b9a93bf39816ebbaca0cbb833851a92..7c319ad3d6ba94ac6cac8752bc769df3dda2df03 100644 (file)
 #include "mpool.h"
 #include "switch.h"
 
+ANN static struct Env_Scope_ *new_scope(void) {
+  struct Env_Scope_ *a = mp_alloc(Env_Scope);
+  vector_init(&a->breaks);
+  vector_init(&a->conts);
+  vector_init(&a->class_stack);
+  vector_init(&a->nspc_stack);
+  vector_init(&a->known_ctx);
+  vector_init((Vector)&a->swi);
+  map_init(&a->swi.map);
+  return a;
+}
+
 Env new_env() {
   const Env env = (Env)xmalloc(sizeof(struct Env_));
   env->global_nspc = new_nspc("global_nspc");
   env->context = NULL;
-  vector_init(&env->breaks);
-  vector_init(&env->conts);
-  vector_init(&env->class_stack);
-  vector_init(&env->nspc_stack);
-  vector_init(&env->known_ctx);
-  env->type_xid = 0;
-  vector_init((Vector)&env->swi);
-  map_init(&env->swi.map);
-
+  env->scope = new_scope();
   env_reset(env);
   return env;
 }
 
 ANN void env_reset(const Env env) {
-  vector_clear(&env->breaks);
-  vector_clear(&env->conts);
-  vector_clear(&env->nspc_stack);
-  vector_add(&env->nspc_stack, (vtype)env->global_nspc);
-  vector_clear(&env->class_stack);
-  vector_add(&env->class_stack, (vtype)NULL);
+  vector_clear(&env->scope->breaks);
+  vector_clear(&env->scope->conts);
+  vector_clear(&env->scope->nspc_stack);
+  vector_add(&env->scope->nspc_stack, (vtype)env->global_nspc);
+  vector_clear(&env->scope->class_stack);
+  vector_add(&env->scope->class_stack, (vtype)NULL);
   env->curr = env->global_nspc;
   env->class_def = NULL;
   env->func = NULL;
-  env->scope = 0;
+  env->scope->depth = 0;
   switch_reset(env);
 }
 
-ANN void free_env(const Env a) {
+ANN static void free_env_scope(struct Env_Scope_  *a) {
   const m_uint size = vector_size(&a->known_ctx);
   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);
   vector_release(&a->conts);
-  switch_reset(a);
   switch_release(&a->swi);
+  mp_free(Env_Scope, a);
+}
+
+ANN void free_env(const Env a) {
+  switch_reset(a);
+  free_env_scope(a->scope);
+  REM_REF(a->global_nspc);
   free(a);
 }
 
 ANN2(1,3) m_uint env_push(const Env env, const Type type, const Nspc nspc) {
-  const m_uint scope = env->scope;
-  vector_add(&env->class_stack, (vtype)env->class_def);
+  const m_uint scope = env->scope->depth;
+  vector_add(&env->scope->class_stack, (vtype)env->class_def);
   env->class_def = type;
-  vector_add(&env->nspc_stack, (vtype)env->curr);
+  vector_add(&env->scope->nspc_stack, (vtype)env->curr);
   env->curr = nspc;
-  env->scope = 0;
+  env->scope->depth = 0;
   return scope;
 }
 
 ANN void env_pop(const Env env, const m_uint scope) {
-  env->class_def = (Type)vector_pop(&env->class_stack);
-  env->curr = (Nspc)vector_pop(&env->nspc_stack);
-  env->scope = scope;
+  env->class_def = (Type)vector_pop(&env->scope->class_stack);
+  env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
+  env->scope->depth = scope;
 }
 
 ANN void env_add_type(const Env env, const Type type) {
@@ -84,7 +93,7 @@ ANN void env_add_type(const Env env, const Type type) {
   SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin);
   nspc_add_value(env->curr, insert_symbol(type->name), v);
   type->owner = env->curr;
-  type->xid = ++env->type_xid;
+  type->xid = ++env->scope->type_xid;
 }
 
 ANN m_bool type_engine_check_prog(const Env env, const Ast ast) {
@@ -94,7 +103,7 @@ ANN m_bool type_engine_check_prog(const Env env, const Ast ast) {
   const m_bool ret = traverse_ast(env, ast);
   if(ret > 0) {
     nspc_commit(env->curr);
-    vector_add(&env->known_ctx, (vtype)ctx);
+    vector_add(&env->scope->known_ctx, (vtype)ctx);
   } else //nspc_rollback(env->global_nspc);
     REM_REF(ctx);
   unload_context(ctx, env);
index 9afc11f3a66462a3acd5ae382b16b39085c95a8d..d496e35defdb174af335822cab50079ad9f1c658 100644 (file)
@@ -19,14 +19,14 @@ ANN Nspc env_nspc(const Env env) {
 
 #define GET(a,b) ((a) & (b)) == (b)
 ANN m_bool env_access(const Env env, const ae_flag flag) {
-  if(env->scope) {
+  if(env->scope->depth) {
    if(GET(flag, ae_flag_global))
       ERR_B(0, "'global' can only be used at %s scope.",
           GET(flag, ae_flag_global) && !env->class_def ?
            "file" : "class")
   }
   if((GET(flag, ae_flag_static) || GET(flag, ae_flag_private) ||
-      GET(flag, ae_flag_protect)) && (!env->class_def || env->scope))
+      GET(flag, ae_flag_protect)) && (!env->class_def || env->scope->depth))
       ERR_B(0, "static/private/protect can only be used at class scope.")
   return GW_OK;
 }
index ec2389778eff5cdf30823d3e32c59e0de31aee24..b4a509076a8bb2294f0bc301b27a2778b77291a3 100644 (file)
@@ -41,7 +41,7 @@ ANN static Switch new_swinfo(const Env env, const Stmt_Switch stmt) {
   info->t = env->class_def;
   info->f = env->func;
   const Switch sw = new_switch();
-  map_set(&env->swi.map, (vtype)info, (vtype)sw);
+  map_set(&env->scope->swi.map, (vtype)info, (vtype)sw);
   return sw;
 }
 
@@ -50,10 +50,10 @@ ANN static inline m_bool swinfo_cmp(const struct SwInfo_ *i1, const struct SwInf
 }
 
 ANN Switch swinfo_get(const Env env, const struct SwInfo_ *info) {
-  for(m_uint i = 0; i < VLEN(&env->swi.map); ++i) {
-    const struct SwInfo_ *key = (const struct SwInfo_*)VKEY(&env->swi.map, i);
+  for(m_uint i = 0; i < VLEN(&env->scope->swi.map); ++i) {
+    const struct SwInfo_ *key = (const struct SwInfo_*)VKEY(&env->scope->swi.map, i);
     if(swinfo_cmp(key, info))
-      return (Switch)VVAL(&env->swi.map, i);
+      return (Switch)VVAL(&env->scope->swi.map, i);
   }
   return NULL;
 }
@@ -61,26 +61,26 @@ 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->swi, (vtype)sw);
+  vector_add((Vector)&env->scope->swi, (vtype)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->swi, (vtype)sw);
+  vector_add((Vector)&env->scope->swi, (vtype)sw);
 }
 
 void switch_reset(const Env env) {
-  for(m_uint i = VLEN(&env->swi.map) + 1; --i;) {
-    struct SwInfo_ *info = (struct SwInfo_ *)VKEY(&env->swi.map, i - 1);
+  for(m_uint i = VLEN(&env->scope->swi.map) + 1; --i;) {
+    struct SwInfo_ *info = (struct SwInfo_ *)VKEY(&env->scope->swi.map, i - 1);
     mp_free(SwInfo, info);
-    Switch sw = (Switch)VVAL(&env->swi.map, i - 1);
+    Switch sw = (Switch)VVAL(&env->scope->swi.map, i - 1);
     free_map(sw->cases);
     free_switch(sw);
   }
-  vector_clear((Vector)&env->swi);
-  map_clear(&env->swi.map);
+  vector_clear((Vector)&env->scope->swi);
+  map_clear(&env->scope->swi.map);
 }
 
 ANN void switch_release(const Scope sw) {
@@ -90,44 +90,44 @@ 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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   vector_add(&sw->exp, (vtype)e);
 }
 
 ANN Exp switch_expget(const Env env) {
-  const Switch sw = (Switch)vector_back((Vector)&env->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   return (Exp)vector_at(&sw->exp, sw->iter++);
 }
 
 ANN m_bool switch_inside(const Env env, const uint pos) {
-  if(!VLEN(&env->swi))
+  if(!VLEN(&env->scope->swi))
     ERR_B(pos, "case found outside switch statement.")
   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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   if(sw->default_case_index)
     ERR_B(pos, "default case already defined")
   sw->default_case_index = pc;
@@ -135,28 +135,28 @@ 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->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   return sw->cases;
 }
 
 ANN Vector switch_vec(const Env env) {
-  const Switch sw = (Switch)vector_back((Vector)&env->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   return vector_copy(sw->vec); // new_vector(); // dyn only
 }
 
 ANN m_uint switch_idx(const Env env) {
-  const Switch sw = (Switch)vector_back((Vector)&env->swi);
+  const Switch sw = (Switch)vector_back((Vector)&env->scope->swi);
   return sw->default_case_index;
 }
 
 ANN void switch_pop(const Env env) {
-  vector_pop((Vector)&env->swi);
+  vector_pop((Vector)&env->scope->swi);
 }
 
 ANN void switch_end(const Env env) {
-  const Switch sw = (Switch)vector_pop((Vector)&env->swi);
-  const vtype index = VKEY(&env->swi.map, VLEN(&env->swi.map) - 1);
-  map_remove(&env->swi.map, index);
+  const Switch sw = (Switch)vector_pop((Vector)&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(sw);
 //  return sw->ok = 1;
 }
index 250d878c3d2dffc02941bf4bcace2291a1066bae..8ea37542ff9f5b923c1f511ac5aaf5629645302a 100644 (file)
@@ -95,7 +95,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { GWDEBUG_EXE
     }
     const Var_Decl var = list->self;
     const Value v = var->value;
-    if(env->class_def && !env->scope && env->class_def->parent)
+    if(env->class_def && !env->scope->depth && env->class_def->parent)
       CHECK_BO(check_exp_decl_parent(env, var))
     if(var->array && var->array->exp)
       CHECK_BO(check_exp_array_subscripts(env, var->array->exp))
@@ -784,16 +784,16 @@ ANN static m_bool check_flow(const Exp exp, const m_str orig) { GWDEBUG_EXE
 }
 
 ANN static m_bool check_breaks(const Env env, const Stmt a, const Stmt b) { GWDEBUG_EXE
-  vector_add(&env->breaks, (vtype)a);
+  vector_add(&env->scope->breaks, (vtype)a);
   RET_NSPC(check_stmt(env, b))
-  vector_pop(&env->breaks);
+  vector_pop(&env->scope->breaks);
   return ret;
 }
 
 ANN static m_bool check_conts(const Env env, const Stmt a, const Stmt b) { GWDEBUG_EXE
-  vector_add(&env->conts, (vtype)a);
+  vector_add(&env->scope->conts, (vtype)a);
   CHECK_BB(check_breaks(env, a, b))
-  vector_pop(&env->conts);
+  vector_pop(&env->scope->conts);
   return GW_OK;
 }
 
@@ -908,7 +908,7 @@ if(env->func->value_ref->type == t_lambda) {
 
 #define describe_check_stmt_stack(stack, name)                                     \
 ANN static m_bool check_stmt_##name(const Env env, const Stmt stmt) { GWDEBUG_EXE \
-  if(!vector_size(&env->stack))                                                    \
+  if(!vector_size(&env->scope->stack))                                                    \
     ERR_B(stmt->pos, "'"#name"' found outside of for/while/until...")             \
   return GW_OK;                                                                        \
 }
@@ -1131,7 +1131,7 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
     env_push_global(env);
   const Func former = env->func;
   env->func = func;
-  ++env->scope;
+  ++env->scope->depth;
   nspc_push_value(env->curr);
   if((f->arg_list && (ret = check_func_args(env, f->arg_list)) > 0) || !f->arg_list) {
   const Value variadic = GET_FLAG(f, variadic) ? set_variadic(env) : NULL;
@@ -1146,7 +1146,7 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
     operator_func(func);
   }
   nspc_pop_value(env->curr);
-  --env->scope;
+  --env->scope->depth;
   env->func = former;
   if(GET_FLAG(f, global))
     env_push_global(env);
index f865c39309aa737bee884d4e45d8979d3758c056..f24a9f84006ad04c3e67a2b0c35a1b0cb7c14ef7 100644 (file)
@@ -41,7 +41,7 @@ ANN static m_bool scan0_stmt_type(const Env env, const Stmt_Type stmt) { GWDEBUG
   CHECK_OB(base)
   CHECK_BB(already_defined(env, stmt->xid, stmt->td->xid->pos)) // test for type ?
   if(!stmt->td->types && (!stmt->td->array || !stmt->td->array->exp)) {
-    const Type t = new_type(++env->type_xid, s_name(stmt->xid), base);
+    const Type t = new_type(++env->scope->type_xid, s_name(stmt->xid), base);
     t->size = base->size;
     const Nspc nspc = (!env->class_def && GET_FLAG(stmt->td, global)) ?
       env->global_nspc : env->curr;
@@ -147,7 +147,7 @@ ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def class_def)
   CHECK_BB(env_access(env, class_def->flag))
   env_storage(env, &class_def->flag);
   if(GET_FLAG(class_def, global)) {
-    vector_add(&env->nspc_stack, (vtype)env->curr);
+    vector_add(&env->scope->nspc_stack, (vtype)env->curr);
     env->curr = env->global_nspc;
   }
   CHECK_BB(already_defined(env, class_def->name->xid, class_def->name->pos)) // test for type ?
@@ -156,7 +156,7 @@ ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def class_def)
 }
 
 ANN static Type scan0_class_def_init(const Env env, const Class_Def class_def) { GWDEBUG_EXE
-  const Type t = new_type(++env->type_xid, s_name(class_def->name->xid), t_object);
+  const Type t = new_type(++env->scope->type_xid, s_name(class_def->name->xid), t_object);
   t->owner = env->curr;
   t->nspc = new_nspc(t->name);
   t->nspc->parent = GET_FLAG(class_def, global) ? env_nspc(env) : env->curr;
@@ -193,7 +193,7 @@ ANN m_bool scan0_class_def(const Env env, const Class_Def class_def) { GWDEBUG_E
   }
   (void)mk_class(env, class_def->type);
   if(GET_FLAG(class_def, global))
-    env->curr = (Nspc)vector_pop(&env->nspc_stack);
+    env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
   return GW_OK;
 }
 
index 148b8fc0fd0a65e4d2992e3a4bd3ef8bf6e1cd9b..7511fef1c4c07110df7452dbd225eb10a203b43a 100644 (file)
@@ -34,7 +34,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) {
   if(GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0))
     ERR_O(decl->self->pos, "can't use protected type %s", t->name)
   if(env->class_def) {
-    if(!env->scope) {
+    if(!env->scope->depth) {
       if(!env->func && !GET_FLAG(decl->td, static))
         SET_FLAG(decl->td, member);
       if(!GET_FLAG(decl->td, ref) && t == env->class_def)
@@ -79,11 +79,11 @@ ANN m_bool scan1_exp_decl(const Env env, Exp_Decl* decl) { GWDEBUG_EXE
     v->flag = decl->td->flag;
     if(var->array && !var->array->exp)
       SET_FLAG(v, ref);
-    if(!env->func && !env->scope && !env->class_def)
+    if(!env->func && !env->scope->depth && !env->class_def)
       SET_FLAG(v, global);
     v->d.ptr = var->addr;
     v->owner = !env->func ? env->curr : NULL;
-    v->owner_class = env->scope ? NULL : env->class_def;
+    v->owner_class = env->scope->depth ? NULL : env->class_def;
   } while((list = list->next));
   decl->type = decl->list->self->value->type;
   if(global)
@@ -277,7 +277,7 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
     return GW_OK;
   const Func former = env->func;
   env->func = FAKE_FUNC;
-  ++env->scope;
+  ++env->scope->depth;
   if(GET_FLAG(f, dtor) && !env->class_def)
     ERR_B(f->td->xid->pos, "dtor must be in class def!!")
   if(f->td)//lambda
@@ -289,7 +289,7 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
   if(GET_FLAG(f, op) && env->class_def)
     SET_FLAG(f, static);
   env->func = former;
-  --env->scope;
+  --env->scope->depth;
   return GW_OK;
 }
 
index 11d71a8c40fc9f147f72575ca1fcec5e2b266778..4f6449591fa677277e5c0256958c528604cab4b9 100644 (file)
@@ -487,7 +487,7 @@ ANN2(1,2,4) static Value func_create(const Env env, const Func_Def f,
 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;
+  m_uint scope = env->scope->depth;
   if(GET_FLAG(f, global))
     scope = env_push_global(env);
   const Value overload = nspc_lookup_value0(env->curr, f->name);
index 48c927f412f70a65a674ffac3b1593e6e35617f6..72573fcfc685c703c930b88079a84084806705a1 100644 (file)
@@ -9,7 +9,7 @@ ANN m_uint union_push(const Env env, const Stmt_Union stmt) {
   const Type type = stmt->xid ? stmt->value->type : stmt->type_xid ?
     stmt->type : NULL;
   return type ? env_push_type(env, type) : GET_FLAG(stmt, global) ?
-    env_push_global(env) : env->scope;
+    env_push_global(env) : env->scope->depth;
 }
 
 ANN void union_pop(const Env env, const Stmt_Union stmt, const m_uint scope) {