}
ANN static m_int frame_pop(Frame* frame) {
- const Local* l = (Local*)vector_pop(&frame->stack);
- CHECK_OB(l)
+ DECL_OB(const Local*, l, = (Local*)vector_pop(&frame->stack))
frame->curr_offset -= l->size;
return l->is_obj ? (m_int)l->offset : frame_pop(frame);
}
array = new_array_sub(emit->gwion->mp, base);
}
assert(array->exp);
- ArrayInfo* info = emit_array_extend_inner(emit, type, array->exp);
- CHECK_OB(info)
+ DECL_OB(ArrayInfo*, info, = emit_array_extend_inner(emit, type, array->exp))
info->is_ref = !!is_ref;
if(array != arr)
free_array_sub(emit->gwion->mp, array);
}
ANN static m_bool prim_char(const Emitter emit, const Exp_Primary* prim) {
- const m_int c = str2char(emit, prim->d.chr, exp_self(prim)->pos);
- CHECK_BB(c);
+ DECL_BB(const m_int, c, = str2char(emit, prim->d.chr, exp_self(prim)->pos))
regpushi(emit, c);
return GW_OK;
}
if(emit->env->func && emit->env->func == exp_call->m_func)
return prepare_call(emit, exp_call);
exp_call->m_func->def->base->tmpl->call = exp_call->tmpl->call;
- const m_int scope = push_tmpl_func(emit, exp_call->m_func);
- CHECK_BB(scope);
+ DECL_BB(const m_int,scope, = push_tmpl_func(emit, exp_call->m_func))
CHECK_BB(prepare_call(emit, exp_call))
emit_pop_type(emit);
emit_pop(emit, (m_uint)scope);
ANN static m_bool emit_stmt_if(const Emitter emit, const Stmt_If stmt) {
emit_push_scope(emit);
CHECK_BB(emit_exp(emit, stmt->cond, 0))
- const Instr op = emit_flow(emit, isa(stmt->cond->type, t_object) > 0 ?
- t_int : stmt->cond->type, BranchEqInt, BranchEqFloat);
- CHECK_OB(op)
+ DECL_OB(const Instr, op, = emit_flow(emit, isa(stmt->cond->type, t_object) > 0 ?
+ t_int : stmt->cond->type, BranchEqInt, BranchEqFloat))
CHECK_BB(scoped_stmt(emit, stmt->if_body, 1))
const Instr op2 = emit_add_instr(emit, Goto);
op->m_val = emit_code_size(emit);
static m_bool td_match(const Env env, const Type_Decl *id[2]) {
- const Type t0 = known_type(env, id[0]);
- CHECK_OB(t0)
- const Type t1 = known_type(env, id[1]);
- CHECK_OB(t1)
+ DECL_OB(const Type, t0, = known_type(env, id[0]))
+ DECL_OB(const Type, t1, = known_type(env, id[1]))
return isa(t0, t1);
}
if(td->array && !td->array->exp)
GWI_ERR_B("class extend array can't be empty")
if(!gwi->gwion->env->class_def->e->def) {
- const Type t = known_type(gwi->gwion->env, td);
- CHECK_OB(t)
+ DECL_OB(const Type, t, = known_type(gwi->gwion->env, td))
if(td->array)
SET_FLAG(gwi->gwion->env->class_def, typedef);
gwi->gwion->env->class_def->e->parent = t;
ANN Type_Decl* str2decl(const Env env, const m_str s, m_uint *depth) {
m_uint i = 0;
- m_str type_name = get_type_name(env, s, i++);
- CHECK_OO(type_name)
- ID_List id = str2list(env, type_name, depth);
- CHECK_OO(id)
+ DECL_OO(m_str, type_name, = get_type_name(env, s, i++))
+ DECL_OO(ID_List, id, = str2list(env, type_name, depth))
Type_Decl* td = new_type_decl(env->gwion->mp, id, 0);
Type_List tmp = NULL;
if(!td) {
ANN Type_Decl* import_td(const Gwi gwi, const m_str name) {
const Env env = gwi->gwion->env;
m_uint array_depth;
- const ID_List type_path = str2list(env, name, &array_depth);
- CHECK_OO(type_path)
+ DECL_OO(const ID_List, type_path, = str2list(env, name, &array_depth))
Type_Decl* type_decl = new_type_decl(env->gwion->mp, type_path, 0);
if(!type_decl) {
free_id_list(env->gwion->mp, type_path);
ANN m_int gwi_func_end(const Gwi gwi, const ae_flag flag) {
CHECK_BB(name_valid(gwi, gwi->func.name));
- Func_Def def = make_dll_as_fun(gwi, &gwi->func, flag);
- CHECK_OB(def)
+ DECL_OB(Func_Def, def, = make_dll_as_fun(gwi, &gwi->func, flag))
if(gwi->templater.n) {
def = new_func_def(gwi->gwion->mp, new_func_base(gwi->gwion->mp, NULL, NULL, NULL), NULL, 0, loc_cpy(gwi->gwion->mp, gwi->loc));
const ID_List list = templater_def(gwi->gwion->st, gwi);
}
ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
- const Exp exp = make_exp(gwi, type, name);
- CHECK_OB(exp);
- const Type t = type_decl_resolve(gwi->gwion->env, exp->d.exp_decl.td);
- if(!t)
- GWI_ERR_B("type '%s' unknown in union declaration.", type)
+ DECL_OB(const Exp, exp, = make_exp(gwi, type, name))
+ DECL_OB(const Type, t, = known_type(gwi->gwion->env, exp->d.exp_decl.td))
if(isa(t, t_object) > 0)
SET_FLAG(exp->d.exp_decl.td, ref);
gwi->union_data.list = new_decl_list(gwi->gwion->mp, exp, gwi->union_data.list);
const Func_Def fdef = dt->def ?: dt->base;
const Symbol sym = func_symbol(env, nspc->name, s_name(fdef->base->xid),
"template", dt->vt_index);
- const Value v = nspc_lookup_value1(nspc, sym);
- CHECK_OO(v)
+ DECL_OO(const Value, v, = nspc_lookup_value1(nspc, sym))
const Func_Def base = v->d.func_ref->def;
const Func_Def def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, fdef->base->td, insert_symbol(env->gwion->st, v->name),
fdef->base->args), fdef->d.code, fdef->flag, loc_cpy(env->gwion->mp, base->pos));
OP_CHECK(opck_new) {
const Exp_Unary* unary = (Exp_Unary*)data;
SET_FLAG(unary->td, ref);
- const Type t = known_type(env, unary->td);
+ DECL_OO(const Type, t, = known_type(env, unary->td))
UNSET_FLAG(unary->td, ref);
- CHECK_OO(t)
if(unary->td->array)
CHECK_BO(check_exp_array_subscripts(env, unary->td->array->exp))
return t;
Var_Decl_List list = decl->list;
CHECK_BO(switch_decl(env, exp_self(decl)->pos))
if(!decl->td->xid) {
- const Type t = check_td(env, decl->td);
- CHECK_OO(t)
+ DECL_OO(const Type, t, = check_td(env, decl->td))
((Exp_Decl*)decl)->type = NULL;
CHECK_BO(scan1_exp(env, exp_self(decl)))
CHECK_BO(scan2_exp(env, exp_self(decl)))
}
ANN Type check_exp_array(const Env env, const Exp_Array* array) {
- Type t_base = check_exp(env, array->base);
- CHECK_OO(t_base)
+ DECL_OO(Type, t_base, = check_exp(env, array->base))
Exp e = array->array->exp;
CHECK_OO(check_exp(env, e))
m_uint depth = 0;
const Exp call = exp->func;
const Exp args = exp->args;
m_uint args_number = 0;
- const Value value = nspc_lookup_value1(call->type->e->owner, insert_symbol(call->type->name));
- CHECK_OO(value)
+ DECL_OO(const Value, value, = nspc_lookup_value1(call->type->e->owner, insert_symbol(call->type->name)))
const m_uint type_number = get_type_number(value->d.func_ref->def->base->tmpl->list);
Type_List tl[type_number];
ID_List list = value->d.func_ref->def->base->tmpl->list;
}
ANN static Type check_exp_cast(const Env env, const Exp_Cast* cast) {
- const Type t = check_exp(env, cast->exp);
- CHECK_OO(t)
+ DECL_OO(const Type, t, = check_exp(env, cast->exp))
CHECK_OO((exp_self(cast)->type = cast->td->xid ? known_type(env, cast->td) : check_td(env, cast->td)))
struct Op_Import opi = { .op=op_cast, .lhs=t, .rhs=exp_self(cast)->type, .data=(uintptr_t)cast, .pos=exp_self(cast)->pos };
return op_check(env, &opi);
}
ANN static Type check_exp_if(const Env env, const Exp_If* exp_if) {
- const Type cond = check_exp(env, exp_if->cond);
- CHECK_OO(cond)
- const Type if_exp = check_exp(env, exp_if->if_exp);
- CHECK_OO(if_exp)
- const Type else_exp = check_exp(env, exp_if->else_exp);
- CHECK_OO(else_exp)
+ DECL_OO(const Type, cond, = check_exp(env, exp_if->cond))
+ DECL_OO(const Type, if_exp, = check_exp(env, exp_if->if_exp))
+ DECL_OO(const Type, else_exp, = check_exp(env, exp_if->else_exp))
if(isa(cond, t_int) < 0 && isa(cond, t_float) < 0 && isa(cond, t_object) < 0)
ERR_O(exp_self(exp_if)->pos,
"Invalid type '%s' in if expression condition.", cond->name)
const Exp_If* exp_if NUSED) { return t_lambda; }
ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) {
- const Type t = check_exp(env, exp->exp);
- CHECK_OO(t)
- const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name));
- CHECK_OO(v)
+ DECL_OO(const Type, t, = check_exp(env, exp->exp))
+ DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)))
return v->type;
}
}
ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) {
- Type t = check_exp(env, stmt->exp);
- CHECK_OB(t)
+ DECL_OB(Type, t, = check_exp(env, stmt->exp))
Type ptr = array_base(t);
const m_uint depth = t->array_depth - 1;
if(GET_FLAG(t, typedef))
ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) {
if(!env->func)
ERR_B(stmt_self(stmt)->pos, "'return' statement found outside function definition")
- const Type ret_type = stmt->val ? check_exp(env, stmt->val) : t_void;
- CHECK_OB(ret_type)
+ DECL_OB(const Type, ret_type, = stmt->val ? check_exp(env, stmt->val) : t_void)
if(env->func->value_ref->type == t_lambda) {
if(env->func->def->base->ret_type &&
isa(ret_type, env->func->def->base->ret_type) < 0 &&
ANN Value case_value(const Exp exp);
ANN static m_bool check_stmt_case(const Env env, const Stmt_Exp stmt) {
CHECK_BB(switch_inside(env, stmt_self(stmt)->pos));
- const Type t = check_exp(env, stmt->val);
- CHECK_OB(t);
+ DECL_OB(const Type, t, = check_exp(env, stmt->val))
if(isa(t, t_int) < 0)
ERR_B(stmt_self(stmt)->pos, "invalid type '%s' case expression. should be 'int'", t->name)
const Value v = case_value(stmt->val);
#include "vm.h"
#include "gwion.h"
ANN Func get_func(const Env env, const Func_Def def) {
- Func f = def->base->func;
- CHECK_OO(f)
+ DECL_OO(Func, f, = def->base->func)
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)) {
++end;
ANN m_bool operator_set_func(const struct Op_Import* opi) {
const Nspc nspc = ((Func)opi->data)->value_ref->owner;
const Vector v = (Vector)map_get(&nspc->info->op_map, opi->op);
- M_Operator* mo = operator_find(v, opi->lhs, opi->rhs);
- CHECK_OB(mo)
+ DECL_OB(M_Operator*, mo, = operator_find(v, opi->lhs, opi->rhs))
mo->func = (Func)opi->data;
return GW_OK;
}
ANN m_bool scan0_stmt_type(const Env env, const Stmt_Type stmt) {
CHECK_BB(env_access(env, stmt->ext->flag, stmt_self(stmt)->pos))
- const Type base = stmt->tmpl ? find_type(env, stmt->ext->xid) : known_type(env, stmt->ext);
- CHECK_OB(base)
+ DECL_OB(const Type, base, = stmt->tmpl ? find_type(env, stmt->ext->xid) : known_type(env, stmt->ext))
CHECK_BB(scan0_defined(env, stmt->xid, td_pos(stmt->ext)))
if(!stmt->ext->types && (!stmt->ext->array || !stmt->ext->array->exp)) {
const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(stmt->xid), base);
CHECK_BB(scan0_class_def_pre(env, cdef))
CHECK_OB((cdef->base.type = scan0_class_def_init(env, cdef)))
if(cdef->body) {
-int call = cdef->base.tmpl && !cdef->base.tmpl->call;
-if(call)cdef->base.tmpl->call = (Type_List)1;
- CHECK_BB(env_body(env, cdef, scan0_section))
-if(call)cdef->base.tmpl->call = NULL;
-}
+ int call = cdef->base.tmpl && !cdef->base.tmpl->call;
+ if(call)cdef->base.tmpl->call = (Type_List)1;
+ CHECK_BB(env_body(env, cdef, scan0_section))
+ if(call)cdef->base.tmpl->call = NULL;
+ }
(void)mk_class(env, cdef->base.type);
if(GET_FLAG(cdef, global))
env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
ANN static m_bool scan1_stmt(const Env env, Stmt stmt);
ANN static Type void_type(const Env env, const Type_Decl* td) {
- const Type t = known_type(env, td);
- CHECK_OO(t)
+ DECL_OO(const Type, t, = known_type(env, td))
if(t->size)
return t;
ERR_O(td_pos(td), "cannot declare variables of size '0' (i.e. 'void')...")
}
ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) {
- const Type t = void_type(env, decl->td);
- CHECK_OO(t);
+ DECL_OO(const Type ,t, = void_type(env, decl->td))
if(decl->td->xid && decl->td->xid->xid == insert_symbol("auto") && decl->type)
return decl->type;
if(!env->scope->depth && env->class_def) {
const loc_t pos = td_pos(cdef->base.ext);
if(cdef->base.ext->array)
CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp))
- const Type parent = cdef->base.type->e->parent = known_type(env, cdef->base.ext);
- CHECK_OB(parent)
+ DECL_OB(const Type , parent, = cdef->base.type->e->parent = known_type(env, cdef->base.ext))
Type t = parent;
do {
if(cdef->base.type == t)
}
ANN static inline m_int _push(const Env env, const Class_Def c) {
- const m_int scope = env_push_type(env, c->base.type);
- CHECK_BB(scope)
+ DECL_BB(const m_int, scope, = env_push_type(env, c->base.type))
return (!c->base.tmpl || tmpl_push(env, c->base.tmpl)) ?
scope : GW_ERROR;
}
// TODO: 'v' should be 2° argument
ANN m_bool
scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) {
- const m_int scope = _push(e, c);
- CHECK_BB(scope)
+ DECL_BB(const m_int, scope, = _push(e, c))
const m_bool ret = _body(d, c->body, f);
_pop(e, c, scope);
return ret;
#undef scanx_ext
ANN m_bool
scanx_ext(const Env e, const Class_Def c, const _exp_func f, void* d) {
- const m_int scope = _push(e, c);
- CHECK_BB(scope)
+ DECL_BB(const m_int, scope, = _push(e, c))
const m_bool ret = f(d, c);
_pop(e, c, scope);
return ret;
Type_List call = info->call;
size_t size = tmpl_set(info, info->cdef->base.type);
do {
- const Type t = known_type(env, call->td);
- CHECK_OB(t)
+ DECL_OB(const Type, t, = known_type(env, call->td))
size += tmpl_set(info, t);
} while((call = call->next) && (base = base->next) && ++size);
return size + 16 + 3;
}
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);
- CHECK_OO(name)
+ DECL_OO(const Symbol, name, = template_id(env, def, call))
if(env->class_def && name == insert_symbol(env->class_def->name))
return env->class_def->e->def;
const Type t = nspc_lookup_type1(env->curr, name);
"you must provide template types for type '%s'", t->name)
if(template_match(t->e->def->base.tmpl->list, type->types) < 0)
ERR_O(type->xid->pos, "invalid template types number")
- const Class_Def a = template_class(env, t->e->def, type->types);
- CHECK_OO(a)
+ DECL_OO(const Class_Def, a, = template_class(env, t->e->def, type->types))
SET_FLAG(a, ref);
if(a->base.type)
return a->base.type;
#include "parse.h"
ANN Type type_decl_resolve(const Env env, const Type_Decl* td) {
- const Type base = find_type(env, td->xid);
- CHECK_OO(base)
- const Type t = scan_type(env, base, td);
+ DECL_OO(const Type, base, = find_type(env, td->xid))
+ DECL_OO(const Type, t, = scan_type(env, base, td))
return !td->array ? t : array_type(env, t, td->array->depth);
}
-Subproject commit f2e8f337708be41cac47fb85862766b801d1bda6
+Subproject commit 512600b2403a7f31454245f3957866ab8cbde070