]> Nishi Git Mirror - gwion.git/commitdiff
:art: Split Common structures
authorfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 1 Apr 2019 16:22:01 +0000 (18:22 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 1 Apr 2019 16:22:01 +0000 (18:22 +0200)
16 files changed:
ast
src/emit/emit.c
src/lib/func.c
src/lib/import.c
src/lib/instr.c
src/oo/type.c
src/parse/check.c
src/parse/func.c
src/parse/scan0.c
src/parse/scan1.c
src/parse/scan2.c
src/parse/template.c
tests/error/override_confict.gw
tests/error/self_extend.gw
tests/error/undef_parent.gw
tests/import/callback.c

diff --git a/ast b/ast
index 25337f99739d1844469e6fc2f3c07feda0d99b40..31cd8af5a79fe16e5b67fb8a456848eb99e24b05 160000 (submodule)
--- a/ast
+++ b/ast
@@ -1 +1 @@
-Subproject commit 25337f99739d1844469e6fc2f3c07feda0d99b40
+Subproject commit 31cd8af5a79fe16e5b67fb8a456848eb99e24b05
index 8ed143f2717023d30ab0eee52faa1d157560c1dd..b5faf8eadf2cd874c3d54e72d66788f29b7cf4db 100644 (file)
@@ -612,7 +612,7 @@ else
 
 ANN static m_uint vararg_size(const Exp_Call* exp_call, const Vector kinds) {
   Exp e = exp_call->args;
-  Arg_List l = exp_call->m_func->def->args;
+  Arg_List l = exp_call->m_func->def->base->args;
   m_uint size = 0;
   while(e) {
     if(!l) {
@@ -829,7 +829,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { GWDEBUG_EXE
   const Instr offset = emit_add_instr(emit, RegSetImm);
   offset->m_val = emit_code_offset(emit);
   const Instr instr = emit_call(emit, f);
-  instr->m_val = f->def->ret_type->size;
+  instr->m_val = f->def->base->ret_type->size;
   instr->m_val2 = offset->m_val;
   return GW_OK;
 }
@@ -923,7 +923,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary* unary) {
     const m_uint size = f->def->stack_depth - (GET_FLAG(f, member) ? SZ_INT : 0);
     emit_exp_spork_finish(emit, code, size);
     const Instr end = emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd);
-    end->m_val2 = unary->exp->d.exp_call.m_func->def->ret_type->size;
+    end->m_val2 = unary->exp->d.exp_call.m_func->def->base->ret_type->size;
   }
   return GW_OK;
 }
@@ -970,7 +970,7 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda)
     if(GET_FLAG(lambda->def, member))
       emit_add_instr(emit, RegPushMem);
     const Instr instr = emit_add_instr(emit, RegPushImm);
-    instr->m_val = (m_uint)lambda->def->func->code;
+    instr->m_val = (m_uint)lambda->def->base->func->code;
     if(lambda->owner)
       emit_pop(emit, scope);
   } else
