++emit->env->scope->depth;
emit_push_scope(emit);
const Instr gc = emit_add_instr(emit, NoOp);
- CHECK_BB(emit_stmt(emit, stmt, pop))
- const m_bool pure = !vector_back(&emit->info->pure);
- if(!pure) {
- gc->opcode = eGcIni;
- emit_add_instr(emit, GcEnd);
+ if(emit_stmt(emit, stmt, pop) > 0) {
+ const m_bool pure = !vector_back(&emit->info->pure);
+ if(!pure) {
+ gc->opcode = eGcIni;
+ emit_add_instr(emit, GcEnd);
+ }
}
emit_pop_scope(emit);
--emit->env->scope->depth;
(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type)))
) {
CHECK_BB(emit_exp(emit, member->base, 0))
- emit_except(emit, member->t_base);
+ emit_add_instr(emit, GWOP_EXCEPT);
+
+// emit_except(emit, member->t_base);
}
if(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type))
return emit_member_func(emit, member);
emit_push_scope(emit);
if(fdef->base->tmpl)
CHECK_BB(template_push_types(emit->env, fdef->base->tmpl))
- CHECK_BB(emit_func_def_body(emit, fdef))
- emit_func_def_return(emit);
- emit_func_def_code(emit, func);
+ const m_bool ret = emit_func_def_body(emit, fdef);
+ if(ret > 0)
+ emit_func_def_return(emit);
if(fdef->base->tmpl)
emit_pop_type(emit);
- emit->env->func = former;
- if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl)
- emit_func_def_global(emit, func->value_ref);
- if(emit->info->memoize && GET_FLAG(func, pure))
- func->code->memoize = memoize_ini(emit, func,
- kindof(func->def->base->ret_type->size, !func->def->base->ret_type->size));
- return GW_OK;
+ if(ret > 0) {
+ emit_func_def_code(emit, func);
+ emit->env->func = former;
+ if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl)
+ emit_func_def_global(emit, func->value_ref);
+ if(emit->info->memoize && GET_FLAG(func, pure))
+ func->code->memoize = memoize_ini(emit, func,
+ kindof(func->def->base->ret_type->size, !func->def->base->ret_type->size));
+ }
+ return ret;
}
#define emit_fptr_def dummy_func
GWI_BB(gwi_gack(gwi, t_bool, gack_bool))
gwi->gwion->type[et_bool] = t_bool;
GWI_BB(gwi_oper_ini(gwi, NULL, "int", "bool"))
+ GWI_BB(gwi_oper_add(gwi, opck_unary_meta)) // should return bool
GWI_BB(gwi_oper_end(gwi, "!", IntNot))
gwi_reserve(gwi, "maybe");
struct SpecialId_ spid = { .type=t_bool, .exec=RegPushMaybe, .is_const=1 };
#include "import.h"
#include "emit.h"
#include "traverse.h"
+#include "parse.h"
#include "gwi.h"
static OP_CHECK(opck_ptr_assign) {
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
- return exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
+ return exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(get_type_name(env, unary->exp->type->name, 1)));
}
-
+#include "tuple.h"
static OP_CHECK(opck_ptr_cast) {
const Exp_Cast* cast = (Exp_Cast*)data;
- const Type t = type_decl_resolve(env, cast->td);
+ DECL_ON(const Type, t, = type_decl_resolve(env, cast->td))
if(!GET_FLAG(t, check)) {
assert(t->e->def);
- CHECK_BO(traverse_class_def(env, t->e->def))
+ CHECK_BN(traverse_class_def(env, t->e->def))
}
-// TODO check types.
-// const Type ptr = nspc_
-// if(t && isa(cast->exp->type, get_type(env, t, 1)) > 0)
+ const Type to = (Type)vector_at(&t->e->tuple->types, 0);
+ if(isa(cast->exp->type, to) > 0)
return t;
-// ERR_N(exp_self(cast)->pos, "invalid pointer cast")
+ ERR_N(exp_self(cast)->pos, "invalid pointer cast")
}
static OP_CHECK(opck_implicit_ptr) {
#include "operator.h"
#include "import.h"
#include "gwi.h"
+#include "specialid.h"
void free_vararg(MemPool p, struct Vararg_* arg) {
xfree(arg->d);
GWI_BB(gwi_oper_add(gwi, at_varobj))
GWI_BB(gwi_oper_end(gwi, "@=>", VarargAssign))
register_freearg(gwi, VarargIni, freearg_vararg);
+struct SpecialId_ spid = { .type=t_vararg, .exec=RegPushImm, .is_const=1 };
+gwi_specialid(gwi, "vararg", &spid);
gwi_reserve(gwi, "vararg");
return GW_OK;
}
static ANN Type check_exp_array(const Env env, const Exp_Array* array) {
CHECK_OO((array->array->type = check_exp(env, array->base)))
- CHECK_OO(check_subscripts(env, array->array))
+ CHECK_BO(check_subscripts(env, array->array))
return at_depth(env, array->array);
}
}
if(isa(ret_type, env->func->def->base->ret_type) > 0)
return GW_OK;
- return check_implicit(env, stmt->val, env->func->def->base->ret_type);
+ if(stmt->val)
+ return check_implicit(env, stmt->val, env->func->def->base->ret_type);
+ if(isa(env->func->def->base->ret_type, env->gwion->type[et_void]) > 0)
+ return GW_OK;
+ ERR_B(stmt_self(stmt)->pos, _("missing value for return statement"))
}
#define describe_check_stmt_stack(stack, name) \
const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), env->gwion->type[et_object]);
t->e->owner = env->curr;
t->nspc = new_nspc(env->gwion->mp, t->name);
-// t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr;
t->nspc->parent = env->curr;
t->e->def = cdef;
t->flag = cdef->flag;
((Exp_Decl*)decl)->type = scan1_exp_decl_type(env, (Exp_Decl*)decl);
CHECK_OB(decl->type)
const m_bool global = GET_FLAG(decl->td, global);
+ if(global && decl->type->e->owner != env->global_nspc)
+ ERR_B(exp_self(decl)->pos, _("type '%s' is not global\n"), decl->type->name)
if(env->context)
env->context->global = 1;
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
const Value v = nspc_lookup_value1(nspc, f->base->xid);
if(v) {
Func ff = v->d.func_ref;
+ if(!ff)continue;
do {
if(ff->def == f) {
++i;
vector_init(&v);
do {
const Type t = nspc_lookup_type0(env->curr, id->xid);
+ if(!t)continue;
vector_add(&v, (vtype)t);
tlen += strlen(t->name);
} while((id = id->next) && ++tlen);