From 812865ba6273d1d37a9e08934588a74a4d868641 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 12 Feb 2024 21:52:10 +0100 Subject: [PATCH] :fire: even more progress, hehe --- include/arg.h | 6 +-- include/array.h | 2 +- include/emit.h | 19 +++---- include/escape.h | 6 +-- include/import/checker.h | 14 ++--- include/import/internals.h | 3 +- include/instr.h | 2 +- include/parse.h | 20 +------ include/pass.h | 8 +-- src/arg.c | 12 ++--- src/emit/emit.c | 101 ++++++++++++++++++------------------ src/emit/escape.c | 25 +++++---- src/gwion.c | 2 +- src/import/cleaner.c | 8 +-- src/import/import_cdef.c | 4 +- src/import/import_checker.c | 60 ++++++++++----------- src/import/import_enum.c | 6 +-- src/import/import_fdef.c | 12 ++--- src/import/import_item.c | 4 +- src/import/import_tdef.c | 6 +-- src/import/import_udef.c | 10 ++-- src/lib/array.c | 16 ++++-- src/lib/closure.c | 2 +- src/lib/dict.c | 2 +- src/lib/instr.c | 2 +- src/lib/object_op.c | 2 - src/lib/opfunc.c | 4 +- src/lib/xork.c | 2 +- src/parse/check.c | 18 +++---- src/parse/scan1.c | 16 +++--- src/parse/scan2.c | 12 ++--- src/parse/scanx.c | 2 +- src/pass.c | 6 +-- 33 files changed, 205 insertions(+), 209 deletions(-) diff --git a/include/arg.h b/include/arg.h index d550620e..0eaff80e 100644 --- a/include/arg.h +++ b/include/arg.h @@ -27,7 +27,7 @@ typedef struct CliArg_ { enum COLOR color; } CliArg; -ANN void arg_release(CliArg *); -ANN m_bool arg_parse(const Gwion, CliArg *); -ANN void arg_compile(const Gwion, CliArg *); +ANN void arg_release(CliArg *); +ANN bool arg_parse(const Gwion, CliArg *); +ANN void arg_compile(const Gwion, CliArg *); #endif diff --git a/include/array.h b/include/array.h index 8399785e..4ae02081 100644 --- a/include/array.h +++ b/include/array.h @@ -22,5 +22,5 @@ typedef struct ArrayInfo_ { ANN Type check_array_access(const Env env, const Array_Sub array); ANN m_bool emit_array_access(const Emitter emit, struct ArrayAccessInfo *const info); -ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args); +ANN2(1,2) bool check_array_instance(const Env env, Type_Decl *td, Exp* args); #endif diff --git a/include/emit.h b/include/emit.h index 030621f4..6692876c 100644 --- a/include/emit.h +++ b/include/emit.h @@ -66,23 +66,21 @@ ANEW ANN Emitter new_emitter(MemPool); ANN void free_emitter(MemPool, Emitter); ANN m_bool emit_ast(const Env env, Ast *ast); ANN m_bool emit_func_def(const Emitter emit, const Func_Def fdef); -ANN m_bool emit_exp_call1(const Emitter, const Func, const m_uint size, const bool is_static); +ANN m_bool emit_exp(const Emitter, Exp*); +ANN bool emit_exp_call1(const Emitter, const Func, const m_uint size, const bool is_static); ANN2(1) Instr emit_add_instr(const Emitter, const f_instr) __attribute__((returns_nonnull)); ANN Code * emit_class_code(const Emitter, const m_str); -ANN m_bool emit_array_extend(const Emitter, const Type, Exp*); -ANN void emit_class_finish(const Emitter, const Nspc); ANN2(1, 2) -m_bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, - const m_bool); +bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, + const bool); ANN m_uint emit_code_offset(const Emitter emit); ANN m_uint emit_local(const Emitter emit, const Type t); ANN m_uint emit_localn(const Emitter emit, const Type t); ANN void* emit_localx(const Emitter emit, const Type t); ANN m_uint emit_local_exp(const Emitter emit, Exp*); -ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *); -ANN m_bool emit_exp(const Emitter, Exp*); +ANN bool emit_exp_spork(const Emitter, const Exp_Unary *); ANN void emit_object_addref(const Emitter emit, const m_int size, const bool emit_var); @@ -90,7 +88,7 @@ ANN void emit_struct_addref(const Emitter emit, const Type t, const m_int size, const bool emit_var); ANN static inline void emit_compound_addref(const Emitter emit, const Type t, const m_int size, - const m_bool emit_var) { + const bool emit_var) { return !tflag(t, tflag_struct) ? emit_object_addref(emit, size, emit_var) : emit_struct_addref(emit, t, size, emit_var); } @@ -113,9 +111,8 @@ ANN static inline m_uint emit_code_size(const Emitter emit) { ANN void emit_push_scope(const Emitter emit); ANN void emit_pop_scope(const Emitter emit); -ANN m_bool ensure_emit(const Emitter, const Type); -ANN m_bool emit_ensure_func(const Emitter emit, const Func f); -ANN m_bool get_emit_var(const Emitter emit, const Type t, bool is_var); +ANN bool emit_ensure_func(const Emitter emit, const Func f); +ANN bool get_emit_var(const Emitter emit, const Type t, bool is_var); ANN static inline void emit_regmove(const Emitter emit, const m_uint i) { const Instr instr = emit_add_instr(emit, RegMove); diff --git a/include/escape.h b/include/escape.h index dd960c4d..a6e2429a 100644 --- a/include/escape.h +++ b/include/escape.h @@ -1,6 +1,6 @@ #ifndef __ESCAPE #define __ESCAPE -char * escape_table(MemPool); -ANN char str2char(const Emitter, const m_str, const loc_t); -ANN m_bool escape_str(const Emitter, m_str, const loc_t); +char *escape_table(MemPool); +ANN bool str2char(const Emitter, const m_str, char *, const loc_t); +ANN bool escape_str(const Emitter, m_str, const loc_t); #endif diff --git a/include/import/checker.h b/include/import/checker.h index 6bb44b03..35328d5f 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -39,12 +39,12 @@ typedef struct OperCK { // name_checker ? struct Vector_ effect; } OperCK; -ANN void func_checker_clean(const Gwi gwi, struct ImportCK *ck); -ANN m_bool check_typename_def(const Gwi gwi, struct ImportCK *ck); +ANN void func_checker_clean(const Gwi gwi, struct ImportCK *ck); +ANN bool check_typename_def(const Gwi gwi, struct ImportCK *ck); -ANN Symbol str2sym(const Gwion, const m_str, const loc_t); -ANN ID_List str2symlist(const Gwion, const m_str, const loc_t); -ANN m_bool str2var(const Gwion, Var_Decl*, const m_str, const loc_t); +ANN Symbol str2sym(const Gwion, const m_str, const loc_t); +ANN ID_List str2symlist(const Gwion, const m_str, const loc_t); +ANN bool str2var(const Gwion, Var_Decl*, const m_str, const loc_t); ANN Type_Decl *str2td(const Gwion, const m_str, const loc_t); ANN Type str2type(const Gwion, const m_str, const loc_t); @@ -66,8 +66,8 @@ ANN static inline Type_Decl *type2td(const Gwion gwion, const Type t, #define gwi_str2td(gwi, path) str2td(gwi->gwion, path, gwi->loc) #define gwi_str2type(gwi, path) str2type(gwi->gwion, path, gwi->loc) -ANN m_bool ck_ini(const Gwi, const enum importck_type); -ANN m_bool ck_ok(const Gwi, const enum importck_type); +ANN bool ck_ini(const Gwi, const enum importck_type); +ANN bool ck_ok(const Gwi, const enum importck_type); ANN void ck_end(const Gwi gwi); ANN void ck_clean(const Gwi gwi); #endif diff --git a/include/import/internals.h b/include/import/internals.h index 07e855d3..63f0b859 100644 --- a/include/import/internals.h +++ b/include/import/internals.h @@ -15,10 +15,11 @@ } #define GWION_ERR(pos, a, ...) \ { env_err(gwion->env, pos, (a), ##__VA_ARGS__); } + #define GWION_ERR_B(pos, a, ...) \ { \ GWION_ERR(pos, (a), ##__VA_ARGS__); \ - return GW_ERROR; \ + return false; \ } #define GWION_ERR_O(pos, a, ...) \ { \ diff --git a/include/instr.h b/include/instr.h index 25724cf7..3be97ae2 100644 --- a/include/instr.h +++ b/include/instr.h @@ -65,7 +65,7 @@ struct dottmpl_ { Type type; m_str tmpl_name; }; -ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v); +ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v); INSTR(SetFunc); INSTR(FuncWait); diff --git a/include/parse.h b/include/parse.h index d5643630..273ddbfb 100644 --- a/include/parse.h +++ b/include/parse.h @@ -33,14 +33,6 @@ } #define RET_NSPC(exp) \ - ++env->scope->depth; \ - nspc_push_value(env->gwion->mp, env->curr); \ - const m_bool ret = exp; \ - nspc_pop_value(env->gwion->mp, env->curr); \ - --env->scope->depth; \ - return ret; - -#define RET_NSPC_B(exp) \ ++env->scope->depth; \ nspc_push_value(env->gwion->mp, env->curr); \ const bool ret = exp; \ @@ -86,24 +78,16 @@ } #define describe_stmt_func(prefix, name, type, prolog, exp) \ - ANN static m_bool prefix##_stmt_##name(const Env env, const type stmt) { \ + ANN static bool prefix##_stmt_##name(const Env env, const type stmt) { \ RET_NSPC(exp) \ } -#define describe_stmt_func_b(prefix, name, type, prolog, exp) \ - ANN static bool prefix##_stmt_##name(const Env env, const type stmt) { \ - RET_NSPC_B(exp) \ - } - -//ANN m_bool check_stmt(const Env env, Stmt* stmt); ANN bool check_stmt_list(const Env env, const Stmt_List); -typedef m_bool (*_exp_func)(const void *, const void *); - ANN bool scanx_body(const Env e, const Class_Def c, const _envset_func f, void *d); -static inline ANN m_bool env_body(const Env env, const Class_Def cdef, +static inline ANN bool env_body(const Env env, const Class_Def cdef, const _envset_func f) { return scanx_body(env, cdef, f, env); } diff --git a/include/pass.h b/include/pass.h index db978889..5b02fc0b 100644 --- a/include/pass.h +++ b/include/pass.h @@ -9,8 +9,8 @@ struct Passes_ { typedef m_bool (*compilation_pass)(const Env, Ast*); ANEW ANN struct Passes_ *new_passes(const Gwion); -ANN void free_passes(MemPool mp, struct Passes_ *); -ANN void pass_register(const Gwion, const m_str, const compilation_pass); -ANN void pass_default(const Gwion); -ANN m_bool pass_set(const Gwion, const Vector); +ANN void free_passes(MemPool mp, struct Passes_ *); +ANN void pass_register(const Gwion, const m_str, const compilation_pass); +ANN void pass_default(const Gwion); +ANN bool pass_set(const Gwion, const Vector); #endif diff --git a/src/arg.c b/src/arg.c index 163ecd35..6fe0310a 100644 --- a/src/arg.c +++ b/src/arg.c @@ -227,7 +227,7 @@ ANN static void split_line(const m_str line, const Vector v) { while (d) { const m_str str = strsep(&d, " "); const size_t sz = strlen(str); - const m_bool arg = (str[sz - 1] == '\n'); + const bool arg = (str[sz - 1] == '\n'); vector_add(v, (vtype)strndup(str, arg ? sz - 1 : sz)); } xfree(d); @@ -238,7 +238,7 @@ ANN static Vector get_config(const char *name) { char * line = NULL; size_t len = 0; FILE * f = fopen(name, "r"); - CHECK_OO(f); + CHECK_O(f); const Vector v = (Vector)xmalloc(sizeof(struct Vector_)); vector_init(v); while (getline(&line, &len, f) != -1) { @@ -254,7 +254,7 @@ struct ArgInternal { CliArg *arg; }; -ANN m_bool _arg_parse(struct ArgInternal *arg); +ANN bool _arg_parse(struct ArgInternal *arg); ANN static void config_parse(struct ArgInternal *arg, const char *name) { const Vector v = get_config(name); @@ -358,7 +358,7 @@ static void myproc(void *data, cmdopt_t *option, const char *arg) { #define GWION_VERSION "N.A." #endif -ANN m_bool _arg_parse(struct ArgInternal *arg) { +ANN bool _arg_parse(struct ArgInternal *arg) { cmdapp_t app; const cmdapp_info_t info = { .program = "gwion", @@ -381,7 +381,7 @@ ANN m_bool _arg_parse(struct ArgInternal *arg) { if (cmdapp_run(&app) == EXIT_SUCCESS && cmdapp_should_exit(&app)) arg->arg->quit = 1; cmdapp_destroy(&app); - return GW_OK; + return true; } ANN static void config_default(struct ArgInternal *arg) { @@ -391,7 +391,7 @@ ANN static void config_default(struct ArgInternal *arg) { config_parse(arg, c); } -ANN m_bool arg_parse(const Gwion gwion, CliArg *a) { +ANN bool arg_parse(const Gwion gwion, CliArg *a) { if(!a->uargs) a->arg.argc = 1; if(a->config_args) a->arg.argv = a->config_args(&a->arg.argc, a->arg.argv); struct ArgInternal arg = {.gwion = gwion, .arg = a}; diff --git a/src/emit/emit.c b/src/emit/emit.c index 131bc658..3b0cec62 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -120,16 +120,16 @@ static const f_instr allocword[4] = {AllocWord, AllocWord2, AllocWord3, ANN static m_bool emit_class_def(const Emitter, const Class_Def); ANN static bool emit_cdef(const Emitter, const Type); -ANN /*static inline*/ m_bool ensure_emit(const Emitter emit, const Type t) { +ANN static m_bool ensure_emit(const Emitter emit, const Type t) { if (tflag(t, tflag_emit) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) - return GW_OK; // clean callers - if(!tflag(t, tflag_tmpl))return GW_OK; + return true; + if(!tflag(t, tflag_tmpl)) return true; struct EnvSet es = {.env = emit->env, .data = emit, .func = (_envset_func)emit_cdef, .scope = emit->env->scope->depth, .flag = tflag_emit}; - return envset_run(&es, t) ? GW_OK : GW_ERROR; + return envset_run(&es, t); } ANN void emit_object_release(const Emitter emit, const m_uint offset) { @@ -319,16 +319,16 @@ ANN static inline void maybe_ctor(const Emitter emit, const Type t) { } ANN2(1, 2) -static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t, +static ArrayInfo *emit_array_extend(const Emitter emit, const Type t, Exp* e, const uint is_ref); -ANN static m_bool emit_pre_ctor(const Emitter emit, const Type type) { +ANN static bool emit_pre_ctor(const Emitter emit, const Type type) { if (type->info->parent) { - CHECK_BB(emit_pre_ctor(emit, type->info->parent)); + CHECK_B(emit_pre_ctor(emit, type->info->parent)); if (tflag(type, tflag_typedef) && type->info->parent->array_depth) - CHECK_OB(emit_array_extend_inner(emit, type, type->info->cdef->base.ext->array->exp, false)); + CHECK_B(emit_array_extend(emit, type, type->info->cdef->base.ext->array->exp, false)); } maybe_ctor(emit, type); - return GW_OK; + return true; } ANN static void struct_expand(const Emitter emit, const Type t) { @@ -346,7 +346,7 @@ ANN static m_bool emit_pre_constructor_array(const Emitter emit, const Instr instr = emit_add_instr(emit, ArrayStruct); instr->m_val = type->size; } - CHECK_BB(emit_pre_ctor(emit, type)); + CHECK_b(emit_pre_ctor(emit, type)); if (!tflag(type, tflag_struct)) emit_add_instr(emit, ArrayBottom); else @@ -361,15 +361,15 @@ ANN static m_bool emit_pre_constructor_array(const Emitter emit, } ANN2(1) -static m_bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) { - if (e) CHECK_BB(emit_exp(emit, e)); +static bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) { + if (e) CHECK_b(emit_exp(emit, e)); m_uint count = 0; while (e) { ++count; e = e->next; } for (m_uint i = count; i < depth; ++i) emit_pushimm(emit, 0); - return GW_OK; + return true; } ANEW ANN static ArrayInfo *new_arrayinfo(const Emitter emit, const Type t, const loc_t loc) { @@ -395,9 +395,9 @@ ANN static inline m_bool arrayinfo_ctor(const Emitter emit, ArrayInfo *info) { } ANN2(1, 2) -static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t, +static ArrayInfo *emit_array_extend(const Emitter emit, const Type t, Exp* e, const uint is_ref) { - CHECK_BO(extend_indices(emit, e, get_depth(t))); + CHECK_O(extend_indices(emit, e, get_depth(t))); ArrayInfo * info = new_arrayinfo(emit, t, t->info->cdef->base.tag.loc); const Instr alloc = emit_add_instr(emit, ArrayAlloc); alloc->m_val = (m_uint)info; @@ -421,26 +421,26 @@ ANN static inline void emit_notpure(const Emitter emit) { } ANN2(1, 2) -m_bool emit_instantiate_object(const Emitter emit, const Type type, - const Array_Sub array, const m_bool is_ref) { +bool emit_instantiate_object(const Emitter emit, const Type type, + const Array_Sub array, const bool is_ref) { emit_notpure(emit); if (type->array_depth) { - DECL_OB(ArrayInfo *, info, - = emit_array_extend_inner(emit, type, array ? array->exp : NULL, + DECL_B(ArrayInfo *, info, + = emit_array_extend(emit, type, array ? array->exp : NULL, is_ref)); - return GW_OK; + return true; } else if (!is_ref) { if(!tflag(type, tflag_typedef) || isa(type, emit->gwion->type[et_closure]) > 0) { const Instr instr = emit_add_instr(emit, ObjectInstantiate); instr->m_val2 = (m_uint)type; } // maybe we should instantiate the first actual type - CHECK_BB(emit_pre_ctor(emit, type)); + CHECK_b(emit_pre_ctor(emit, type)); } - return GW_OK; + return true; } ANN2(1, 2) -m_bool emit_instantiate_decl(const Emitter emit, const Type type, +bool emit_instantiate_decl(const Emitter emit, const Type type, const Type_Decl *td, const m_bool is_ref) { return emit_instantiate_object(emit, type, td->array, is_ref); } @@ -660,7 +660,7 @@ ANN static m_bool emit_prim_dict(const Emitter emit, Exp* *data) { } e->next = next; CHECK_BB(emit_exp(emit, &func)); - CHECK_BB(emit_exp_call1(emit, func.type->info->func, + CHECK_b(emit_exp_call1(emit, func.type->info->func, func.type->info->func->def->base->ret_type->size, true)); count++; } while((e = e->next->next)); @@ -747,7 +747,8 @@ ANN static m_bool emit_prim_float(const Emitter emit, const m_float *fnum) { } ANN static m_bool emit_prim_char(const Emitter emit, const m_str *str) { - const char c = str2char(emit, *str, prim_pos(str)); + char c; + CHECK_b(str2char(emit, *str, &c, prim_pos(str))); emit_pushimm(emit, c); return GW_OK; } @@ -760,7 +761,7 @@ ANN static m_bool emit_prim_str(const Emitter emit, const struct AstString *str) char c[sz + 1]; if (sz) { strcpy(c, str->data); - CHECK_BB(escape_str(emit, c, prim_pos(str))); + CHECK_B(escape_str(emit, c, prim_pos(str))); } else c[0] = '\0'; v->d.obj = new_string(emit->gwion, c); @@ -830,13 +831,13 @@ ANN static m_bool emit_prim_interp(const Emitter emit, Exp* *exp) { return GW_OK; } -ANN m_bool emit_ensure_func(const Emitter emit, const Func f) { +ANN bool emit_ensure_func(const Emitter emit, const Func f) { const ValueFrom *from = f->value_ref->from; if(from->owner_class) - CHECK_BB(ensure_emit(emit, from->owner_class)); - if(f->code) return GW_OK; + CHECK_b(ensure_emit(emit, from->owner_class)); + if(f->code) return true; const m_uint scope = emit_push(emit, from->owner_class, from->owner); - const m_bool ret = emit_func_def(emit, f->def); + const bool ret = emit_func_def(emit, f->def); emit_pop(emit, scope); return ret; } @@ -845,14 +846,14 @@ ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) { if(emit->locale->def->d.code) { const Stmt* stmt = mp_vector_at((emit->locale->def->d.code), Stmt, 0); const Func f = stmt->d.stmt_exp.val->d.exp_call.func->type->info->func; - CHECK_OB(emit_ensure_func(emit, f)); + CHECK_b(emit_ensure_func(emit, f)); } - CHECK_OB(emit_ensure_func(emit, emit->locale)); + CHECK_b(emit_ensure_func(emit, emit->locale)); comptime_ini(emit, "locale"); const M_Object string = new_string(emit->gwion, s_name(*id)); emit_pushimm(emit, (m_uint)string); emit_pushimm(emit, (m_uint)emit->locale->code); - CHECK_BB(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true)); + CHECK_b(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true)); m_float ret; comptime_end(emit, SZ_FLOAT, &ret); if(ret == -1.0) @@ -877,7 +878,7 @@ ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, ANN static m_bool _decl_static(const Emitter emit, const Exp_Decl *decl, const Var_Decl *var_decl, const uint is_ref) { const Value v = var_decl->value; - if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref)); + if(!decl->args) CHECK_b(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref)); else CHECK_BB(emit_exp(emit, decl->args)); CHECK_BB(emit_dot_static_data(emit, v, 1)); emit_add_instr(emit, Assign); @@ -1012,7 +1013,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const bool emit_addr = (!is_obj || is_ref) ? emit_var : true; if (is_obj && !is_ref && !exp_self(decl)->ref) { - if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); + if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); else CHECK_BB(emit_exp(emit, decl->args)); } f_instr *exec = (f_instr *)allocmember; @@ -1055,7 +1056,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const bool emit_addr = (!is_obj || is_ref) ? emit_var : true; if (is_obj && !is_ref) { - if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); + if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); else CHECK_BB(emit_exp(emit, decl->args)); } if (type->size > SZ_INT) @@ -1307,7 +1308,7 @@ ANN static m_bool emit_new_struct(const Emitter emit,const Exp_Call *call) { else emit_regpushmem(emit, offset, t->size, true); if(tflag(t, tflag_ctor)) emit_ext_ctor(emit, t); emit_add_instr(emit, NoOp); - CHECK_BB(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true + CHECK_b(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true return GW_OK; } @@ -1341,7 +1342,7 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { if (f != emit->env->func || (f && f->value_ref->from->owner_class)) CHECK_BB(prepare_call(emit, call)); else CHECK_BB(emit_func_args(emit, call)); - CHECK_BB(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func))); + CHECK_b(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func))); } return GW_OK; } @@ -1424,7 +1425,7 @@ ANN static inline m_bool traverse_emit_func_def(const Emitter emit, return emit_func_def(emit, fdef); } -ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v) { +ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v) { const m_uint scope = emit->env->scope->depth; const bool shadowing = emit->env->scope->shadowing; emit->env->scope->shadowing = true; @@ -1439,7 +1440,7 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Valu emit_pop(emit, scope); envset_pop(&es, v->from->owner_class); emit->env->scope->shadowing = shadowing; - return ret ? GW_OK : GW_ERROR; + return ret; } static INSTR(fptr_call) { @@ -1617,20 +1618,20 @@ ANN static void call_finish(const Emitter emit, const Func f, instr->m_val2 = offset; } -ANN m_bool emit_exp_call1(const Emitter emit, const Func f, +ANN bool emit_exp_call1(const Emitter emit, const Func f, const m_uint size, const bool is_static) { const EmitterStatus status = emit->status; emit->status = (EmitterStatus){}; if(unlikely(fflag(f, fflag_fptr))) emit_fptr_call(emit, f); else if (unlikely(!f->code && emit->env->func != f)) { - if (fflag(f, fflag_tmpl)) CHECK_BB(emit_template_code(emit, f)); + if (fflag(f, fflag_tmpl)) CHECK_b(emit_template_code(emit, f)); else //if(is_new(f->def))//if(tflag(f->value_ref->type, tflag_ftmpl)) { const Type t = f->value_ref->from->owner_class; if(t && (!emit->env->curr || isa(t, emit->env->class_def) < 0)) //!is_new(f->def) || f->value_ref->from->owner_class->array_depth) //if(f->value_ref->from->owner_class->array_depth) -CHECK_BB(emit_ensure_func(emit, f)); +CHECK_b(emit_ensure_func(emit, f)); } } else if(is_static) push_func_code(emit, f); @@ -1693,10 +1694,10 @@ ANN static m_bool spork_prepare_func(const Emitter emit, const Type t = actual_type(emit->gwion, sp->exp->d.exp_call.func->type); const Func f = t->info->func; if(!f->code && f != emit->env->func) - CHECK_BB(emit_ensure_func(emit, f)); + CHECK_b(emit_ensure_func(emit, f)); push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX, sp->exp->loc); - return emit_exp_call1(emit, f, f->def->base->ret_type->size, false); + return emit_exp_call1(emit, f, f->def->base->ret_type->size, false) ? GW_OK : GW_ERROR; } ANN static VM_Code spork_prepare(const Emitter emit, const struct Sporker *sp) { @@ -1735,7 +1736,7 @@ ANN static void spork_ini(const Emitter emit, const struct Sporker *sp) { instr->m_val2 = (m_uint)sp->type; } -ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { +ANN bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { struct Sporker sporker = { .exp = unary->unary_type == unary_exp ? unary->exp : NULL, .code = unary->unary_type == unary_code ? unary->code : NULL, @@ -1744,7 +1745,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { .loc = exp_self(unary)->loc, .is_spork = (unary->op == insert_symbol("spork")), .emit_var = exp_getvar(exp_self(unary))}; - CHECK_OB((sporker.vm_code = spork_prepare(emit, &sporker))); + CHECK_B((sporker.vm_code = spork_prepare(emit, &sporker))); if(!sporker.is_spork) emit_local_exp(emit, exp_self(unary)); spork_ini(emit, &sporker); @@ -1760,7 +1761,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { .type = emit->env->class_def, .exp_type = ae_exp_primary }; - CHECK_BB(emit_exp(emit, &exp)); + CHECK_b(emit_exp(emit, &exp)); offset += SZ_INT; } if(sporker.captures) { @@ -1779,7 +1780,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { }; if(cap->is_ref) exp_setvar(&exp, true); offset += exp_size(&exp); - CHECK_BB(emit_exp(emit, &exp)); + CHECK_b(emit_exp(emit, &exp)); // emit_exp_addref(emit, &exp, -exp_size(&exp)); } } @@ -1789,7 +1790,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { args->m_val = offset; } (unary->unary_type == unary_code ? spork_code : spork_func)(emit, &sporker); - return GW_OK; + return true; } ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) { diff --git a/src/emit/escape.c b/src/emit/escape.c index 6e617309..a1eb83ce 100644 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@ -22,13 +22,14 @@ char *escape_table(MemPool p) { return escape; } -static int get_escape(const Emitter emit, const char c, const loc_t loc) { - if (emit->info->escape[(int)c]) return emit->info->escape[(int)c]; +static bool get_escape(const Emitter emit, const char c, char *out, const loc_t loc) { + *out = emit->info->escape[(int)c]; + if(out) return true; env_err(emit->env, loc, _("unrecognized escape sequence '\\%c'"), c); - return GW_ERROR; + return false; } -m_bool escape_str(const Emitter emit, const m_str base, const loc_t loc) { +bool escape_str(const Emitter emit, const m_str base, const loc_t loc) { unsigned char *str_lit = (unsigned char *)base; m_str str = base; while (*str_lit) { @@ -62,16 +63,22 @@ m_bool escape_str(const Emitter emit, const m_str base, const loc_t loc) { c1, c3); return GW_ERROR; } - } else - CHECK_BB((*str++ = (char)get_escape(emit, (char)c, loc))); + } else { + char out; + CHECK_B((*str++ = (char)get_escape(emit, (char)c, &out, loc))); + } } else *str++ = (char)*str_lit; ++str_lit; } *str = '\0'; - return GW_OK; + return true; } -ANN char str2char(const Emitter emit, const m_str c, const loc_t loc) { - return c[0] != '\\' ? c[0] : get_escape(emit, c[1], loc); +ANN bool str2char(const Emitter emit, const m_str c, char *out, const loc_t loc) { + if(c[0] != '\\') { + *out = c[0]; + return true; + } + return get_escape(emit, c[1], out, loc); } diff --git a/src/gwion.c b/src/gwion.c index 10f98afb..e26cdfe7 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -117,7 +117,7 @@ ANN m_bool gwion_ini(const Gwion gwion, CliArg *arg) { gwion->type = (Type *)xcalloc(MAX_TYPE, sizeof(struct Type_ *)); arg->si = gwion->vm->bbq->si = new_soundinfo(gwion->mp); new_passes(gwion); - CHECK_BB(arg_parse(gwion, arg)); + CHECK_b(arg_parse(gwion, arg)); if (arg->color == COLOR_NEVER) tcol_override_color_checks(0); else if (arg->color == COLOR_AUTO) diff --git a/src/import/cleaner.c b/src/import/cleaner.c index 6b64baa3..a718cf09 100644 --- a/src/import/cleaner.c +++ b/src/import/cleaner.c @@ -14,17 +14,17 @@ #include "import.h" #include "gwi.h" -ANN m_bool ck_ini(const Gwi gwi, const enum importck_type t) { +ANN bool ck_ini(const Gwi gwi, const enum importck_type t) { if (gwi->ck) // TODO: improve error message GWI_ERR_B(_("already importing")) gwi->ck = mp_calloc2(gwi->gwion->mp, sizeof(ImportCK)); gwi->ck->type = t; - return GW_OK; + return true; } -ANN m_bool ck_ok(const Gwi gwi, const enum importck_type t) { +ANN bool ck_ok(const Gwi gwi, const enum importck_type t) { if (!gwi->ck) GWI_ERR_B(_("import not started")) - if (gwi->ck->type == t) return GW_OK; + if (gwi->ck->type == t) return true; // TODO: improve error message GWI_ERR_B(_("already importing")) } diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index f175e8f8..d5eae18d 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -80,7 +80,7 @@ ANN static Type type_finish(const Gwi gwi, const Type t) { ANN2(1, 2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent) { struct ImportCK ck = {.name = name}; - CHECK_BO(check_typename_def(gwi, &ck)); + CHECK_O(check_typename_def(gwi, &ck)); DECL_OO(Type_Decl *, td, = gwi_str2td(gwi, parent ?: "Object")); Tmpl *tmpl = ck.sl ? new_tmpl(gwi->gwion->mp, ck.sl) : NULL; if (tmpl) CHECK_O(template_push_types(gwi->gwion->env, tmpl)); @@ -106,7 +106,7 @@ Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent) { ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { struct ImportCK ck = {.name = name}; - CHECK_BO(check_typename_def(gwi, &ck)); + CHECK_O(check_typename_def(gwi, &ck)); const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), gwi->gwion->type[et_compound]); t->size = 0; diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 7846300d..45c7ad7b 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -28,7 +28,7 @@ struct AC { m_uint depth; }; -ANN static m_bool ac_run(const Gwion gwion, struct AC *const ac); +ANN static bool ac_run(const Gwion gwion, struct AC *const ac); ANN static Array_Sub mk_array(MemPool mp, struct AC *ac) { const Array_Sub array = new_array_sub(mp, ac->base); array->depth = ac->depth; @@ -70,14 +70,14 @@ ANN Symbol str2sym(const Gwion gwion, const m_str path, const loc_t loc) { return _str2sym(gwion, &tdc, path); } -ANN m_bool str2var(const Gwion gwion, Var_Decl *vd, const m_str path, const loc_t loc) { +ANN bool str2var(const Gwion gwion, Var_Decl *vd, const m_str path, const loc_t loc) { struct td_checker tdc = {.str = path, .loc = loc}; - DECL_OB(const Symbol, sym, = __str2sym(gwion, &tdc)); + DECL_B(const Symbol, sym, = __str2sym(gwion, &tdc)); struct AC ac = {.str = tdc.str, .loc = loc}; - CHECK_BB(ac_run(gwion, &ac)); + CHECK_B(ac_run(gwion, &ac)); vd->tag = MK_TAG(sym, loc); vd->value = NULL; - return GW_OK; + return true; } #define SPEC_ERROR (Specialized_List) GW_ERROR @@ -114,14 +114,14 @@ ANN static Specialized_List __tmpl_list(const Gwion gwion, return sl; } -ANN m_bool check_typename_def(const Gwi gwi, ImportCK *ck) { +ANN bool check_typename_def(const Gwi gwi, ImportCK *ck) { struct td_checker tdc = {.str = ck->name, .loc = gwi->loc}; - if (!(ck->sym = _str2sym(gwi->gwion, &tdc, tdc.str))) return GW_ERROR; + if (!(ck->sym = _str2sym(gwi->gwion, &tdc, tdc.str))) return false; Specialized_List sl = __tmpl_list(gwi->gwion, &tdc); - if (sl == SPEC_ERROR) return GW_ERROR; + if (sl == SPEC_ERROR) return false; ck->sl = sl; ck->name = s_name(ck->sym); - return GW_OK; + return true; } ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc); @@ -213,7 +213,7 @@ ANN static Type_Decl *str2td_fptr(const Gwion gwion, struct td_checker *tdc) { } tdc->str += 2; struct AC ac = {.str = tdc->str, .loc = tdc->loc}; - if(ac_run(gwion, &ac) < 0 ) { + if(!ac_run(gwion, &ac)) { if(tl) free_tmplarg_list(gwion->mp, tl); if(args) free_arg_list(gwion->mp, args); return NULL; @@ -239,7 +239,7 @@ ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc) { DECL_OO(const Symbol, sym, = __str2sym(gwion, tdc)); TmplArg_List tl = td_tmpl(gwion, tdc); struct AC ac = {.str = tdc->str, .loc = tdc->loc}; - CHECK_BO(ac_run(gwion, &ac)); + CHECK_O(ac_run(gwion, &ac)); tdc->str = ac.str; if (tl == (TmplArg_List)GW_ERROR) return NULL; const uint option = get_n(tdc, '?'); @@ -302,7 +302,7 @@ ANN Exp* td2exp(const MemPool mp, const Type_Decl *td) { return base; } -ANN static m_bool td_info_run(const Env env, struct td_info *info) { +ANN static bool td_info_run(const Env env, struct td_info *info) { const Gwion gwion = env->gwion; TmplArg_List tl = info->tl; for(uint32_t i = 0; i < tl->len; i++) { @@ -351,23 +351,23 @@ ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl, text_init(&ls.text, gwion->mp); Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl }; struct td_info info = {.tl = tl, .fmt = &l }; - CHECK_BO(td_info_run(gwion->env, &info)); + CHECK_O(td_info_run(gwion->env, &info)); return ls.text.str; } -ANN static inline m_bool ac_finish(const Gwion gwion, const struct AC *ac) { - if (*ac->str == ']') return GW_OK; +ANN static inline bool ac_finish(const Gwion gwion, const struct AC *ac) { + if (*ac->str == ']') return true; GWION_ERR_B(ac->loc, "unfinished array"); } -ANN static inline m_bool ac_num(const Gwion gwion, const struct AC *ac, +ANN static inline bool ac_num(const Gwion gwion, const struct AC *ac, const m_int num) { - if (num >= 0) return GW_OK; + if (num >= 0) return true; GWION_ERR_B(ac->loc, "negative array dimension") } -ANN static inline m_bool ac_exp(const Gwion gwion, const struct AC *ac) { - if (!ac->depth || ac->base) return GW_OK; +ANN static inline bool ac_exp(const Gwion gwion, const struct AC *ac) { + if (!ac->depth || ac->base) return true; GWION_ERR_B(ac->loc, "malformed array [][...]") } @@ -378,34 +378,34 @@ ANN static void ac_add_exp(struct AC *ac, Exp* exp) { ac->base = ac->exp = exp; } -ANN static inline m_bool ac_noexp(const Gwion gwion, struct AC *ac) { - if (!ac->exp) return GW_OK; +ANN static inline bool ac_noexp(const Gwion gwion, struct AC *ac) { + if (!ac->exp) return true; GWION_ERR_B(ac->loc, "malformed array [...][]") } -ANN static m_bool _ac_run(const Gwion gwion, struct AC *const ac) { +ANN static bool _ac_run(const Gwion gwion, struct AC *const ac) { const m_str str = ac->str; const m_int num = strtol(str, &ac->str, 10); - CHECK_BB(ac_finish(gwion, ac)); + CHECK_B(ac_finish(gwion, ac)); if (str != ac->str) { - CHECK_BB(ac_num(gwion, ac, num)); - CHECK_BB(ac_exp(gwion, ac)); + CHECK_B(ac_num(gwion, ac, num)); + CHECK_B(ac_exp(gwion, ac)); Exp* exp = new_prim_int(gwion->mp, num, ac->loc); // set type: otherwise could fail at emit time exp->type = gwion->type[et_int]; ac_add_exp(ac, exp); } else - CHECK_BB(ac_noexp(gwion, ac)); + CHECK_B(ac_noexp(gwion, ac)); ++ac->str; - return GW_OK; + return true; } -ANN static m_bool ac_run(const Gwion gwion, struct AC *const ac) { +ANN static bool ac_run(const Gwion gwion, struct AC *const ac) { while (*ac->str) { if (*ac->str != '[') break; ++ac->str; - CHECK_BB(_ac_run(gwion, ac)); + CHECK_B(_ac_run(gwion, ac)); ++ac->depth; } - return GW_OK; + return true; } diff --git a/src/import/import_enum.c b/src/import/import_enum.c index c4dcf79c..08da25ea 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -19,7 +19,7 @@ //! \arg string defining a primitive type //! why is return type m_int ? ANN m_int gwi_enum_ini(const Gwi gwi, const m_str type) { - CHECK_BB(ck_ini(gwi, ck_edef)); + CHECK_b(ck_ini(gwi, ck_edef)); CHECK_OB((gwi->ck->xid = gwi_str2sym(gwi, type))); gwi->ck->tmpl = new_mp_vector(gwi->gwion->mp, EnumValue, 0); return GW_OK; @@ -30,7 +30,7 @@ ANN m_int gwi_enum_ini(const Gwi gwi, const m_str type) { //! \arg name of the entry //! TODO: change return type to m_bool ANN m_int gwi_enum_add(const Gwi gwi, const m_str name, const m_uint i) { - CHECK_BB(ck_ok(gwi, ck_edef)); + CHECK_B(ck_ok(gwi, ck_edef)); DECL_OB(const Symbol, xid, = gwi_str2sym(gwi, name)); const EnumValue ev = { .tag = MK_TAG(xid, gwi->loc), .gwint = { .num = i }, .set = true}; mp_vector_add(gwi->gwion->mp, &gwi->ck->tmpl, EnumValue, ev); @@ -40,7 +40,7 @@ ANN m_int gwi_enum_add(const Gwi gwi, const m_str name, const m_uint i) { //! finish enum import //! \arg the importer ANN Type gwi_enum_end(const Gwi gwi) { - CHECK_BO(ck_ok(gwi, ck_edef)); + CHECK_O(ck_ok(gwi, ck_edef)); if (!gwi->ck->tmpl->len) GWI_ERR_O("Enum is empty"); const Gwion gwion = gwi->gwion; const Enum_Def edef = diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index 21a7d6c1..bf75294c 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -18,9 +18,9 @@ ANN2(1, 2, 3) static m_bool dl_func_init(const Gwi gwi, const restrict m_str t, const restrict m_str n) { - CHECK_BB(ck_ini(gwi, ck_fdef)); + CHECK_b(ck_ini(gwi, ck_fdef)); gwi->ck->name = n; - CHECK_BB(check_typename_def(gwi, gwi->ck)); + CHECK_b(check_typename_def(gwi, gwi->ck)); CHECK_OB((gwi->ck->td = gwi_str2td(gwi, t))); gwi->ck->mpv = new_mp_vector(gwi->gwion->mp, Arg, 0); return GW_OK; @@ -84,7 +84,7 @@ ANN m_int gwi_func_valid(const Gwi gwi, ImportCK *ck) { } ANN m_int gwi_func_end(const Gwi gwi, const f_xfun addr, const ae_flag flag) { - CHECK_BB(ck_ok(gwi, ck_fdef)); + CHECK_b(ck_ok(gwi, ck_fdef)); gwi->ck->addr = addr; gwi->ck->flag = flag; const m_bool ret = gwi_func_valid(gwi, gwi->ck); @@ -94,10 +94,10 @@ ANN m_int gwi_func_end(const Gwi gwi, const f_xfun addr, const ae_flag flag) { ANN m_int gwi_func_arg(const Gwi gwi, const restrict m_str t, const restrict m_str n) { - CHECK_BB(ck_ok(gwi, ck_fdef)); + CHECK_b(ck_ok(gwi, ck_fdef)); DECL_OB(Type_Decl *, td, = gwi_str2td(gwi, t)); struct Var_Decl_ var; - if(gwi_str2var(gwi, &var, n) > 0) { + if(gwi_str2var(gwi, &var, n)) { Arg arg = { .var = MK_VAR(td, var) }; mp_vector_add(gwi->gwion->mp, &gwi->ck->mpv, Arg, arg); return GW_OK; @@ -123,7 +123,7 @@ ANN static m_bool section_fptr(const Gwi gwi, const Fptr_Def fdef) { } ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag) { - CHECK_BO(ck_ok(gwi, ck_fdef)); + CHECK_O(ck_ok(gwi, ck_fdef)); DECL_OO(const Fptr_Def, fptr, = import_fptr(gwi)); fptr->base->flag |= flag; if (gwi->gwion->data->cdoc) { diff --git a/src/import/import_item.c b/src/import/import_item.c index 2f1f73ca..49098f1e 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -12,7 +12,7 @@ ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { - CHECK_BB(ck_ini(gwi, ck_item)); + CHECK_b(ck_ini(gwi, ck_item)); if ((gwi->ck->exp = make_exp(gwi, type, name))) return GW_OK; GWI_ERR_B(_(" ... during var import '%s.%s'."), gwi->gwion->env->name, name) } @@ -30,7 +30,7 @@ ANN static m_int gwi_item_tmpl(const Gwi gwi) { #undef gwi_item_end ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data addr) { - CHECK_BB(ck_ok(gwi, ck_item)); + CHECK_b(ck_ok(gwi, ck_item)); const Env env = gwi->gwion->env; gwi->ck->exp->d.exp_decl.var.td->flag = flag; if (gwi->gwion->data->cdoc) { diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 005fd68a..c2900b5b 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -13,14 +13,14 @@ ANN m_int gwi_typedef_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { - CHECK_BB(ck_ini(gwi, ck_tdef)); + CHECK_b(ck_ini(gwi, ck_tdef)); gwi->ck->name = name; - CHECK_BB(check_typename_def(gwi, gwi->ck)); + CHECK_b(check_typename_def(gwi, gwi->ck)); return (gwi->ck->td = gwi_str2td(gwi, type)) ? GW_OK : GW_ERROR; } ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { - CHECK_BO(ck_ok(gwi, ck_tdef)); + CHECK_O(ck_ok(gwi, ck_tdef)); Type_Decl *td = gwi->ck->td; td->flag |= flag; const Type_Def tdef = diff --git a/src/import/import_udef.c b/src/import/import_udef.c index 28f7bcd7..73194526 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -18,7 +18,7 @@ ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name) { DECL_OO(Type_Decl *, td, = gwi_str2td(gwi, type)); struct Var_Decl_ vd; - if(gwi_str2var(gwi, &vd, name) < 0) { + if(!gwi_str2var(gwi, &vd, name)) { free_type_decl(gwi->gwion->mp, td); return NULL; } @@ -26,16 +26,16 @@ ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name) { } ANN m_int gwi_union_ini(const Gwi gwi, const m_str name) { - CHECK_BB(ck_ini(gwi, ck_udef)); + CHECK_b(ck_ini(gwi, ck_udef)); gwi->ck->name = name; - CHECK_BB(check_typename_def(gwi, gwi->ck)); + CHECK_b(check_typename_def(gwi, gwi->ck)); gwi->ck->mpv = new_mp_vector(gwi->gwion->mp, Variable, 0); return GW_OK; } ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) { - CHECK_BB(ck_ok(gwi, ck_udef)); + CHECK_b(ck_ok(gwi, ck_udef)); DECL_OB(Type_Decl *, td, = str2td(gwi->gwion, type, gwi->loc)); DECL_OB(const Symbol, xid, = str2sym(gwi->gwion, name, gwi->loc)); Variable um = { .td = td, .vd = { .tag = MK_TAG(xid, gwi->loc) } }; @@ -65,7 +65,7 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) { } ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { - CHECK_BO(ck_ok(gwi, ck_udef)); + CHECK_O(ck_ok(gwi, ck_udef)); if (!gwi->ck->mpv->len) GWI_ERR_O(_("union is empty")); const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->ck->mpv, gwi->loc); gwi->ck->list = NULL; diff --git a/src/lib/array.c b/src/lib/array.c index 73efbf16..291468a9 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -413,13 +413,14 @@ ANN static inline m_bool array_do(const Emitter emit, const Array_Sub array, return GW_OK; } -ANN m_bool get_emit_var(const Emitter emit, const Type t, bool is_var) { +ANN bool get_emit_var(const Emitter emit, const Type t, bool is_var) { const Env env = emit->env; bool vars[2] = { is_var }; struct Op_Import opi = {.op = insert_symbol("@array_init"), .lhs = t, .data = (uintptr_t)vars}; - CHECK_BB(op_emit(emit, &opi)); + if(op_emit(emit, &opi) != GW_OK) + return false; return vars[1]; } @@ -1192,7 +1193,14 @@ ANN static bool last_is_zero(Exp* e) { return exp_is_zero(e); } -ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args) { +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + +ANN2(1,2) bool check_array_instance(const Env env, Type_Decl *td, Exp* args) { if (!last_is_zero(td->array->exp)) { if (!args) ERR_B(td->tag.loc, "declaration of abstract type arrays needs lambda"); @@ -1201,5 +1209,5 @@ ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args) { gwerr_warn("array is empty", "no need to provide a lambda", NULL, env->name, td->array->exp->loc); } - return GW_OK; + return true; } diff --git a/src/lib/closure.c b/src/lib/closure.c index d3576976..7209e207 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -537,7 +537,7 @@ static inline void op_impl_ensure_types(const Env env, const Func func) { static OP_EMIT(opem_op_impl) { struct Implicit *impl = (struct Implicit *)data; if(!impl->e->type->info->func->code) - emit_ensure_func(emit, impl->e->type->info->func); + CHECK_b(emit_ensure_func(emit, impl->e->type->info->func)); emit_pushimm(emit, (m_uint)impl->e->type->info->func->code); return emit_fptr_assign(emit, impl->e->type, impl->t); } diff --git a/src/lib/dict.c b/src/lib/dict.c index 9cd68b0a..ceeb72a2 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -359,7 +359,7 @@ if(info->is_var) { emit_add_instr(emit, hmap_grow_dec); const Instr endgrow = emit_add_instr(emit, BranchNeqInt); CHECK_BB(emit_exp(emit, call.d.exp_call.func)); - CHECK_BB(emit_exp_call1(emit, call.d.exp_call.func->type->info->func, + CHECK_b(emit_exp_call1(emit, call.d.exp_call.func->type->info->func, call.d.exp_call.func->type->info->func->def->base->ret_type->size, true)); emit_add_instr(emit, hmap_find); const Instr regrow = emit_add_instr(emit, BranchEqInt); diff --git a/src/lib/instr.c b/src/lib/instr.c index 6ad98c81..d06bcc74 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -26,7 +26,7 @@ ANN static Func_Def traverse_tmpl(const Emitter emit, Func_Def fdef, Func_Def fb const Func_Def def = cpy_func_def(env->gwion->mp, v->d.func_ref->def); if (vflag(v, vflag_builtin)) v->d.func_ref->def->d.dl_func_ptr = xfun; def->base->tmpl->call = cpy_tmplarg_list(env->gwion->mp, fbase->base->tmpl->call); - CHECK_BO(traverse_dot_tmpl(emit, def, v)); + CHECK_O(traverse_dot_tmpl(emit, def, v)); if (vflag(v, vflag_builtin)) builtin_func(emit->gwion, def->base->func, xfun); return def; } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 4c7399da..da4ce296 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -237,8 +237,6 @@ OP_EMIT(opem_object_dot) { const Exp_Dot *member = (Exp_Dot *)data; const Type t_base = member_type(emit->gwion, member->base->type); const Value value = find_value(t_base, member->xid); -// if(!tflag(t_base, tflag_emit) /*&& emit->env->class_def != t_base*/) -// ensure_emit(emit, t_base); if (is_class(emit->gwion, value->type)) { emit_pushimm(emit, (m_uint)value->type); return GW_OK; diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 13df8d00..1c4fbbf7 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -124,7 +124,7 @@ OP_CHECK(opck_new) { if(GET_FLAG(base, abstract)) CHECK_ON(abstract_array(env, array)); if(GET_FLAG(base, abstract)) - CHECK_BN(check_array_instance(env, unary->ctor.td, unary->ctor.exp)); + CHECK_ON(check_array_instance(env, unary->ctor.td, unary->ctor.exp)); } CHECK_ON(ensure_traverse(env, t)); if (type_ref(t)) @@ -160,7 +160,7 @@ OP_CHECK(opck_new) { OP_EMIT(opem_new) { const Exp_Unary *unary = (Exp_Unary *)data; if(!tflag(exp_self(unary)->type, tflag_struct)) - CHECK_BB(emit_instantiate_object(emit, exp_self(unary)->type, + CHECK_b(emit_instantiate_object(emit, exp_self(unary)->type, unary->ctor.td->array, 0)); if(!unary->ctor.exp) emit_local_exp(emit, exp_self(unary)); diff --git a/src/lib/xork.c b/src/lib/xork.c index 037ddccd..730e3340 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -80,7 +80,7 @@ static OP_CHECK(opck_spork) { static OP_EMIT(opem_spork) { const Exp_Unary *unary = (Exp_Unary *)data; - return emit_exp_spork(emit, unary); + return emit_exp_spork(emit, unary) ? GW_OK : GW_ERROR; } static FREEARG(freearg_xork) { vmcode_remref((VM_Code)instr->m_val, gwion); } diff --git a/src/parse/check.c b/src/parse/check.c index 8f54734a..033bffbc 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1384,12 +1384,12 @@ ANN bool check_enum_def(const Env env, const Enum_Def edef) { } ANN static bool check_stmt_code(const Env env, const Stmt_Code stmt) { - if (stmt->stmt_list) { RET_NSPC_B(check_stmt_list(env, stmt->stmt_list)) } + if (stmt->stmt_list) { RET_NSPC(check_stmt_list(env, stmt->stmt_list)) } return true; } ANN static inline bool _check_breaks(const Env env, Stmt* b) { - RET_NSPC_B(check_stmt(env, b))} + RET_NSPC(check_stmt(env, b))} ANN static bool check_breaks(const Env env, Stmt* a, Stmt* b) { vector_add(&env->scope->breaks, (vtype)a); @@ -1476,7 +1476,7 @@ ANN static inline bool repeat_type(const Env env, Exp* e) { } #define stmt_func_xxx(name, type, prolog, exp) \ - describe_stmt_func_b(check, name, type, prolog, exp) + describe_stmt_func(check, name, type, prolog, exp) stmt_func_xxx(if, Stmt_If,, !(!check_flow(env, stmt->cond) || !check_stmt(env, stmt->if_body) || (stmt->else_body && !check_stmt(env, stmt->else_body))) ? true : false) @@ -1639,7 +1639,7 @@ ANN static bool _check_stmt_case(const Env env, const Stmt_Match stmt) { } ANN static bool check_stmt_case(const Env env, const Stmt_Match stmt) { - RET_NSPC_B(_check_stmt_case(env, stmt))} + RET_NSPC(_check_stmt_case(env, stmt))} ANN static bool case_loop(const Env env, const Stmt_Match stmt) { bool ok = true; @@ -1653,7 +1653,7 @@ ANN static bool case_loop(const Env env, const Stmt_Match stmt) { ANN static inline bool check_handler(const restrict Env env, const Handler *handler) { - RET_NSPC_B(check_stmt(env, handler->stmt)); + RET_NSPC(check_stmt(env, handler->stmt)); } ANN static inline bool check_handler_list(const restrict Env env, @@ -1681,7 +1681,7 @@ ANN static inline bool find_handler(const Handler_List handlers, const Symbol xi ANN static inline bool check_stmt_try_start(const restrict Env env, const Stmt_Try stmt) { - RET_NSPC_B(check_stmt(env, stmt->stmt)) + RET_NSPC(check_stmt(env, stmt->stmt)) } ANN static inline bool check_stmt_try(const restrict Env env, const Stmt_Try stmt) { @@ -1710,11 +1710,11 @@ ANN static bool _check_stmt_match(const Env env, const Stmt_Match stmt) { ANN static inline bool handle_where(const Env env, const Stmt_Match stmt) { if (stmt->where) CHECK_B(check_stmt(env, stmt->where)); - RET_NSPC_B(_check_stmt_match(env, stmt)) + RET_NSPC(_check_stmt_match(env, stmt)) } ANN static bool check_stmt_match(const Env env, const Stmt_Match stmt) { - RET_NSPC_B(handle_where(env, stmt)) + RET_NSPC(handle_where(env, stmt)) } #define check_stmt_while check_stmt_flow @@ -2081,7 +2081,7 @@ ANN static bool _check_trait_def(const Env env, const Trait_Def pdef) { } ANN static bool check_trait_def(const Env env, const Trait_Def pdef) { - RET_NSPC_B(_check_trait_def(env, pdef)); + RET_NSPC(_check_trait_def(env, pdef)); } ANN bool check_fptr_def(const Env env, const Fptr_Def fptr) { diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 862dc557..e5284d0b 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -269,7 +269,7 @@ ANN static inline bool _scan1_stmt_match_case(const restrict Env env, ANN static inline bool scan1_stmt_match_case(const restrict Env env, const Stmt_Match stmt) { - RET_NSPC_B(_scan1_stmt_match_case(env, stmt))} + RET_NSPC(_scan1_stmt_match_case(env, stmt))} ANN static inline bool _scan1_stmt_match(const restrict Env env, const Stmt_Match stmt) { @@ -287,12 +287,12 @@ ANN static inline bool ANN static inline bool scan1_stmt_match(const restrict Env env, const Stmt_Match stmt) { CHECK_B(scan1_exp(env, stmt->cond)); - RET_NSPC_B(_scan1_stmt_match(env, stmt)) + RET_NSPC(_scan1_stmt_match(env, stmt)) } ANN static inline bool scan1_handler(const restrict Env env, const Handler *handler) { - RET_NSPC_B(scan1_stmt(env, handler->stmt)); + RET_NSPC(scan1_stmt(env, handler->stmt)); } ANN static inline bool scan1_handler_list(const restrict Env env, @@ -309,7 +309,7 @@ ANN static inline bool scan1_handler_list(const restrict Env env, ANN static inline bool scan1_stmt_try(const restrict Env env, const Stmt_Try stmt) { CHECK_B(scan1_handler_list(env, stmt->handler)); - RET_NSPC_B(scan1_stmt(env, stmt->stmt)) + RET_NSPC(scan1_stmt(env, stmt->stmt)) } ANN static inline bool stmt_each_defined(const restrict Env env, @@ -354,7 +354,7 @@ ANN static inline bool shadow_var(const Env env, const Tag tag){ } #define describe_ret_nspc(name, type, prolog, exp) \ - describe_stmt_func_b(scan1, name, type, prolog, exp) + describe_stmt_func(scan1, name, type, prolog, exp) describe_ret_nspc(flow, Stmt_Flow,, !(!scan1_exp(env, stmt->cond) || !scan1_stmt(env, stmt->body)) ? true : false) describe_ret_nspc(for, Stmt_For,, !(!scan1_stmt(env, stmt->c1) || @@ -391,12 +391,12 @@ ANN static inline bool _scan1_stmt_if(const Env env, const Stmt_If stmt) { } ANN static inline bool scan1_stmt_if(const Env env, const Stmt_If stmt) { - RET_NSPC_B(_scan1_stmt_if(env, stmt)); + RET_NSPC(_scan1_stmt_if(env, stmt)); return true; } ANN static inline bool scan1_stmt_code(const Env env, const Stmt_Code stmt) { - if (stmt->stmt_list) { RET_NSPC_B(scan1_stmt_list(env, stmt->stmt_list)) } + if (stmt->stmt_list) { RET_NSPC(scan1_stmt_list(env, stmt->stmt_list)) } return true; } @@ -732,7 +732,7 @@ ANN bool scan1_fdef(const Env env, const Func_Def fdef) { else if (fbflag(fdef->base, fbflag_op) && env->class_def) SET_FLAG(fdef->base, static); if(!is_ctor(fdef)) { - RET_NSPC_B(scan1_fbody(env, fdef)) + RET_NSPC(scan1_fbody(env, fdef)) } else if(!fdef->builtin) CHECK_B(scan1_stmt_list(env, fdef->d.code)); return true; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 695c35d1..a0ecf0f2 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -176,7 +176,7 @@ ANN static inline bool _scan2_stmt_match_case(const restrict Env env, ANN static inline bool scan2_stmt_match_case(const restrict Env env, const Stmt_Match stmt) { - RET_NSPC_B(_scan2_stmt_match_case(env, stmt))} + RET_NSPC(_scan2_stmt_match_case(env, stmt))} ANN static inline bool _scan2_stmt_match(const restrict Env env, const Stmt_Match stmt) { @@ -193,7 +193,7 @@ ANN static inline bool ANN static inline bool scan2_handler(const restrict Env env, const Handler *handler) { - RET_NSPC_B(scan2_stmt(env, handler->stmt)); + RET_NSPC(scan2_stmt(env, handler->stmt)); } ANN static inline bool scan2_handler_list(const restrict Env env, @@ -210,13 +210,13 @@ ANN static inline bool scan2_handler_list(const restrict Env env, ANN static inline bool scan2_stmt_try(const restrict Env env, const Stmt_Try stmt) { CHECK_B(scan2_handler_list(env, stmt->handler)); - RET_NSPC_B(scan2_stmt(env, stmt->stmt)) + RET_NSPC(scan2_stmt(env, stmt->stmt)) } ANN static inline bool scan2_stmt_match(const restrict Env env, const Stmt_Match stmt) { CHECK_B(scan2_exp(env, stmt->cond)); - RET_NSPC_B(_scan2_stmt_match(env, stmt)) + RET_NSPC(_scan2_stmt_match(env, stmt)) } #define scan2_exp_lambda bdummy_func @@ -224,7 +224,7 @@ ANN static inline bool scan2_stmt_match(const restrict Env env, HANDLE_EXP_FUNC_B(scan2, bool, Env) #define scan2_stmt_func(name, type, prolog, exp) \ - describe_stmt_func_b(scan2, name, type, prolog, exp) + describe_stmt_func(scan2, name, type, prolog, exp) scan2_stmt_func(flow, Stmt_Flow,, !(!scan2_exp(env, stmt->cond) || !scan2_stmt(env, stmt->body)) ? true : false) scan2_stmt_func(for, Stmt_For,, !(!scan2_stmt(env, stmt->c1) || @@ -240,7 +240,7 @@ scan2_stmt_func(if, Stmt_If,, !(!scan2_exp(env, stmt->cond) || (stmt->else_body && !scan2_stmt(env, stmt->else_body))) ? true : false) ANN static inline bool scan2_stmt_code(const Env env, const Stmt_Code stmt) { - if (stmt->stmt_list) { RET_NSPC_B(scan2_stmt_list(env, stmt->stmt_list)) } + if (stmt->stmt_list) { RET_NSPC(scan2_stmt_list(env, stmt->stmt_list)) } return true; } diff --git a/src/parse/scanx.c b/src/parse/scanx.c index c3eab3cc..30e45a44 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -6,7 +6,7 @@ #include "traverse.h" #include "parse.h" -ANN static inline bool _body(const Env e, Ast b, const _exp_func f) { +ANN static inline bool _body(const Env e, Ast b, const _envset_func f) { for(m_uint i = 0; i < b->len; i++) { Section *section = mp_vector_at(b, Section, i); CHECK_B(f(e, section)); diff --git a/src/pass.c b/src/pass.c index bcf6a57f..f050c0d1 100644 --- a/src/pass.c +++ b/src/pass.c @@ -28,7 +28,7 @@ ANN void pass_register(const Gwion gwion, const m_str name, map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass); } -ANN m_bool pass_set(const Gwion gwion, const Vector passes) { +ANN bool pass_set(const Gwion gwion, const Vector passes) { const Vector v = &gwion->data->passes->vec; vector_clear(v); for (m_uint i = 0; i < vector_size(passes); ++i) { @@ -45,11 +45,11 @@ if(!strcmp(name, "none")) { */ gw_err("Failed to set compilation passes, back to default\n"); pass_default(gwion); - return GW_ERROR; + return false; } vector_add(v, (vtype)pass); } - return GW_OK; + return true; } ANN void pass_default(const Gwion gwion) { -- 2.43.0