@@ -1503,7 +1503,7 @@ ANN static m_bool emit_vararg_end(const Emitter emit, const m_uint offset) { GWD
 
 ANN static m_bool emit_vararg(const Emitter emit, const Exp_Dot* member) { GWDEBUG_EXE
   m_uint offset = emit->env->class_def ? SZ_INT : 0;
-  Arg_List l = emit->env->func->def->args;
+  Arg_List l = emit->env->func->def->base->args;
   const m_str str = s_name(member->xid);
   while(l) {
     offset += l->type->size;
@@ -1625,7 +1625,7 @@ ANN static void emit_func_def_args(const Emitter emit, Arg_List a) { GWDEBUG_EXE
 }
 
 ANN static void emit_func_def_ensure(const Emitter emit, const Func_Def func_def) { GWDEBUG_EXE
-  const m_uint size = func_def->ret_type->size;
+  const m_uint size = func_def->base->ret_type->size;
   if(size) {
     const Instr instr = emit_kind(emit, size, 0, regpushimm);
     instr->m_val2 = size;
@@ -1658,8 +1658,8 @@ ANN static void emit_func_def_code(const Emitter emit, const Func func) { GWDEBU
 }
 
 ANN static m_bool emit_func_def_body(const Emitter emit, const Func_Def func_def) { GWDEBUG_EXE
-  if(func_def->args)
-    emit_func_def_args(emit, func_def->args);
+  if(func_def->base->args)
+    emit_func_def_args(emit, func_def->base->args);
   if(GET_FLAG(func_def, variadic))
     stack_alloc(emit);
   if(func_def->d.code->d.stmt_code.stmt_list)
@@ -1686,7 +1686,7 @@ ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def) { G
   emit->env->func = func;
   CHECK_BB(emit_func_def_body(emit, func_def))
   if(GET_FLAG(func_def, variadic) && !emit->env->func->variadic)
-    ERR_B(func_def->td->xid->pos, "invalid variadic use")
+    ERR_B(func_def->base->td->xid->pos, "invalid variadic use")
   emit_func_def_return(emit);
   emit_func_def_code(emit, func);
   emit->env->func = former;
@@ -1724,13 +1724,13 @@ ANN static inline void emit_class_pop(const Emitter emit) { GWDEBUG_EXE
 }
 
 ANN static m_bool emit_class_def(const Emitter emit, const Class_Def class_def) { GWDEBUG_EXE
-  const Type type = class_def->type;
+  const Type type = class_def->base.type;
   const Nspc nspc = type->nspc;
   if(tmpl_class_base(class_def->tmpl))
     return GW_OK;
-  if(class_def->ext && ((/*!GET_FLAG(type->parent, emit) &&*/
-      GET_FLAG(class_def->ext, typedef)) || class_def->ext->types)) {
-    const Type base = class_def->ext->array ?
+  if(class_def->base.ext && ((/*!GET_FLAG(type->parent, emit) &&*/
+      GET_FLAG(class_def->base.ext, typedef)) || class_def->base.ext->types)) {
+    const Type base = class_def->base.ext->array ?
              array_base(type->parent) : type->parent;
     if(!base->nspc->pre_ctor)
       CHECK_BB(emit_class_def(emit, base->def))
@@ -1739,8 +1739,8 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def class_def)
     nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size);
   emit_class_push(emit, type);
   emit_class_code(emit, type->name);
-  if(class_def->ext && class_def->ext->array)
-    CHECK_BB(emit_array_extend(emit, type->parent, class_def->ext->array->exp))
+  if(class_def->base.ext && class_def->base.ext->array)
+    CHECK_BB(emit_array_extend(emit, type->parent, class_def->base.ext->array->exp))
   if(class_def->body) {
     Class_Body body = class_def->body;
     do CHECK_BB(emit_section(emit, body->section))
index ce3fde4debb4c42911a3c46813d7744311e31768..5d5187e311b26d88d1ac7a316f7dec73d282f606 100644 (file)
@@ -46,7 +46,7 @@ ANN static Type fptr_type(const Env env, Exp_Binary* bin) {
   const Func l_func = bin->lhs->type->d.func;
   const Func r_func = bin->rhs->type->d.func;
   const Nspc nspc = l_func->value_ref->owner;
-  const m_str c = s_name(l_func->def->name);
+  const m_str c = s_name(l_func->def->base->xid);
   const Value v = l_func->value_ref;
   for(m_uint i = 0; i <= v->offset; ++i) {
     const Symbol sym = func_symbol(env, nspc->name, c, NULL, i);
@@ -62,7 +62,7 @@ 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->depth;
-  Arg_List base = def->args, arg = l->arg;
+  Arg_List base = def->base->args, arg = l->args;
   while(base && arg) {
     arg->td = base->td;
     base = base->next;
@@ -70,9 +70,9 @@ ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner,
   }
   if(base || arg)
     ERR_B(l->self->pos, "argument number does not match for lambda")
-  l->def = new_func_def(def->td, l->name, l->arg, l->code, def->flag);
+  l->def = new_func_def(new_func_base(def->base->td, l->name, l->args), l->code, def->flag);
   const m_bool ret = traverse_func_def(env, l->def);
-  arg = l->arg;
+  arg = l->args;
   while(arg) {
     arg->td = NULL;
     arg = arg->next;
@@ -111,12 +111,12 @@ static OP_CHECK(opck_fptr_at) {
       ERR_N(bin->self->pos, "can't assign static function to member function pointer")
   } else if(GET_FLAG(l_func, member))
       ERR_N(bin->self->pos, "can't assign member function to static function pointer")
-  if(isa(r_fdef->ret_type, l_fdef->ret_type) < 0)
+  if(isa(r_fdef->base->ret_type, l_fdef->base->ret_type) < 0)
     ERR_N(bin->self->pos, "return type '%s' does not match '%s'\n\t... in pointer assignement",
-         r_fdef->ret_type->name, l_fdef->ret_type->name)
+         r_fdef->base->ret_type->name, l_fdef->base->ret_type->name)
   if(GET_FLAG(l_fdef, variadic) != GET_FLAG(r_fdef, variadic))
     ERR_N(bin->self->pos, "function must be of same argument kind.",
-         r_fdef->ret_type->name, l_fdef->ret_type->name)
+         r_fdef->base->ret_type->name, l_fdef->base->ret_type->name)
   if(isa(bin->lhs->type, t_fptr) > 0 && isa(bin->lhs->type, bin->rhs->type) > 0)
     return bin->rhs->type;
   return fptr_type(env, bin);
index 1a20bc44d761386f682a38a5deada32f970c278a..11b53fc000585cb26e133a3c16fa1393f3995267 100644 (file)
@@ -209,9 +209,9 @@ ANN2(1,2) m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_c
     ERR_B(0, "during import: class '%s' already imported.", type->name)
   if(gwi->templater.n) {
     const ID_List types = templater_def(gwi->gwion->st,&gwi->templater);
-    type->def = new_class_def(0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL);
+    type->def = new_class_def(0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, 0);
     type->def->tmpl = new_tmpl_class(types, -1);
-    type->def->type = type;
+    type->def->base.type = type;
     SET_FLAG(type, template);
   } else
     SET_FLAG(type, scan1 | ae_flag_scan2 | ae_flag_check | ae_flag_emit);
@@ -225,7 +225,7 @@ ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td) {
     ERR_B(0, "gwi_class_ext invoked before gwi_class_ini")
   const VM_Code ctor = gwi->gwion->env->class_def->nspc->pre_ctor;
   if(gwi->gwion->env->class_def->parent ||
-      (gwi->gwion->env->class_def->def && gwi->gwion->env->class_def->def->ext))
+      (gwi->gwion->env->class_def->def && gwi->gwion->env->class_def->def->base.ext))
     ERR_B(0, "class extend already set")
   if(td->array && !td->array->exp)
     ERR_B(0, "class extend array can't be empty")
@@ -248,7 +248,7 @@ ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td) {
     free_type_decl(td);
   } else {
     SET_FLAG(td, typedef);
-    gwi->gwion->env->class_def->def->ext = td;
+    gwi->gwion->env->class_def->def->base.ext = td;
   }
   return GW_OK;
 }
@@ -434,7 +434,7 @@ ANN static Func_Def make_dll_as_fun(const Env env, DL_Func * dl_fun, ae_flag fla
   }
   name = dl_fun->name;
   arg_list = make_dll_arg_list(env, dl_fun);
-  func_def = new_func_def(type_decl, insert_symbol(env->gwion->st, name), arg_list, NULL, flag);
+  func_def = new_func_def(new_func_base(type_decl, insert_symbol(env->gwion->st, name), arg_list), NULL, flag);
   func_def->d.dl_func_ptr = (void*)(m_uint)dl_fun->addr;
   return func_def;
 }
@@ -448,7 +448,7 @@ ANN m_int gwi_func_end(const Gwi gwi, const ae_flag flag) {
   Func_Def def = import_fun(gwi->gwion->env, &gwi->func, flag);
   CHECK_OB(def)
   if(gwi->templater.n) {
-    def = new_func_def(NULL, NULL, NULL, NULL, 0);
+    def = new_func_def(new_func_base(NULL, NULL, NULL), NULL, 0);
     const ID_List list = templater_def(gwi->gwion->st, &gwi->templater);
     def->tmpl = new_tmpl_list(list, -1);
     SET_FLAG(def, template);
@@ -532,17 +532,17 @@ ANN static Stmt import_fptr(const Env env, DL_Func* dl_fun, ae_flag flag) {
       !(type_decl = new_type_decl(type_path, 0)))
     ERR_O(0, "\t...\tduring fptr import '%s' (type).",
           dl_fun->name)
-  return new_stmt_fptr(insert_symbol(env->gwion->st, dl_fun->name), type_decl, args, flag);
+  struct Func_Base_ *base = new_func_base(type_decl, insert_symbol(env->gwion->st, dl_fun->name), args);
+  return new_stmt_fptr(base, flag);
 }
 
 ANN m_int gwi_fptr_end(const Gwi gwi, const ae_flag flag) {
   const Stmt stmt = import_fptr(gwi->gwion->env, &gwi->func, flag);
-
   CHECK_BB(traverse_stmt_fptr(gwi->gwion->env, &stmt->d.stmt_fptr))
   if(gwi->gwion->env->class_def)
-    SET_FLAG(stmt->d.stmt_fptr.func->def, builtin);
+    SET_FLAG(stmt->d.stmt_fptr.base->func->def, builtin);
   else
-    SET_FLAG(stmt->d.stmt_fptr.func, builtin);
+    SET_FLAG(stmt->d.stmt_fptr.base->func, builtin);
   ADD_REF(stmt->d.stmt_fptr.type);
   free_stmt(stmt);
   return GW_OK;
index e1671e8459ffaa712b2e346116c81b45b2646c18..26c43620e2f3f472d1e6fee3deafb47f945ec233 100644 (file)
@@ -62,13 +62,13 @@ INSTR(PopArrayClass) { GWDEBUG_EXE
 #include "template.h"
 
 ANN static Func_Def from_base(const Env env, const struct dottmpl_ *dt, const Type t) {
-  const Symbol sym = func_symbol(env, t->name, s_name(dt->base->name),
+  const Symbol sym = func_symbol(env, t->name, s_name(dt->base->base->xid),
     "template", dt->overload);
   const Value v = nspc_lookup_value1(t->nspc, sym);
   CHECK_OO(v)
   const Func_Def base = v->d.func_ref->def;
-  const Func_Def def = new_func_def(base->td, insert_symbol(env->gwion->st, v->name),
-            base->args, base->d.code, base->flag);
+  const Func_Def def = new_func_def(new_func_base(base->base->td, insert_symbol(env->gwion->st, v->name),
+            base->base->args), base->d.code, base->flag);
   def->tmpl = new_tmpl_list(base->tmpl->list, dt->overload);
   SET_FLAG(def, template);
   return def;
@@ -103,7 +103,7 @@ INSTR(DotTmpl) {
       dt->def = def; //
       dt->owner = t; //
       if(traverse_dot_tmpl(emit, dt) > 0) {
-        *(VM_Code*)shred->reg = def->func->code;
+        *(VM_Code*)shred->reg = def->base->func->code;
         shred->reg += SZ_INT;
         return;
       }
index 0d6c92532121355ef7f352a7906d3305634c09ec..2fad207d99bbbdb8667ca146018b9408d59f606f 100644 (file)
@@ -104,7 +104,7 @@ ANN m_bool type_ref(Type t) {
     if(GET_FLAG(t, empty))
       return GW_OK;
     if(GET_FLAG(t, typedef) && t->def)
-      if(t->def->ext && t->def->ext->array && !t->def->ext->array->exp)
+      if(t->def->base.ext && t->def->base.ext->array && !t->def->base.ext->array->exp)
         return GW_OK;
   } while((t = t->parent));
   return 0;
index 0a7b1f736dc8335a662df081b27fa7ada955f391..8686c75f368e87c334f633104eab71e321ca79b8 100644 (file)
@@ -337,7 +337,8 @@ ANN2(1,2) static Func find_func_match_actual(const Env env, Func func, const Exp
   const m_bool implicit, const m_bool specific) {
   do {
     Exp e = args;
-    Arg_List e1 = func->def->args;
+printf("base %s %p %p\n", func->name, func->def->base, func->def);
+    Arg_List e1 = func->def->base->args;
     while(e) {
       if(!e1) {
         if(GET_FLAG(func->def, variadic))
@@ -408,18 +409,18 @@ ANN static Func _find_template_match(const Env env, const Value v, const Exp_Cal
       if(!(value = template_get_ready(env, v, "template", i)))
         continue;
       base = value->d.func_ref->def;
-      def = new_func_def(base->td, insert_symbol(v->name),
-                base->args, base->d.code, base->flag);
+      def = new_func_def(new_func_base(base->base->td, insert_symbol(v->name),
+                base->base->args), base->d.code, base->flag);
       def->tmpl = new_tmpl_list(base->tmpl->list, (m_int)i);
       SET_FLAG(def, template);
     }
     if(traverse_func_template(env, def, types) > 0) {
       nspc_pop_type(env->curr);
       if(check_call(env, exp) > 0) {
-        const Func next = def->func->next;
-        def->func->next = NULL;
-        m_func = find_func_match(env, def->func, args);
-        def->func->next = next;
+        const Func next = def->base->func->next;
+        def->base->func->next = NULL;
+        m_func = find_func_match(env, def->base->func, args);
+        def->base->func->next = next;
         if(m_func) {
           SET_FLAG(m_func, checked | ae_flag_template);
           goto end;
@@ -439,7 +440,7 @@ ANN Func find_template_match(const Env env, const Value value, const Exp_Call* e
   if(f)
     return f;
   while(t) {
-   Value v = nspc_lookup_value1(t->nspc, value->d.func_ref->def->name);
+   Value v = nspc_lookup_value1(t->nspc, value->d.func_ref->def->base->xid);
    if(!v)
      goto next;
    const Func f = _find_template_match(env, v, exp);
@@ -472,7 +473,7 @@ ANN2(1) static void* function_alternative(const Type f, const Exp args){
   Func up = f->d.func;
   do {
     gw_err("(%s)\t", up->name);
-    const Arg_List e = up->def->args;
+    const Arg_List e = up->def->base->args;
     e ? print_arg(e) : (void)gw_err("\033[32mvoid\033[0m");
     gw_err("\n");
   } while((up = up->next));
@@ -512,7 +513,7 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) {
   Type_List tl[type_number];
   ID_List list = value->d.func_ref->def->tmpl->list;
   while(list) {
-    Arg_List arg = value->d.func_ref->def->args;
+    Arg_List arg = value->d.func_ref->def->base->args;
     Exp template_arg = args;
     while(arg && template_arg) {
       char path[id_list_len(arg->td->xid)];
@@ -535,7 +536,7 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) {
   const Exp_Call tmp_func = { .func=call, .args=args, .tmpl=&tmpl, .self=base };
   const Func func = get_template_func(env, &tmp_func, value);
   base->d.exp_call.m_func = func;
-  return func ? func->def->ret_type : NULL;
+  return func ? func->def->base->ret_type : NULL;
 }
 
 ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) {
@@ -550,7 +551,7 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
   if(exp->args)
     CHECK_OO(check_exp(env, exp->args))
   Exp_Lambda *l = &exp->func->d.exp_lambda;
-  Arg_List arg = l->arg;
+  Arg_List arg = l->args;
   Exp e = exp->args;
   while(arg && e) {
     arg->type = e->type;
@@ -559,12 +560,12 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
   }
   if(arg || e)
     ERR_O(exp->self->pos, "argument number does not match for lambda")
-  l->def = new_func_def(NULL, l->name, l->arg, l->code, 0);
+  l->def = new_func_def(new_func_base(NULL, l->name, l->args), l->code, 0);
   CHECK_BO(traverse_func_def(env, l->def))
   if(env->class_def)
     SET_FLAG(l->def, member);
-  exp->self->d.exp_call.m_func = l->def->func;
-  return l->def->ret_type ?: (l->def->ret_type = t_void);
+  exp->self->d.exp_call.m_func = l->def->base->func;
+  return l->def->base->ret_type ?: (l->def->base->ret_type = t_void);
 }
 
 ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {
@@ -581,7 +582,7 @@ ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {
     return check_exp_call_template(env, exp);
   const Func func = find_func_match(env, exp->func->type->d.func, exp->args);
   return (exp->self->d.exp_call.m_func = func) ?
-    func->def->ret_type : function_alternative(exp->func->type, exp->args);
+    func->def->base->ret_type : function_alternative(exp->func->type, exp->args);
 }
 
 ANN static Type check_exp_binary(const Env env, const Exp_Binary* bin) { GWDEBUG_EXE
@@ -619,7 +620,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { GWDEBUG_EXE
       ERR_O(exp->self->pos, "template call of non-template function.")
     const Func ret = find_template_match(env, v, exp);
     CHECK_OO((exp->m_func = ret))
-    return ret->def->ret_type;
+    return ret->def->base->ret_type;
   }
   return check_exp_call1(env, exp);
 }
@@ -831,21 +832,21 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { GWDEBU
   const Type ret_type = stmt->val ? check_exp(env, stmt->val) : t_void;
   CHECK_OB(ret_type)
   if(env->func->value_ref->type == t_lambda) {
-    if(env->func->def->ret_type &&
-     isa(ret_type, env->func->def->ret_type) < 0 &&
-     isa(env->func->def->ret_type, ret_type) < 0)
+    if(env->func->def->base->ret_type &&
+     isa(ret_type, env->func->def->base->ret_type) < 0 &&
+     isa(env->func->def->base->ret_type, ret_type) < 0)
           ERR_B(stmt->self->pos, "return types do not match for lambda expression")
     env->func->value_ref->type = ret_type;
     return GW_OK;
   }
   if(isa(ret_type, t_null) > 0 &&
-     isa(env->func->def->ret_type, t_object) > 0)
+     isa(env->func->def->base->ret_type, t_object) > 0)
     return GW_OK;
-  if(env->func->def->ret_type && isa(ret_type, env->func->def->ret_type) < 0)
+  if(env->func->def->base->ret_type && isa(ret_type, env->func->def->base->ret_type) < 0)
     ERR_B(stmt->self->pos, "invalid return type '%s' -- expecting '%s'",
-          ret_type->name, env->func->def->ret_type->name)
+          ret_type->name, env->func->def->base->ret_type->name)
   else //! set default return type for lambdas
-    env->func->def->ret_type = ret_type;
+    env->func->def->base->ret_type = ret_type;
   return GW_OK;
 }
 
@@ -948,16 +949,16 @@ ANN static m_bool check_stmt_list(const Env env, Stmt_List l) { GWDEBUG_EXE
 
 ANN static m_bool check_signature_match(const Func_Def f, const Func parent) { GWDEBUG_EXE
   if(GET_FLAG(parent->def, static) != GET_FLAG(f, static)) {
-    const m_str c_name  = f->func->value_ref->owner_class->name;
+    const m_str c_name  = f->base->func->value_ref->owner_class->name;
     const m_str p_name = parent->value_ref->owner_class->name;
-    const m_str f_name = s_name(f->name);
-    ERR_B(f->td->xid->pos,
+    const m_str f_name = s_name(f->base->xid);
+    ERR_B(f->base->td->xid->pos,
           "function '%s.%s' ressembles '%s.%s' but cannot override...\n"
           "\t...(reason: '%s.%s' is declared as 'static')",
           c_name, f_name, p_name, c_name,
           GET_FLAG(f, static) ? c_name : p_name, f_name)
   }
-  return !f->tmpl ? isa(f->ret_type, parent->def->ret_type) : GW_OK;
+  return !f->tmpl ? isa(f->base->ret_type, parent->def->base->ret_type) : GW_OK;
 }
 
 ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def f,
@@ -967,8 +968,8 @@ ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def f,
     if(compat_func(f, parent_func->def) > 0) {
       CHECK_BB(check_signature_match(f, parent_func))
       if(!f->tmpl) {
-        f->func->vt_index = parent_func->vt_index;
-        vector_set(&env->curr->info->vtable, f->func->vt_index, (vtype)f->func);
+        f->base->func->vt_index = parent_func->vt_index;
+        vector_set(&env->curr->info->vtable, f->base->func->vt_index, (vtype)f->base->func);
       }
       return GW_OK;
     }
@@ -977,10 +978,10 @@ ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def f,
 }
 
 ANN static m_bool check_parent_match(const Env env, const Func_Def f) { GWDEBUG_EXE
-  const Func func = f->func;
+  const Func func = f->base->func;
   const Type parent = env->class_def->parent;
   if(parent) {
-    const Value v = find_value(parent, f->name);
+    const Value v = find_value(parent, f->base->xid);
     if(v && isa(v->type, t_function) > 0) {
       const m_bool match = parent_match_actual(env, f, v->d.func_ref);
       if(match)
@@ -1008,33 +1009,33 @@ ANN static m_bool check_func_args(const Env env, Arg_List arg_list) { GWDEBUG_EX
 }
 
 ANN static inline Func get_overload(const Env env, const Func_Def def, const m_uint i) {
-  const Symbol sym = func_symbol(env, env->curr->name, s_name(def->name), NULL, i);
+  const Symbol sym = func_symbol(env, env->curr->name, s_name(def->base->xid), NULL, i);
   return nspc_lookup_func1(env->curr, sym);
 }
 
 ANN static m_bool check_func_overload(const Env env, const Func_Def f) {
-  const Value v = f->func->value_ref;
+  const Value v = f->base->func->value_ref;
   for(m_uint i = 0; i <= v->offset; ++i) {
     const Func f1 = get_overload(env, f, i);
     for(m_uint j = i + 1; f1 && j <= v->offset; ++j) {
       const Func f2 = get_overload(env, f, j);
       if(f2 && compat_func(f1->def, f2->def) > 0)
-        ERR_B(f2->def->td->xid->pos, "global function '%s' already defined"
-          " for those arguments", s_name(f->name))
+        ERR_B(f2->def->base->td->xid->pos, "global function '%s' already defined"
+          " for those arguments", s_name(f->base->xid))
     }
   }
   return GW_OK;
 }
 
 ANN static m_bool check_func_def_override(const Env env, const Func_Def f) { GWDEBUG_EXE
-  const Func func = f->func;
+  const Func func = f->base->func;
   if(env->class_def && env->class_def->parent) {
-    const Value override = find_value(env->class_def->parent, f->name);
+    const Value override = find_value(env->class_def->parent, f->base->xid);
     if(override && override->owner_class && isa(override->type, t_function) < 0)
-      ERR_B(f->td->xid->pos,
+      ERR_B(f->base->td->xid->pos,
             "function name '%s' conflicts with previously defined value...\n"
             "\tfrom super class '%s'...",
-            s_name(f->name), override->owner_class->name)
+            s_name(f->base->xid), override->owner_class->name)
   }
   if(func->value_ref->offset && (!f->tmpl || !f->tmpl->base))
     CHECK_BB(check_func_overload(env, f))
@@ -1049,11 +1050,11 @@ ANN static Value set_variadic(const Env env) {
 }
 
 ANN static void operator_func(const Func f) {
-  const Arg_List a = f->def->args;
+  const Arg_List a = f->def->base->args;
   const m_bool is_unary = GET_FLAG(f->def, unary);
   const Type l = is_unary ? NULL : a->type;
   const Type r = is_unary ? a->type : a->next ? a->next->type : NULL;
-  const Operator op = name2op(s_name(f->def->name));
+  const Operator op = name2op(s_name(f->def->base->xid));
   struct Op_Import opi = { .op=op, .lhs=l, .rhs=r, .data=(m_uint)f };
   operator_set_func(&opi);
 }
@@ -1072,15 +1073,15 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
   env->func = func;
   ++env->scope->depth;
   nspc_push_value(env->curr);
-  if(!f->args)
-    UNSET_FLAG(f->func, pure);
+  if(!f->base->args)
+    UNSET_FLAG(f->base->func, pure);
   else
-    ret = check_func_args(env, f->args);
+    ret = check_func_args(env, f->base->args);
   if(ret > 0) {
     const Value variadic = GET_FLAG(f, variadic) ? set_variadic(env) : NULL;
     if(!GET_FLAG(f, builtin) && check_stmt_code(env, &f->d.code->d.stmt_code) < 0)
-      ret = err_msg(f->td ? f->td->xid->pos : 0, "...in function '%s'", 
-         s_name(f->name));
+      ret = err_msg(f->base->td ? f->base->td->xid->pos : 0, "...in function '%s'", 
+         s_name(f->base->xid));
     if(variadic)
       REM_REF(variadic, env->gwion)
     if(GET_FLAG(f, builtin))
@@ -1099,14 +1100,14 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
 DECL_SECTION_FUNC(check)
 
 ANN static m_bool check_class_parent(const Env env, const Class_Def class_def) { GWDEBUG_EXE
-  if(class_def->ext->array) {
-    CHECK_BB(check_exp_array_subscripts(env, class_def->ext->array->exp))
-    if(!GET_FLAG(class_def->type, check) && class_def->tmpl)
-      REM_REF(class_def->type->parent->nspc, env->gwion);
+  if(class_def->base.ext->array) {
+    CHECK_BB(check_exp_array_subscripts(env, class_def->base.ext->array->exp))
+    if(!GET_FLAG(class_def->base.type, check) && class_def->tmpl)
+      REM_REF(class_def->base.type->parent->nspc, env->gwion);
   }
-  if(class_def->ext->types) {
-    const Type t = class_def->type->parent->array_depth ?
-      array_base(class_def->type->parent) : class_def->type->parent;
+  if(class_def->base.ext->types) {
+    const Type t = class_def->base.type->parent->array_depth ?
+      array_base(class_def->base.type->parent) : class_def->base.type->parent;
     if(!GET_FLAG(t, checked)) {
       if(class_def->tmpl)
         CHECK_BB(template_push_types(env, class_def->tmpl->list.list, class_def->tmpl->base))
@@ -1115,15 +1116,15 @@ ANN static m_bool check_class_parent(const Env env, const Class_Def class_def) {
         nspc_pop_type(env->curr);
     }
   }
-  if(!GET_FLAG(class_def->type->parent, checked))
-    CHECK_BB(check_class_def(env, class_def->type->parent->def))
-  if(GET_FLAG(class_def->type->parent, typedef))
-    SET_FLAG(class_def->type, typedef);
+  if(!GET_FLAG(class_def->base.type->parent, checked))
+    CHECK_BB(check_class_def(env, class_def->base.type->parent->def))
+  if(GET_FLAG(class_def->base.type->parent, typedef))
+    SET_FLAG(class_def->base.type, typedef);
   return GW_OK;
 }
 
 ANN static m_bool check_class_body(const Env env, const Class_Def class_def) {
-  const m_uint scope = env_push_type(env, class_def->type);
+  const m_uint scope = env_push_type(env, class_def->base.type);
   Class_Body body = class_def->body;
   do CHECK_BB(check_section(env, body->section))
   while((body = body->next));
@@ -1141,8 +1142,8 @@ ANN static inline void inherit(const Type t) {
 ANN m_bool check_class_def(const Env env, const Class_Def class_def) { GWDEBUG_EXE
   if(tmpl_class_base(class_def->tmpl))
     return GW_OK;
-  const Type the_class = class_def->type;
-  if(class_def->ext)
+  const Type the_class = class_def->base.type;
+  if(class_def->base.ext)
     CHECK_BB(check_class_parent(env, class_def))
   else
     the_class->parent = t_object;
index 27eb6f021ce05b26c4104ab4ffc0e4fa46c27731..7f8e180582b36ea95e3173c16c877ca5b63e4f76 100644 (file)
@@ -32,7 +32,7 @@ ANN Func new_func(const m_str name, const Func_Def def) {
 #include "vm.h"
 #include "gwion.h"
 ANN Func get_func(const Env env, const Func_Def def) {
-  Func f = def->func;
+  Func f = def->base->func;
   CHECK_OO(f)
   m_str end = strrchr(f->name, '@'); // test end cause some template func do not have @x@env->curr->name
   if(end && env->class_def && GET_FLAG(env->class_def, template)) {
index b88e54fad27be61483b4a4084148c2ac001dfca9..7703c7a470b5cb5ea5de17ea45fe16abe6e3ade1 100644 (file)
@@ -29,41 +29,41 @@ ANN static inline m_bool scan0_defined(const Env env, const Symbol s, const uint
 }
 
 ANN m_bool scan0_stmt_fptr(const Env env, const Stmt_Fptr stmt) { GWDEBUG_EXE
-  CHECK_BB(env_access(env, stmt->td->flag))
-  CHECK_BB(scan0_defined(env, stmt->xid, stmt->td->xid->pos));
-  const m_str name = s_name(stmt->xid);
+  CHECK_BB(env_access(env, stmt->base->td->flag))
+  CHECK_BB(scan0_defined(env, stmt->base->xid, stmt->base->td->xid->pos));
+  const m_str name = s_name(stmt->base->xid);
   const Type t = new_type(t_fptr->xid, name, t_fptr);
-  t->owner = !(!env->class_def && GET_FLAG(stmt->td, global)) ?
+  t->owner = !(!env->class_def && GET_FLAG(stmt->base->td, global)) ?
     env->curr : env->global_nspc;
   t->nspc = new_nspc(name);
-  t->flag = stmt->td->flag;
+  t->flag = stmt->base->td->flag;
   stmt->type = t;
-  nspc_add_type(t->owner, stmt->xid, t);
+  nspc_add_type(t->owner, stmt->base->xid, t);
   stmt->value = mk_class(env, t);
   return GW_OK;
 }
 
 ANN static m_bool scan0_stmt_type(const Env env, const Stmt_Type stmt) { GWDEBUG_EXE
-  CHECK_BB(env_access(env, stmt->td->flag))
-  const Type base = known_type(env, stmt->td);
+  CHECK_BB(env_access(env, stmt->ext->flag))
+  const Type base = known_type(env, stmt->ext);
   CHECK_OB(base)
-  CHECK_BB(scan0_defined(env, stmt->xid, stmt->td->xid->pos))
-  if(!stmt->td->types && (!stmt->td->array || !stmt->td->array->exp)) {
+  CHECK_BB(scan0_defined(env, stmt->xid, stmt->ext->xid->pos))
+  if(!stmt->ext->types && (!stmt->ext->array || !stmt->ext->array->exp)) {
     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)) ?
+    const Nspc nspc = (!env->class_def && GET_FLAG(stmt->ext, global)) ?
       env->global_nspc : env->curr;
     nspc_add_type(nspc, stmt->xid, t);
     t->owner = nspc;
     stmt->type = t;
-    t->flag = stmt->td->flag | ae_flag_checked;
-    if(stmt->td->array && !stmt->td->array->exp)
+    t->flag = stmt->ext->flag | ae_flag_checked;
+    if(stmt->ext->array && !stmt->ext->array->exp)
       SET_FLAG(t, empty);
   } else {
     const ae_flag flag = base->def ? base->def->flag : 0;
-    const Class_Def def = new_class_def(flag, stmt->xid, stmt->td, NULL);
+    const Class_Def def = new_class_def(flag, stmt->xid, stmt->ext, NULL, stmt->ext->xid->pos);
     CHECK_BB(scan0_class_def(env, def))
-    stmt->type = def->type;
+    stmt->type = def->base.type;
   }
   SET_FLAG(stmt->type, typedef);
   return GW_OK;
@@ -157,26 +157,25 @@ ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def class_def)
     vector_add(&env->scope->nspc_stack, (vtype)env->curr);
     env->curr = env->global_nspc;
   }
-//  CHECK_BB(scan0_defined(env, class_def->xid, class_def->name->pos)) // test for type ?
-  CHECK_BB(scan0_defined(env, class_def->xid, 0)) // test for type ?
-  CHECK_BB(isres(class_def->xid))
+  CHECK_BB(scan0_defined(env, class_def->base.xid, class_def->pos)) // test for type ?
+  CHECK_BB(isres(class_def->base.xid))
   return GW_OK;
 }
 
 ANN static Type scan0_class_def_init(const Env env, const Class_Def class_def) { GWDEBUG_EXE
-  const Type t = new_type(++env->scope->type_xid, s_name(class_def->xid), t_object);
+  const Type t = new_type(++env->scope->type_xid, s_name(class_def->base.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;
   t->def = class_def;
   t->flag = class_def->flag;
   if(!strstr(t->name, "<"))
-    nspc_add_type(env->curr, class_def->xid, t);
+    nspc_add_type(env->curr, class_def->base.xid, t);
   if(class_def->tmpl) {
     SET_FLAG(t, template);
     SET_FLAG(class_def, template);
   }
-  if(class_def->ext && class_def->ext->array)
+  if(class_def->base.ext && class_def->base.ext->array)
     SET_FLAG(t, typedef);
   return t;
 }
@@ -191,15 +190,15 @@ ANN static m_bool scan0_section(const Env env, const Section* section) { GWDEBUG
 
 ANN m_bool scan0_class_def(const Env env, const Class_Def class_def) { GWDEBUG_EXE
   CHECK_BB(scan0_class_def_pre(env, class_def))
-  CHECK_OB((class_def->type = scan0_class_def_init(env, class_def)))
+  CHECK_OB((class_def->base.type = scan0_class_def_init(env, class_def)))
   if(class_def->body) {
     Class_Body body = class_def->body;
-    const m_uint scope = env_push_type(env, class_def->type);
+    const m_uint scope = env_push_type(env, class_def->base.type);
     do CHECK_BB(scan0_section(env, body->section))
     while((body = body->next));
     env_pop(env, scope);
   }
-  (void)mk_class(env, class_def->type);
+  (void)mk_class(env, class_def->base.type);
   if(GET_FLAG(class_def, global))
     env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
   return GW_OK;
index 4e3b1b2f4857c265b464fa7767dc0c5f98e7193b..485ebc44fe337e8fc25425265073a5e783624275 100644 (file)
@@ -206,8 +206,8 @@ ANN static m_bool scan1_args(const Env env, Arg_List list) { GWDEBUG_EXE
 }
 
 ANN m_bool scan1_stmt_fptr(const Env env, const Stmt_Fptr ptr) { GWDEBUG_EXE
-  CHECK_OB((ptr->ret_type = known_type(env, ptr->td)))
-  return ptr->args ? scan1_args(env, ptr->args) : GW_OK;
+  CHECK_OB((ptr->base->ret_type = known_type(env, ptr->base->td)))
+  return ptr->base->args ? scan1_args(env, ptr->base->args) : GW_OK;
 }
 
 ANN static inline m_bool scan1_stmt_type(const Env env, const Stmt_Type stmt) { GWDEBUG_EXE
@@ -276,11 +276,11 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
   env->func = FAKE_FUNC;
   ++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)
-    CHECK_OB((f->ret_type = known_type(env, f->td)))
-  if(f->args)
-    CHECK_BB(scan1_args(env, f->args))
+    ERR_B(f->base->td->xid->pos, "dtor must be in class def!!")
+  if(f->base->td)
+    CHECK_OB((f->base->ret_type = known_type(env, f->base->td)))
+  if(f->base->args)
+    CHECK_BB(scan1_args(env, f->base->args))
   if(!GET_FLAG(f, builtin))
     CHECK_BB(scan1_stmt_code(env, &f->d.code->d.stmt_code))
   if(GET_FLAG(f, op) && env->class_def)
@@ -293,25 +293,25 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
 DECL_SECTION_FUNC(scan1)
 
 ANN static m_bool scan1_class_parent(const Env env, const Class_Def class_def) {
-  if(class_def->ext->array)
-    CHECK_BB(scan1_exp(env, class_def->ext->array->exp))
-  const Type parent = class_def->type->parent = known_type(env, class_def->ext);
+  if(class_def->base.ext->array)
+    CHECK_BB(scan1_exp(env, class_def->base.ext->array->exp))
+  const Type parent = class_def->base.type->parent = known_type(env, class_def->base.ext);
   CHECK_OB(parent)
-  if(parent == class_def->type)
-    ERR_B(class_def->ext->xid->pos, "class '%s' cannot extend itself",
-      class_def->type->name);
-  if(isa(class_def->type->parent, t_object) < 0)
-    ERR_B(class_def->ext->xid->pos, "cannot extend primitive type '%s'",
-            class_def->type->parent->name)
+  if(parent == class_def->base.type)
+    ERR_B(class_def->base.ext->xid->pos, "class '%s' cannot extend itself",
+      class_def->base.type->name);
+  if(isa(class_def->base.type->parent, t_object) < 0)
+    ERR_B(class_def->base.ext->xid->pos, "cannot extend primitive type '%s'",
+            class_def->base.type->parent->name)
   if(!GET_FLAG(parent, scan1) && parent->def)
     CHECK_BB(scan1_class_def(env, parent->def))
   if(type_ref(parent))
-    ERR_B(class_def->ext->xid->pos, "can't use ref type in class extend")
+    ERR_B(class_def->base.ext->xid->pos, "can't use ref type in class extend")
   return GW_OK;
 }
 
 ANN static m_bool scan1_class_body(const Env env, const Class_Def class_def) {
-  const m_uint scope = env_push_type(env, class_def->type);
+  const m_uint scope = env_push_type(env, class_def->base.type);
   Class_Body body = class_def->body;
   do CHECK_BB(scan1_section(env, body->section))
   while((body = body->next));
@@ -322,11 +322,11 @@ ANN static m_bool scan1_class_body(const Env env, const Class_Def class_def) {
 ANN m_bool scan1_class_def(const Env env, const Class_Def class_def) { GWDEBUG_EXE
   if(tmpl_class_base(class_def->tmpl))
     return GW_OK;
-  if(class_def->ext)
+  if(class_def->base.ext)
     CHECK_BB(scan1_class_parent(env, class_def))
   if(class_def->body)
     CHECK_BB(scan1_class_body(env, class_def))
-  SET_FLAG(class_def->type, scan1);
+  SET_FLAG(class_def->base.type, scan1);
   return GW_OK;
 }
 
index 2f36853956c74c3573e3dfed24d5a04a1280ea06..7081b1b70ad3b8684772e8b19dd90ec921e8f3fd 100644 (file)
@@ -61,7 +61,7 @@ ANN static Value arg_value(const Arg_List list) {
 }
 
 ANN static m_bool scan2_args(const Env env, const Func_Def f) { GWDEBUG_EXE
-  Arg_List list = f->args;
+  Arg_List list = f->base->args;
   do {
     const Var_Decl var = list->var_decl;
     if(var->array)
@@ -85,39 +85,36 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d,
     else SET_FLAG(v, static);
     SET_ACCESS(d, v)
   }
-  d->func = v->d.func_ref = f;
+  d->base->func = v->d.func_ref = f;
   return f->value_ref = v;
 }
 
 ANN m_bool scan2_stmt_fptr(const Env env, const Stmt_Fptr ptr) { GWDEBUG_EXE
-  struct Func_Def_ d = { .stack_depth=0 };
-  d.args = ptr->args;
-  if(d.args)
-    CHECK_BB(scan2_args(env, &d))
-  const Func_Def def = new_func_def(ptr->td, ptr->xid, ptr->args, NULL, ptr->td->flag);
-  def->ret_type = ptr->ret_type;
-  def->stack_depth = d.stack_depth;
-  ptr->func = new_func(s_name(ptr->xid), def);
-  ptr->value->d.func_ref = ptr->func;
-  ptr->func->value_ref = ptr->value;
-  ptr->type->d.func = ptr->func;
+  const Func_Def def = new_func_def(new_func_base(ptr->base->td, ptr->base->xid, ptr->base->args), NULL, ptr->base->td->flag);
+  def->base->ret_type = ptr->base->ret_type;
+  ptr->base->func = new_func(s_name(ptr->base->xid), def);
+  ptr->value->d.func_ref = ptr->base->func;
+  ptr->base->func->value_ref = ptr->value;
+  ptr->type->d.func = ptr->base->func;
   SET_FLAG(ptr->value, func | ae_flag_checked);
+  if(ptr->base->args)
+    CHECK_BB(scan2_args(env, def))
   if(env->class_def) {
-    if(GET_FLAG(ptr->td, global)) {
+    if(GET_FLAG(ptr->base->td, global)) {
       SET_FLAG(ptr->value, global);
-      SET_FLAG(ptr->func, global);
-    } else if(!GET_FLAG(ptr->td, static)) {
+      SET_FLAG(ptr->base->func, global);
+    } else if(!GET_FLAG(ptr->base->td, static)) {
       SET_FLAG(ptr->value, member);
-      SET_FLAG(ptr->func, member);
+      SET_FLAG(ptr->base->func, member);
       def->stack_depth += SZ_INT;
     } else {
       SET_FLAG(ptr->value, static);
-      SET_FLAG(ptr->func, static);
+      SET_FLAG(ptr->base->func, static);
     }
     ptr->value->owner_class = env->class_def;
   }
-  nspc_add_value(env->curr, ptr->xid, ptr->value);
-  nspc_add_func(ptr->type->owner, ptr->xid, ptr->func);
+  nspc_add_value(env->curr, ptr->base->xid, ptr->value);
+  nspc_add_func(ptr->type->owner, ptr->base->xid, ptr->base->func);
   return GW_OK;
 }
 
@@ -305,9 +302,9 @@ ANN static m_bool scan2_func_def_overload(const Func_Def f, const Value overload
   const m_bool base = tmpl_list_base(f->tmpl);
   const m_bool tmpl = GET_FLAG(overload, template);
   if(isa(overload->type, t_function) < 0)
-    ERR_B(f->td->xid->pos, "function name '%s' is already used by another value", overload->name)
+    ERR_B(f->base->td->xid->pos, "function name '%s' is already used by another value", overload->name)
   if((!tmpl && base) || (tmpl && !base && !GET_FLAG(f, template)))
-    ERR_B(f->td->xid->pos, "must overload template function with template")
+    ERR_B(f->base->td->xid->pos, "must overload template function with template")
   return GW_OK;
 }
 
@@ -339,7 +336,7 @@ ANN2(1,2) static Value func_value(const Env env, const Func f,
   CHECK_OO(scan2_func_assign(env, f->def, f, v))
   if(!overload) {
     ADD_REF(v);
-    nspc_add_value(env->curr, f->def->name, v);
+    nspc_add_value(env->curr, f->def->base->xid, v);
   } else /* if(!GET_FLAG(f->def, template)) */ {
     f->next = overload->d.func_ref->next;
     overload->d.func_ref->next = f;
@@ -348,7 +345,7 @@ ANN2(1,2) static Value func_value(const Env env, const Func f,
 }
 
 ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f, const Value overload) { GWDEBUG_EXE
-  const m_str func_name = s_name(f->name);
+  const m_str func_name = s_name(f->base->xid);
   const Func func = scan_new_func(env, f, func_name);
   const Value value = func_value(env, func, overload);
   SET_FLAG(value, checked | ae_flag_template);
@@ -357,7 +354,7 @@ ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f
   Nspc nspc = env->curr;
   uint i = 0;
   do {
-    const Value v = nspc_lookup_value1(nspc, f->name);
+    const Value v = nspc_lookup_value1(nspc, f->base->xid);
     if(v) {
       Func ff = v->d.func_ref;
       do {
@@ -372,7 +369,7 @@ ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f
           nspc_add_value(env->curr, sym, value);
           if(!overload) {
             ADD_REF(value)
-            nspc_add_value(env->curr, f->name, value);
+            nspc_add_value(env->curr, f->base->xid, value);
           }
           func->vt_index = ff->vt_index;
           return GW_OK;
@@ -386,7 +383,7 @@ ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f
   if(!overload) {
     func->vt_index = i;
     ADD_REF(value)
-    nspc_add_value(env->curr, f->name, value);
+    nspc_add_value(env->curr, f->base->xid, value);
   } else
     func->vt_index = ++overload->offset;
   return GW_OK;
@@ -400,28 +397,28 @@ ANN static m_bool scan2_func_def_builtin(const Func func, const m_str name) { GW
 }
 
 ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f) { GWDEBUG_EXE
-  assert(f->args);
-  const Operator op = name2op(s_name(f->name));
+  assert(f->base->args);
+  const Operator op = name2op(s_name(f->base->xid));
   const Type l = GET_FLAG(f, unary) ? NULL :
-    f->args->var_decl->value->type;
-  const Type r = GET_FLAG(f, unary) ? f->args->var_decl->value->type :
-    f->args->next ? f->args->next->var_decl->value->type : NULL;
-  struct Op_Import opi = { .op=op, .lhs=l, .rhs=r, .ret=f->ret_type };
+    f->base->args->var_decl->value->type;
+  const Type r = GET_FLAG(f, unary) ? f->base->args->var_decl->value->type :
+    f->base->args->next ? f->base->args->next->var_decl->value->type : NULL;
+  struct Op_Import opi = { .op=op, .lhs=l, .rhs=r, .ret=f->base->ret_type };
   CHECK_BB(env_add_op(env, &opi))
   if(env->class_def) {
     if(env->class_def == l)
       REM_REF(l, env->gwion)
     if(env->class_def == r)
       REM_REF(r, env->gwion)
-    if(env->class_def == f->ret_type)
-      REM_REF(f->ret_type, env->gwion)
+    if(env->class_def == f->base->ret_type)
+      REM_REF(f->base->ret_type, env->gwion)
   }
   return GW_OK;
 }
 
 ANN static m_bool scan2_func_def_code(const Env env, const Func_Def f) { GWDEBUG_EXE
   const Func former = env->func;
-  env->func = f->func;
+  env->func = f->base->func;
   CHECK_BB(scan2_stmt_code(env, &f->d.code->d.stmt_code))
   env->func = former;
   return GW_OK;
@@ -429,15 +426,15 @@ ANN static m_bool scan2_func_def_code(const Env env, const Func_Def f) { GWDEBUG
 
 ANN static void scan2_func_def_flag(const Env env, const Func_Def f) { GWDEBUG_EXE
   if(!GET_FLAG(f, builtin))
-    SET_FLAG(f->func, pure);
+    SET_FLAG(f->base->func, pure);
   if(GET_FLAG(f, dtor)) {
     SET_FLAG(env->class_def, dtor);
-    SET_FLAG(f->func, dtor);
+    SET_FLAG(f->base->func, dtor);
   }
 }
 
 ANN static m_str func_tmpl_name(const Env env, const Func_Def f) {
-  const m_str func_name = s_name(f->name);
+  const m_str func_name = s_name(f->base->xid);
   struct Vector_ v;
   ID_List id = f->tmpl->list;
   m_uint tlen = 0;
@@ -485,8 +482,8 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
   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);
-  m_str func_name = s_name(f->name);
+  const Value overload = nspc_lookup_value0(env->curr, f->base->xid);
+  m_str func_name = s_name(f->base->xid);
   if(overload)
     CHECK_BB(scan2_func_def_overload(f, overload))
   if(tmpl_list_base(f->tmpl))
@@ -495,8 +492,8 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
     const Symbol sym  = func_symbol(env, env->curr->name, func_name, NULL, overload ? ++overload->offset : 0);
     func_name = s_name(sym);
   } else {
-    if(f->func)
-      func_name = f->func->name;
+    if(f->base->func)
+      func_name = f->base->func->name;
     else
       func_name = func_tmpl_name(env, f);
     const Func func = nspc_lookup_func1(env->curr, insert_symbol(func_name));
@@ -505,17 +502,17 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
         f->stack_depth += SZ_INT;
       if(GET_FLAG(func->def, variadic))
         f->stack_depth += SZ_INT;
-      f->ret_type = type_decl_resolve(env, f->td);
-      return (f->args && f->args->type) ? scan2_args(env, f) : GW_OK;
+      f->base->ret_type = type_decl_resolve(env, f->base->td);
+      return (f->base->args && f->base->args->type) ? scan2_args(env, f) : GW_OK;
     }
   }
   const Func base = get_func(env, f);
   if(!base) {
     CHECK_OB((value = func_create(env, f, overload, func_name)))
   } else {
-    f->func = base;
+    f->base->func = base;
 }
-  if(f->args)
+  if(f->base->args)
     CHECK_BB(scan2_args(env, f))
   if(!GET_FLAG(f, builtin) && f->d.code->d.stmt_code.stmt_list)
     CHECK_BB(scan2_func_def_code(env, f))
@@ -532,17 +529,17 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE
 DECL_SECTION_FUNC(scan2)
 
 ANN static m_bool scan2_class_parent(const Env env, const Class_Def class_def) {
-  const Type t = class_def->type->parent->array_depth ?
-    array_base(class_def->type->parent) : class_def->type->parent;
-  if(!GET_FLAG(t, scan2) && GET_FLAG(class_def->ext, typedef))
+  const Type t = class_def->base.type->parent->array_depth ?
+    array_base(class_def->base.type->parent) : class_def->base.type->parent;
+  if(!GET_FLAG(t, scan2) && GET_FLAG(class_def->base.ext, typedef))
     CHECK_BB(scan2_class_def(env, t->def))
-  if(class_def->ext->array)
-    CHECK_BB(scan2_exp(env, class_def->ext->array->exp))
+  if(class_def->base.ext->array)
+    CHECK_BB(scan2_exp(env, class_def->base.ext->array->exp))
   return GW_OK;
 }
 
 ANN static m_bool scan2_class_body(const Env env, const Class_Def class_def) {
-  const m_uint scope = env_push_type(env, class_def->type);
+  const m_uint scope = env_push_type(env, class_def->base.type);
   Class_Body body = class_def->body;
   do CHECK_BB(scan2_section(env, body->section))
   while((body = body->next));
@@ -553,11 +550,11 @@ ANN static m_bool scan2_class_body(const Env env, const Class_Def class_def) {
 ANN m_bool scan2_class_def(const Env env, const Class_Def class_def) { GWDEBUG_EXE
   if(tmpl_class_base(class_def->tmpl))
     return GW_OK;
-  if(class_def->ext)
+  if(class_def->base.ext)
     CHECK_BB(scan2_class_parent(env, class_def))
   if(class_def->body)
     CHECK_BB(scan2_class_body(env, class_def))
-  SET_FLAG(class_def->type, scan2);
+  SET_FLAG(class_def->base.type, scan2);
   return GW_OK;
 }
 
index 5dbb7d64c1ef36d45ecffaf09cd5060035818a5a..ed1f7c03fd9d8ac3756d1c1f002cb298572609bb 100644 (file)
@@ -67,7 +67,7 @@ ANN static inline size_t tmpl_set(struct tmpl_info* info, const Type t) {
 
 ANN static size_t template_size(const Env env, struct tmpl_info* info) {
   ID_List base = info->cdef->tmpl->list.list;
-  size_t size = tmpl_set(info, info->cdef->type);
+  size_t size = tmpl_set(info, info->cdef->base.type);
   do size += tmpl_set(info, type_decl_resolve(env, info->call->td));
   while((info->call = info->call->next) && (base = base->next) && ++size);
   return size + 16 + 3;
@@ -88,7 +88,7 @@ ANN static void template_name(const Env env, struct tmpl_info* info, m_str s) {
     str = tmpl_get(info, str);
     *str++ = (info->index < size - 1) ? ',' : '>';
    }
-  if(info->cdef->type->owner == env->global_nspc)
+  if(info->cdef->base.type->owner == env->global_nspc)
     sprintf(str, "%p", (void*)env->curr);
   else
     *str = '\0';
@@ -113,7 +113,7 @@ ANN m_bool template_match(ID_List base, Type_List call) {
 ANN static Class_Def template_class(const Env env, const Class_Def def, const Type_List call) {
   const Symbol name = template_id(env, def, call);
   const Type t = nspc_lookup_type1(env->curr, name);
-  return t ? t->def : new_class_def(def->flag, name, def->ext, def->body);
+  return t ? t->def : new_class_def(def->flag, name, def->base.ext, def->body, def->pos);
 }
 
 ANN m_bool template_push_types(const Env env, ID_List base, Type_List tl) {
@@ -148,24 +148,24 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) {
     CHECK_BO(template_push_types(env, t->def->tmpl->list.list, type->types))
     const Class_Def a = template_class(env, t->def, type->types);
     SET_FLAG(a, ref);
-    if(a->type)
-      POP_RET(a->type);
+    if(a->base.type)
+      POP_RET(a->base.type);
     CHECK_BO(scan0_class_def(env, a))
-    SET_FLAG(a->type, template | ae_flag_ref);
-    a->type->owner = t->owner;
+    SET_FLAG(a->base.type, template | ae_flag_ref);
+    a->base.type->owner = t->owner;
     if(GET_FLAG(t, builtin))
-      SET_FLAG(a->type, builtin);
+      SET_FLAG(a->base.type, builtin);
     CHECK_BO(scan1_class_def(env, a))
     nspc_pop_type(env->curr);
     if(t->nspc->dtor) {
-      a->type->nspc->dtor = t->nspc->dtor;
-      SET_FLAG(a->type, dtor);
+      a->base.type->nspc->dtor = t->nspc->dtor;
+      SET_FLAG(a->base.type, dtor);
       ADD_REF(t->nspc->dtor)
     }
     a->tmpl = new_tmpl_class(get_total_type_list(env, t), 0);
     a->tmpl->base = type->types;
-    nspc_add_type(t->owner, insert_symbol(a->type->name), a->type);
-    return a->type;
+    nspc_add_type(t->owner, insert_symbol(a->base.type->name), a->base.type);
+    return a->base.type;
   } else if(type->types)
       ERR_O(type->xid->pos,
             "type '%s' is not template. You should not provide template types", t->name)
index 63c87c0603e3326e116ee3abf06161e2d6629b87..f1f8b1d8a3b17dd43d338d49ee7c17b8d36902eb 100644 (file)
@@ -8,3 +8,8 @@ class D extends C
 {
        function void test() {}
 }
+
+C c;
+D d;
+<<<c>>>;
+<<<d>>>;
\ No newline at end of file
index e6d5a55b4f098499fcaa38519ea2116ec1b3bb85..23869cfa1c55ee89530084827ebbf40cf1d33ce6 100644 (file)
@@ -2,3 +2,5 @@
 class C extends C {
 
 }
+C c;
+<<<c>>>;
\ No newline at end of file
index e349ba728f3e214c442c5e28b8b885f2a2b81ebb..34a62f8a18dc374afe913ab84a43d47d248ae17d 100644 (file)
@@ -1,2 +1,4 @@
 // [contains] unknown type
 class C extends Undefined {}
+C c;
+<<<c>>>;
\ No newline at end of file
index 9faa39c15b141bbb92ba9e5eb22e145d82d03594..5df0a49b26ceda3e90f67da35bedf8eba3396917 100644 (file)
@@ -47,7 +47,7 @@ static SFUN(cb_func) {
   struct ret_info* info = (struct ret_info*)xmalloc(sizeof(struct ret_info));
   info->offset = offset;
   info->code = shred->code;
-  info->size = f->def->ret_type->size;
+  info->size = f->def->base->ret_type->size;
   info->pc = shred->pc;
   instr->execute = my_ret;
 //  *(VM_Code*)instr->ptr = shred->code;