-Subproject commit 25337f99739d1844469e6fc2f3c07feda0d99b40
+Subproject commit 31cd8af5a79fe16e5b67fb8a456848eb99e24b05
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) {
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;
}
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;
}
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
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;
}
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;
}
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)
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;
}
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))
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))
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);
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;
}
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;
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);
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);
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")
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;
}
}
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;
}
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);
!(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;
#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;
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;
}
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;
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))
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;
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);
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));
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)];
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) {
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;
}
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) {
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
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);
}
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;
}
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,
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;
}
}
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)
}
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))
}
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);
}
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))
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))
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));
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;
#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)) {
}
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;
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;
}
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;
}
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
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)
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));
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;
}
}
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)
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;
}
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;
}
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;
}
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);
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 {
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;
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;
}
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;
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;
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))
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));
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))
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));
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;
}
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;
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';
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) {
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)
{
function void test() {}
}
+
+C c;
+D d;
+<<<c>>>;
+<<<d>>>;
\ No newline at end of file
class C extends C {
}
+C c;
+<<<c>>>;
\ No newline at end of file
// [contains] unknown type
class C extends Undefined {}
+C c;
+<<<c>>>;
\ No newline at end of file
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;