From fecfc13df586e9f444e39878641934aff959f6e5 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 12 Feb 2024 03:37:05 +0100 Subject: [PATCH] :art: init poisoning This reverts commit e1ccc6791f9918e7ad4120e93617b9f8c191a0ad. --- include/array.h | 2 +- include/constant.h | 5 + include/emit.h | 22 ++-- include/env/env.h | 34 +++--- include/env/envset.h | 13 +- include/env/func.h | 2 +- include/env/type.h | 2 +- include/import.h | 2 +- include/import/checker.h | 2 +- include/instr.h | 2 +- include/operator.h | 16 +-- include/parse.h | 127 +++++++++++--------- include/pass.h | 2 +- include/template.h | 2 +- include/tmp_resolve.h | 2 +- include/traverse.h | 64 +++++----- src/emit/emit.c | 2 +- src/env/env_utils.c | 28 ++--- src/env/envset.c | 2 +- src/gwion.c | 2 +- src/import/import_cdef.c | 2 +- src/import/import_prim.c | 4 +- src/import/import_udef.c | 2 +- src/lib/array.c | 4 +- src/lib/dict.c | 2 +- src/lib/object_op.c | 8 +- src/parse/check.c | 12 +- src/parse/func_resolve_tmpl.c | 4 +- src/parse/scan0.c | 217 +++++++++++++++++++--------------- src/parse/scan1.c | 19 +-- src/parse/scan2.c | 8 +- src/parse/scanx.c | 20 +++- src/parse/spread.c | 18 +-- src/parse/template.c | 26 ++-- src/parse/traverse.c | 10 +- src/parse/type_decl.c | 2 +- src/pass.c | 9 +- 37 files changed, 396 insertions(+), 304 deletions(-) create mode 100644 include/constant.h diff --git a/include/array.h b/include/array.h index ef0cbc7f..8399785e 100644 --- a/include/array.h +++ b/include/array.h @@ -20,7 +20,7 @@ typedef struct ArrayInfo_ { } ArrayInfo; ANN Type check_array_access(const Env env, const Array_Sub array); -ANN bool emit_array_access(const Emitter emit, +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); #endif diff --git a/include/constant.h b/include/constant.h new file mode 100644 index 00000000..26113041 --- /dev/null +++ b/include/constant.h @@ -0,0 +1,5 @@ +#ifndef __CONSTANT +#define __CONSTANT +ANN m_bool constant_int(Exp* e); +ANN m_bool constant_float(Exp* e); +#endif diff --git a/include/emit.h b/include/emit.h index 75a79a48..030621f4 100644 --- a/include/emit.h +++ b/include/emit.h @@ -64,25 +64,25 @@ struct Emitter_ { ANEW ANN Emitter new_emitter(MemPool); ANN void free_emitter(MemPool, Emitter); -ANN bool emit_ast(const Env env, Ast *ast); -ANN bool emit_func_def(const Emitter emit, const Func_Def fdef); -ANN bool emit_exp_call1(const Emitter, const Func, const m_uint size, const bool is_static); +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); 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 bool emit_array_extend(const Emitter, const Type, Exp*); +ANN m_bool emit_array_extend(const Emitter, const Type, Exp*); ANN void emit_class_finish(const Emitter, const Nspc); ANN2(1, 2) -bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, - const bool); +m_bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, + const m_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 bool emit_exp_spork(const Emitter, const Exp_Unary *); -ANN bool emit_exp(const Emitter, Exp*); +ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *); +ANN m_bool emit_exp(const Emitter, Exp*); ANN void emit_object_addref(const Emitter emit, const m_int size, const bool emit_var); @@ -90,7 +90,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 bool emit_var) { + const m_bool emit_var) { return !tflag(t, tflag_struct) ? emit_object_addref(emit, size, emit_var) : emit_struct_addref(emit, t, size, emit_var); } @@ -113,8 +113,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 bool ensure_emit(const Emitter, const Type); -ANN bool emit_ensure_func(const Emitter emit, const Func f); +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 static inline void emit_regmove(const Emitter emit, const m_uint i) { diff --git a/include/env/env.h b/include/env/env.h index 7ac00faf..d7e245c5 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -26,7 +26,7 @@ struct Env_Scope_ { bool in_try; bool in_loop; bool shadowing; - bool poison; + bool poison; // move me }; typedef struct Env_ { @@ -47,23 +47,23 @@ ANN2(1, 3) m_uint env_push(const Env, const Type, const Nspc); ANN static inline m_uint env_push_global(const Env env) { return env_push(env, NULL, env->global_nspc); } -ANN void env_pop(const Env, const m_uint); -ANN Type scan_type(const Env, const Type, Type_Decl *); -ANN Value mk_class(const Env env, const Type base, const loc_t); -ANN bool compat_func(const __restrict__ Func_Def, +ANN void env_pop(const Env, const m_uint); +ANN Type scan_type(const Env, const Type, Type_Decl *); +ANN Value mk_class(const Env env, const Type base, const loc_t); +ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); -ANN Type known_type(const Env env, Type_Decl *); -ANN Type prim_ref(const Env env, const Type t, const Type_Decl *td); -ANN bool env_access(const Env env, const ae_flag flag, const loc_t); -ANN bool env_storage(const Env env, ae_flag flag, const loc_t); -ANN void env_add_type(const Env, const Type, const loc_t); -ANN Type find_type(const Env, Type_Decl *); -ANN bool traverse_func_template(const Env, const Func_Def); -ANN void env_err(const Env, const loc_t, const m_str fmt, ...); -ANN void env_warn(const Env, const loc_t, const m_str fmt, ...); -ANN void env_error_footer(const Env env); -ANN Value global_string(const Env env, const m_str str, const loc_t); -ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion); +ANN Type known_type(const Env env, Type_Decl *); +ANN Type prim_ref(const Env env, const Type t, const Type_Decl *td); +ANN bool env_access(const Env env, const ae_flag flag, const loc_t); +ANN bool env_storage(const Env env, ae_flag flag, const loc_t); +ANN void env_add_type(const Env, const Type, const loc_t); +ANN Type find_type(const Env, Type_Decl *); +ANN m_bool traverse_func_template(const Env, const Func_Def); +ANN void env_err(const Env, const loc_t, const m_str fmt, ...); +ANN void env_warn(const Env, const loc_t, const m_str fmt, ...); +ANN void env_error_footer(const Env env); +ANN Value global_string(const Env env, const m_str str, const loc_t); +ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion); struct ScopeEffect { Symbol sym; diff --git a/include/env/envset.h b/include/env/envset.h index cdd1f23f..dc6db789 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -1,8 +1,7 @@ #ifndef __ENVSET #define __ENVSET -// couldbe _exp_func -typedef bool (*envset_func)(const void *, const void *); +typedef m_bool (*envset_func)(const void *, const void *); struct EnvSet { const Env env; const envset_func func; @@ -14,13 +13,13 @@ struct EnvSet { bool run; }; -ANN bool envset_run(struct EnvSet *, const Type); -ANN2(1, 3) bool envset_push(struct EnvSet *, const Type, const Nspc); -ANN static inline bool envset_pushv(struct EnvSet *es, const Value v) { +ANN m_bool envset_run(struct EnvSet *, const Type); +ANN2(1, 3) m_bool envset_push(struct EnvSet *, const Type, const Nspc); +ANN static inline m_bool envset_pushv(struct EnvSet *es, const Value v) { es->_ctx = es->env->context; es->_filename = es->env->name; - CHECK_B(envset_push(es, v->from->owner_class, v->from->owner)); - return true; + CHECK_BB(envset_push(es, v->from->owner_class, v->from->owner)); + return GW_OK; } ANN2(1) void envset_pop(struct EnvSet *, const Type); #endif diff --git a/include/env/func.h b/include/env/func.h index e4495e73..cd90ee93 100644 --- a/include/env/func.h +++ b/include/env/func.h @@ -33,7 +33,7 @@ ANEW ANN Func new_func(MemPool, const m_str, const Func_Def); ANN2(1, 2) Symbol func_symbol(const Env, const m_str, const m_str, const m_str, const m_uint); -ANN bool check_lambda(const Env, const Type, Exp_Lambda *); +ANN m_bool check_lambda(const Env, const Type, Exp_Lambda *); ANN Type check_op_call(const Env env, Exp_Call *const exp); ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr); diff --git a/include/env/type.h b/include/env/type.h index 4045a098..aa3b5857 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -67,7 +67,7 @@ ANN2(1, 2) ANEW Type new_type(MemPool, const m_str name, const Type); ANEW ANN Type type_copy(MemPool, const Type type); ANN Value find_value(const Type, const Symbol); ANN m_bool isa(const Type, const Type) __attribute__((pure)); -ANN bool isres(const Env, const Tag); +ANN bool isres(const Env, const Tag); // move me ANN Type array_type(const Env, const Type, const m_uint, const loc_t); ANN Type find_common_anc(const Type, const Type) __attribute__((pure)); ANN Type array_base(Type) __attribute__((pure)); diff --git a/include/import.h b/include/import.h index 0a6242ff..b3f85b5b 100644 --- a/include/import.h +++ b/include/import.h @@ -25,7 +25,7 @@ typedef struct Gwi_ *Gwi; void a(const Type t NUSED, m_bit *const VALUE NUSED, \ const VM_Shred shred NUSED) #define OP_CHECK(a) ANN Type a(const Env env NUSED, void *data NUSED) -#define OP_EMIT(a) ANN bool a(const Emitter emit NUSED, void *data NUSED) +#define OP_EMIT(a) ANN m_bool a(const Emitter emit NUSED, void *data NUSED) #ifdef GWION_BUILTIN #define GWI_BB(a) \ { \ diff --git a/include/import/checker.h b/include/import/checker.h index d73b576f..6bb44b03 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -33,7 +33,7 @@ typedef struct OperCK { // name_checker ? m_str ret; Symbol sym; Type (*ck)(Env, void *); // oper - bool (*em)(Emitter, void *); // oper + m_bool (*em)(Emitter, void *); // oper m_str lhs; // oper m_str rhs; // oper struct Vector_ effect; diff --git a/include/instr.h b/include/instr.h index 3be97ae2..25724cf7 100644 --- a/include/instr.h +++ b/include/instr.h @@ -65,7 +65,7 @@ struct dottmpl_ { Type type; m_str tmpl_name; }; -ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v); +ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value v); INSTR(SetFunc); INSTR(FuncWait); diff --git a/include/operator.h b/include/operator.h index a5591e74..1cebd8a4 100644 --- a/include/operator.h +++ b/include/operator.h @@ -44,7 +44,7 @@ } while (0) typedef Type (*opck)(const Env, void *); -typedef bool (*opem)(const Emitter, void *); +typedef m_bool (*opem)(const Emitter, void *); struct Op_Func { opck ck; @@ -77,13 +77,13 @@ struct TemplateScan { }; ANN void op_cpy(const Env env, const struct Op_Import *opi); -ANN bool add_op(const Gwion gwion, const struct Op_Import *); +ANN m_bool add_op(const Gwion gwion, const struct Op_Import *); ANN void* op_get(const Env env, struct Op_Import *opi); -ANN Type op_check(const Env, struct Op_Import *); -ANN bool op_emit(const Emitter, const struct Op_Import *); -ANN bool operator_set_func(const struct Op_Import *); -ANN void free_op_map(Map map, struct Gwion_ *gwion); -ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); +ANN Type op_check(const Env, struct Op_Import *); +ANN m_bool op_emit(const Emitter, const struct Op_Import *); +ANN m_bool operator_set_func(const struct Op_Import *); +ANN void free_op_map(Map map, struct Gwion_ *gwion); +ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); ANN void operator_suspend(const Nspc, struct Op_Import *); ANN static inline void operator_resume(struct Op_Import *opi) { @@ -97,5 +97,5 @@ ANN static inline void set_decl_ref(Exp* e) { } ANN void func_operator(const Func_Def fdef, struct Op_Import *opi); -ANN bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx); +ANN m_bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx); #endif diff --git a/include/parse.h b/include/parse.h index bad8dbb8..7a9feb87 100644 --- a/include/parse.h +++ b/include/parse.h @@ -4,11 +4,25 @@ #include "gwion.h" #define insert_symbol(a) insert_symbol(env->gwion->st, (a)) +#undef ERR_b +#define ERR_b(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + + +#define ERR_OK(ok, a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + ok = false; \ + } + #undef ERR_B #define ERR_B(a, b, ...) \ { \ env_err(env, (a), (b), ##__VA_ARGS__); \ - return false; \ + return GW_ERROR; \ } #undef ERR_O @@ -21,7 +35,7 @@ #define RET_NSPC(exp) \ ++env->scope->depth; \ nspc_push_value(env->gwion->mp, env->curr); \ - const bool ret = exp; \ + const m_bool ret = exp; \ nspc_pop_value(env->gwion->mp, env->curr); \ --env->scope->depth; \ return ret; @@ -41,62 +55,88 @@ } #define HANDLE_EXP_FUNC(prefix, type, Arg) \ + DECL_EXP_FUNC(prefix, type, Arg) \ + ANN type prefix##_exp(const Arg arg, Exp* exp) { \ + do CHECK_BB(prefix##_exp_func[exp->exp_type](arg, &exp->d)); \ + while ((exp = exp->next)); \ + return GW_OK; \ + } + +#define HANDLE_EXP_FUNC_B(prefix, type, Arg) \ DECL_EXP_FUNC(prefix, type, Arg) \ ANN type prefix##_exp(const Arg arg, Exp* exp) { \ - bool ok = true; \ do { \ - if(exp->poison) continue; \ - if(!prefix##_exp_func[exp->exp_type](arg, &exp->d)) { \ - prefix##_poison(arg, exp); \ - ok = false; \ + if(!exp->poison) { \ + if(!prefix##_exp_func[exp->exp_type](arg, &exp->d)); \ + exp->poison = true; \ } \ } while ((exp = exp->next)); \ - return ok; \ + return GW_OK; \ } -ANN static inline void scanx_poison(const Env env, Exp *e) { - env->scope->poison = true; - e->poison = true; -} - #define describe_stmt_func(prefix, name, type, prolog, exp) \ - ANN static bool prefix##_stmt_##name(const Env env, const type stmt) { \ + ANN static m_bool prefix##_stmt_##name(const Env env, const type stmt) { \ RET_NSPC(exp) \ } -ANN bool check_stmt(const Env env, Stmt* stmt); // neeeded??? -ANN bool check_stmt_list(const Env env, const Stmt_List); +ANN m_bool check_stmt(const Env env, Stmt* stmt); +ANN m_bool check_stmt_list(const Env env, const Stmt_List); -typedef bool (*_exp_func)(const void *, const void *); -ANN bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, +typedef m_bool (*_exp_func)(const void *, const void *); +ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, void *data); -static inline ANN bool env_body(const Env env, const Class_Def cdef, +static inline ANN m_bool env_body(const Env env, const Class_Def cdef, const _exp_func f) { return scanx_body(env, cdef, f, env); } #define env_body(a, b, c) env_body(a, b, (_exp_func)c) -ANN bool scanx_cdef(const Env, void *, const Type, const _exp_func f_cdef, +typedef bool (*_exp_func_b)(const void *, const void *); +ANN bool scanx_body_b(const Env env, const Class_Def cdef, const _exp_func_b f, + void *data); +static inline ANN bool env_body_b(const Env env, const Class_Def cdef, + const _exp_func_b f) { + return scanx_body_b(env, cdef, f, env); +} +#define env_body_b(a, b, c) env_body_b(a, b, (_exp_func_b)c) + +ANN m_bool scanx_cdef(const Env, void *, const Type, const _exp_func f_cdef, const _exp_func f_union); +#define xxx_section_b(prefix) \ +static inline m_bool prefix##_section_b(const Env env, Section *section) { \ + return prefix##_section(env, section) ? GW_OK : GW_ERROR;} + +#define xxx_cdef_b(prefix) \ +static inline m_bool prefix##_class_def_b(const Env env, const Class_Def cdef) { \ + return prefix##_class_def(env, cdef) ? GW_OK : GW_ERROR;} \ +static inline m_bool prefix##_union_def_b(const Env env, const Union_Def udef) { \ + return prefix##_union_def(env, udef) ? GW_OK : GW_ERROR;} \ + static inline m_bool prefix##_cdef(const Env env, const Type t) { \ + return scanx_cdef(env, env, t, (_exp_func)prefix##_class_def_b, \ + (_exp_func)prefix##_union_def_b); \ + } + +xxx_cdef_b(scan0) + #define xxx_cdef(prefix) \ - static inline bool prefix##_cdef(const Env env, const Type t) { \ + static inline m_bool prefix##_cdef(const Env env, const Type t) { \ return scanx_cdef(env, env, t, (_exp_func)prefix##_class_def, \ (_exp_func)prefix##_union_def); \ } -xxx_cdef(scan0); -xxx_cdef(scan1); -xxx_cdef(scan2); -xxx_cdef(check); -xxx_cdef(traverse); +xxx_cdef(scan1) +xxx_cdef(scan2) +xxx_cdef(check) +xxx_cdef(traverse) -ANN bool scanx_fdef(const Env, void *, const Func_Def, const _exp_func); + ANN m_bool + scanx_fdef(const Env, void *, const Func_Def, const _exp_func); -ANN bool check_subscripts(const Env, const Array_Sub, const bool is_decl); -ANN bool check_implicit(const Env env, Exp* e, const Type t); -ANN bool ensure_traverse(const Env env, const Type t); -ANN bool check_traverse_fdef(const Env env, const Func_Def fdef); +ANN m_bool check_subscripts(const Env, const Array_Sub, const m_bool is_decl); +ANN m_bool check_implicit(const Env env, Exp* e, const Type t); +ANN m_bool ensure_traverse(const Env env, const Type t); +ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef); ANN static inline void env_weight(const Env env, const uint16_t weight) { if (env->func) @@ -134,7 +174,7 @@ ANN static inline bool not_upvalue(const Env env, const Value v) { nspc_lookup_value1(env->curr, insert_symbol(v->name)); } -ANN bool abstract_array(const Env env, const Array_Sub array); +ANN m_bool abstract_array(const Env env, const Array_Sub array); ANN static inline bool is_static_call(const Gwion gwion, Exp* e) { if (e->exp_type != ae_exp_dot) return true; @@ -146,28 +186,5 @@ ANN static inline bool is_static_call(const Gwion gwion, Exp* e) { member->base->exp_type == ae_exp_cast; } - -ANN bool template_push_types(const Env, const Tmpl *); -static inline bool scanx_actual_tmpl(const Tmpl *tmpl) { - return tmpl && tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list; -} - -ANN static inline bool scanx_tmpl_push(const Env env, const Tmpl *tmpl) { - return scanx_actual_tmpl(tmpl) ? template_push_types(env, tmpl): false; -} - -ANN static inline m_int scanx_push(const Env env, const Class_Def c) { - const m_int scope = env_push_type(env, c->base.type); - if(scope < 0) return -1; - return (!c->base.tmpl || scanx_tmpl_push(env, c->base.tmpl)) ? scope : -1; -} - -ANN static inline void scanx_pop(const Env e, const Class_Def c, const m_uint s) { - if (scanx_actual_tmpl(c->base.tmpl)) - nspc_pop_type(e->gwion->mp, e->curr); - env_pop(e, s); -} - - #define is_new(a) !strcmp(s_name((a)->base->tag.sym), "new") #endif diff --git a/include/pass.h b/include/pass.h index ccb486b0..db978889 100644 --- a/include/pass.h +++ b/include/pass.h @@ -6,7 +6,7 @@ struct Passes_ { struct Vector_ vec; }; // change this to gwion ? -typedef bool (*compilation_pass)(const Env, Ast*); +typedef m_bool (*compilation_pass)(const Env, Ast*); ANEW ANN struct Passes_ *new_passes(const Gwion); ANN void free_passes(MemPool mp, struct Passes_ *); diff --git a/include/template.h b/include/template.h index b4e4dc74..d15e4600 100644 --- a/include/template.h +++ b/include/template.h @@ -27,5 +27,5 @@ ANN static inline Tmpl* get_tmpl(const Type t) { return (a); \ } -ANN bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ); +ANN m_bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ); #endif diff --git a/include/tmp_resolve.h b/include/tmp_resolve.h index 0aebd6d7..f88e75b2 100644 --- a/include/tmp_resolve.h +++ b/include/tmp_resolve.h @@ -3,5 +3,5 @@ ANN Func find_template_match(const Env env, const Value value, Exp_Call *const exp); ANN Func find_func_match(const Env env, const Func up, Exp_Call *const exp); -ANN2(1,2) bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread); +ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread); #endif diff --git a/include/traverse.h b/include/traverse.h index dede5914..d39ac62c 100644 --- a/include/traverse.h +++ b/include/traverse.h @@ -1,52 +1,52 @@ #ifndef __TRAVERSE #define __TRAVERSE -ANN bool traverse_ast(const Env, Ast *const); -ANN bool traverse_class_def(const Env, const Class_Def); -ANN bool traverse_func_def(const Env, const Func_Def); -ANN bool traverse_union_def(const Env, const Union_Def); -ANN bool traverse_enum_def(const Env, const Enum_Def); -ANN bool traverse_fptr_def(const Env, const Fptr_Def); -ANN bool traverse_type_def(const Env env, const Type_Def); -ANN bool traverse_exp(const Env, Exp*); +ANN m_bool traverse_ast(const Env, Ast *const); +ANN m_bool traverse_class_def(const Env, const Class_Def); +ANN m_bool traverse_func_def(const Env, const Func_Def); +ANN m_bool traverse_union_def(const Env, const Union_Def); +ANN m_bool traverse_enum_def(const Env, const Enum_Def); +ANN m_bool traverse_fptr_def(const Env, const Fptr_Def); +ANN m_bool traverse_type_def(const Env env, const Type_Def); +ANN m_bool traverse_exp(const Env, Exp*); ANN bool scan0_ast(const Env, Ast*); -ANN bool scan1_ast(const Env, Ast*); -ANN bool scan2_ast(const Env, Ast*); -ANN bool check_ast(const Env, Ast*); +ANN m_bool scan1_ast(const Env, Ast*); +ANN m_bool scan2_ast(const Env, Ast*); +ANN m_bool check_ast(const Env, Ast*); -ANN bool scan1_exp(const Env, Exp*); -ANN bool scan2_exp(const Env, Exp*); -ANN Type check_exp(const Env, Exp*); +ANN m_bool scan1_exp(const Env, Exp*); +ANN m_bool scan2_exp(const Env, Exp*); +ANN Type check_exp(const Env, Exp*); ANN bool scan0_func_def(const Env, const Func_Def); -ANN bool scan1_func_def(const Env, const Func_Def); -ANN bool scan2_func_def(const Env, const Func_Def); -ANN bool check_func_def(const Env, const Func_Def); +ANN m_bool scan1_func_def(const Env, const Func_Def); +ANN m_bool scan2_func_def(const Env, const Func_Def); +ANN m_bool check_func_def(const Env, const Func_Def); ANN bool scan0_fptr_def(const Env, const Fptr_Def); -ANN bool scan1_fptr_def(const Env, const Fptr_Def); -ANN bool scan2_fptr_def(const Env, const Fptr_Def); -ANN bool check_fptr_def(const Env, const Fptr_Def); +ANN m_bool scan1_fptr_def(const Env, const Fptr_Def); +ANN m_bool scan2_fptr_def(const Env, const Fptr_Def); +ANN m_bool check_fptr_def(const Env, const Fptr_Def); ANN bool scan0_union_def(const Env, const Union_Def); -ANN bool scan1_union_def(const Env, const Union_Def); -ANN bool scan2_union_def(const Env, const Union_Def); -ANN bool check_union_def(const Env, const Union_Def); +ANN m_bool scan1_union_def(const Env, const Union_Def); +ANN m_bool scan2_union_def(const Env, const Union_Def); +ANN m_bool check_union_def(const Env, const Union_Def); ANN bool scan0_enum_def(const Env, const Enum_Def); -ANN bool scan1_enum_def(const Env, const Enum_Def); -// ANN bool scan2_enum_def(const Env, const Enum_Def); -ANN bool check_enum_def(const Env, const Enum_Def); +ANN m_bool scan1_enum_def(const Env, const Enum_Def); +// ANN m_bool scan2_enum_def(const Env, const Enum_Def); +ANN m_bool check_enum_def(const Env, const Enum_Def); ANN bool scan0_type_def(const Env, const Type_Def); -ANN bool scan1_type_def(const Env, const Type_Def); -ANN bool scan2_type_def(const Env, const Type_Def); -ANN bool check_type_def(const Env, const Type_Def); +ANN m_bool scan1_type_def(const Env, const Type_Def); +ANN m_bool scan2_type_def(const Env, const Type_Def); +ANN m_bool check_type_def(const Env, const Type_Def); ANN bool scan0_class_def(const Env, const Class_Def); -ANN bool scan1_class_def(const Env, const Class_Def); -ANN bool scan2_class_def(const Env, const Class_Def); -ANN bool check_class_def(const Env, const Class_Def); +ANN m_bool scan1_class_def(const Env, const Class_Def); +ANN m_bool scan2_class_def(const Env, const Class_Def); +ANN m_bool check_class_def(const Env, const Class_Def); ANN Type check_exp_call1(const Env env, Exp_Call *const exp); ANN bool scan0_prim_def(const Env env, const Prim_Def pdef); diff --git a/src/emit/emit.c b/src/emit/emit.c index 77d1109b..45b6c0da 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -2914,7 +2914,7 @@ ANN /*static */ inline m_bool emit_cdef(const Emitter emit, const Type t) { ANN static m_bool cdef_parent(const Emitter emit, const Class_Def cdef) { const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_BB(template_push_types(emit->env, cdef->base.tmpl)); + if (tmpl) CHECK_b(template_push_types(emit->env, cdef->base.tmpl)); const m_bool ret = emit_parent(emit, cdef); if (tmpl) nspc_pop_type(emit->gwion->mp, emit->env->curr); return ret; diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 551b17e5..b74b53c2 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -6,24 +6,24 @@ #include "parse.h" #define GET(a, b) ((a) & (b)) == (b) -ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t loc) { +ANN bool env_access(const Env env, const ae_flag flag, const loc_t loc) { if (env->scope->depth) { if (GET(flag, ae_flag_global)) - ERR_B(loc, _("`{G}global{0}` can only be used at %s scope."), + ERR_b(loc, _("`{G}global{0}` can only be used at %s scope."), GET(flag, ae_flag_global) && !env->class_def ? "file" : "class") } if ((GET(flag, ae_flag_static) || GET(flag, ae_flag_private) || GET(flag, ae_flag_protect)) && (!env->class_def || env->scope->depth)) - ERR_B(loc, _("`{G}static/private/protect{0}` can only be used at class scope.")) - return GW_OK; + ERR_b(loc, _("`{G}static/private/protect{0}` can only be used at class scope.")) + return true; } -ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t loc) { - CHECK_BB(env_access(env, flag, loc)); +ANN bool env_storage(const Env env, ae_flag flag, const loc_t loc) { + CHECK_B(env_access(env, flag, loc)); if(env->class_def && GET(flag, ae_flag_global)) - ERR_B(loc, _("`{G}global{0}` at class scope only valid for function pointers")); - return GW_OK; + ERR_b(loc, _("`{G}global{0}` at class scope only valid for function pointers")); + return true; } #undef GET @@ -65,13 +65,13 @@ ANN Type find_type(const Env env, Type_Decl *td) { return type; } -ANN m_bool already_defined(const Env env, const Symbol s, const loc_t loc) { +ANN bool already_defined(const Env env, const Symbol s, const loc_t loc) { const Value v = nspc_lookup_value0(env->curr, s); - if (!v || is_class(env->gwion, v->type)) return GW_OK; + if (!v || is_class(env->gwion, v->type)) return true; gwerr_basic(_("already declared as variable"), NULL, NULL, env->name, loc, 0); declared_here(v); env_error_footer(env); - return GW_ERROR; + return false; } ANN static Type class_type(const Env env, const Type base) { @@ -107,11 +107,11 @@ ANN Value global_string(const Env env, const m_str str, const loc_t loc) { return value; } -ANN m_bool isres(const Env env, const Tag tag) { +ANN bool isres(const Env env, const Tag tag) { const Map map = &env->gwion->data->id; for (m_uint i = 0; i < map_size(map); i++) { if (tag.sym == (Symbol)VKEY(map, i)) - ERR_B(tag.loc, _("%s is reserved."), s_name(tag.sym)); + ERR_b(tag.loc, _("%s is reserved."), s_name(tag.sym)); } - return GW_OK; + return true; } diff --git a/src/env/envset.c b/src/env/envset.c index 5f11cbb6..65922c2b 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -31,7 +31,7 @@ ANN static m_bool push(struct EnvSet *es, const Type t) { env_push_type((void *)es->env, t); // do not push if is a function? if (tflag(t, tflag_tmpl)) { const Tmpl *tmpl = get_tmpl(t); - CHECK_BB(template_push_types(es->env, tmpl)); + CHECK_b(template_push_types(es->env, tmpl)); } return GW_OK; } diff --git a/src/gwion.c b/src/gwion.c index 08ef77a8..10f98afb 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -230,7 +230,7 @@ ANN void env_warn(const Env env, const loc_t loc, const m_str fmt, ...) { } ANN void env_err(const Env env, const loc_t loc, const m_str fmt, ...) { - if (env->context && env->context->error) return; +// if (env->context && env->context->error) return; #ifndef __FUZZING__ va_list arg; va_start(arg, fmt); diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 8da4fc23..f175e8f8 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -83,7 +83,7 @@ Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent) { CHECK_BO(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_BO(template_push_types(gwi->gwion->env, tmpl)); + if (tmpl) CHECK_O(template_push_types(gwi->gwion->env, tmpl)); DECL_OO(const Type, base, = known_type(gwi->gwion->env, td)); const TmplArg_List tl = td->types; if (tflag(base, tflag_ntmpl)) td->types = NULL; diff --git a/src/import/import_prim.c b/src/import/import_prim.c index d4bece40..94600012 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -226,9 +226,9 @@ ANN m_bool gwi_primitive(const Gwi gwi, const m_str name, const m_uint size, con const Prim_Def pdef = new_prim_def(gwi->gwion->mp, insert_symbol(gwi->gwion->st, name), size, gwi->loc, flag); if(gwi->gwion->data->cdoc) gwfmt_prim_def(gwi->gwfmt, pdef); if(!env->class_def || !tflag(env->class_def, tflag_tmpl)) { - const m_bool ret = scan0_prim_def(gwi->gwion->env, pdef); + const bool ret = scan0_prim_def(gwi->gwion->env, pdef); free_prim_def(gwi->gwion->mp, pdef); - return ret; + return ret ? GW_OK : GW_ERROR; } Section section = MK_SECTION(primitive, prim_def, pdef); gwi_body(gwi, §ion); diff --git a/src/import/import_udef.c b/src/import/import_udef.c index aeba45d6..d9fd81c7 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -47,7 +47,7 @@ ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, } ANN static Type union_type(const Gwi gwi, const Union_Def udef) { - CHECK_BO(scan0_union_def(gwi->gwion->env, udef)); + CHECK_O(scan0_union_def(gwi->gwion->env, udef)); CHECK_BO(traverse_union_def(gwi->gwion->env, udef)); // if(!udef->tmpl) // emit_union_offset(udef->l, udef->o); diff --git a/src/lib/array.c b/src/lib/array.c index 3ca56637..1a7d3b09 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -798,6 +798,8 @@ static OP_CHECK(opck_array_scan) { struct TemplateScan *ts = (struct TemplateScan *)data; const Type t_array = env->gwion->type[et_array]; const Class_Def c = t_array->info->cdef; + if (ts->t == t_array && !ts->td->types) + ERR_N(ts->td->tag.loc, "Array needs template arguments"); DECL_ON(const Type, base, = ts->t != t_array ? ts->t : known_type(env, mp_vector_at(ts->td->types, TmplArg, 0)->d.td)); if (base->size == 0) { @@ -825,7 +827,7 @@ static OP_CHECK(opck_array_scan) { env->context = base->info->value->from->ctx; const m_uint scope = env_push(env, base->info->value->from->owner_class, base->info->value->from->owner); - CHECK_BN(scan0_class_def(env, cdef)); + CHECK_ON(scan0_class_def(env, cdef)); const Type t = cdef->base.type; if (GET_FLAG(base, abstract) && !tflag(base, tflag_union)) SET_FLAG(t, abstract); diff --git a/src/lib/dict.c b/src/lib/dict.c index 200be739..098769d0 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -573,7 +573,7 @@ static OP_CHECK(opck_dict_scan) { const bool is_global = tmpl_global(env, ts->td->types); const m_uint scope = is_global ? env_push_global(env) : env->scope->depth; - CHECK_BN(scan0_class_def(env, cdef)); + CHECK_ON(scan0_class_def(env, cdef)); const Type t = cdef->base.type; t->nspc->class_data_size = sizeof(struct HMapInfo); const m_bool ret = traverse_cdef(env, t); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index ee25d9cb..81e38d5a 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -284,13 +284,13 @@ ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) { if(c->body) cdef->body = cpy_ast(env->gwion->mp, c->body); cdef->cflag = c->cflag; cdef->base.tmpl = mk_tmpl(env, c->base.tmpl, info->td->types); - const m_bool ret = scan0_class_def(env, cdef); + const bool ret = scan0_class_def(env, cdef); if ((info->ret = cdef->base.type)) { info->ret->info->cdef = cdef; set_tflag(info->ret, tflag_cdef); } else free_class_def(env->gwion->mp, cdef); - return ret; + return ret ? GW_OK : GW_ERROR; } ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { @@ -301,14 +301,14 @@ ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { udef->tmpl = mk_tmpl(env, u->tmpl, info->td->types); // resolve the template here if (GET_FLAG(info->base, global)) SET_FLAG(udef, global); - const m_bool ret = scan0_union_def(env, udef); + const bool ret = scan0_union_def(env, udef); if (udef->type) { udef->type->info->udef = udef; // mark as udef info->ret = udef->type; // is info->ret necessary? set_tflag(info->ret, tflag_udef); } else free_union_def(env->gwion->mp, udef); - return ret; + return ret ? GW_OK : GW_ERROR; } ANN static Type _scan_class(const Env env, struct tmpl_info *info) { diff --git a/src/parse/check.c b/src/parse/check.c index 74a5add4..3f1392e2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -601,7 +601,7 @@ static Func find_func_match_actual(const Env env, const Func f, Exp* exp, if (arg->type == env->gwion->type[et_auto]) { const Type owner = func->value_ref->from->owner_class; - if (owner) CHECK_BO(template_push(env, owner)); + if (owner) CHECK_O(template_push(env, owner)); arg->type = known_type(env, arg->var.td); if (owner) nspc_pop_type(env->gwion->mp, env->curr); CHECK_OO(arg->type); @@ -674,7 +674,7 @@ ANN static m_bool check_func_args(const Env env, Arg_List args) { Arg *arg = mp_vector_at(args, Arg, i); const Var_Decl *decl = &arg->var.vd; const Value v = decl->value; - if(decl->tag.sym) CHECK_BB(already_defined(env, decl->tag.sym, decl->tag.loc)); + if(decl->tag.sym) CHECK_b(already_defined(env, decl->tag.sym, decl->tag.loc)); valid_value(env, decl->tag.sym, v); } return GW_OK; @@ -2072,7 +2072,7 @@ ANN static m_bool check_parent(const Env env, const Class_Def cdef) { ANN static m_bool cdef_parent(const Env env, const Class_Def cdef) { const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_BB(template_push_types(env, cdef->base.tmpl)); + if (tmpl) CHECK_B(template_push_types(env, cdef->base.tmpl)); const m_bool ret = check_parent(env, cdef); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); return ret; @@ -2280,7 +2280,11 @@ ANN m_bool check_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { Section * section = mp_vector_at(a, Section, i); - CHECK_BB(check_section(env, section)); +if(section->poison) continue; + if(check_section(env, section) < 0) { + section->poison = GW_OK; + return GW_ERROR; + } } if(vector_size(&env->scope->effects)) check_unhandled(env); if(env->context->extend) check_extend(env, env->context->extend); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index bf7f3354..46e4c9c8 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -47,7 +47,7 @@ ANN static Func ensure_tmpl(const Env env, const Func_Def fdef, if (exp->args && !exp->args->type) return NULL; const Func f = fdef->base->func; const Tmpl tmpl = {.list = fdef->base->tmpl->list, .call = exp->tmpl->call}; - CHECK_BO(template_push_types(env, &tmpl)); + CHECK_O(template_push_types(env, &tmpl)); const Func func = find_func_match(env, f, exp); nspc_pop_type(env->gwion->mp, env->curr); if (func) @@ -75,7 +75,7 @@ ANN static Func fptr_match(const Env env, struct ResolverArgs *ra) { const Func_Def base = v->d.func_ref ? v->d.func_ref->def : ra->e->func->type->info->func->def; const Tmpl tmpl = {.list = base->base->tmpl->list, .call = ra->types}; - CHECK_BO(template_push_types(env, &tmpl)); + CHECK_O(template_push_types(env, &tmpl)); Func_Base *const fbase = cpy_func_base(env->gwion->mp, base->base); fbase->tag.sym = sym; fbase->tmpl->call = cpy_tmplarg_list(env->gwion->mp, ra->types); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 55c90a6b..0e08fed7 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -13,14 +13,28 @@ #include "spread.h" #include "emit.h" +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + static inline void add_type(const Env env, const Nspc nspc, const Type t) { nspc_add_type_front(nspc, insert_symbol(t->name), t); } -ANN static inline m_bool scan0_defined(const Env env, const Tag tag) { - if (nspc_lookup_type1(env->curr, tag.sym)) - ERR_B(tag.loc, _("type '%s' already defined"), s_name(tag.sym)); - return already_defined(env, tag.sym, tag.loc); +ANN static inline bool scan0_defined(const Env env, const Tag tag) { + if (nspc_lookup_type1(env->curr, tag.sym)) { +// ERR_B(tag.loc, _("type '%s' already defined"), s_name(tag.sym)); + env_err(env, tag.loc, _("type '%s' already defined"), s_name(tag.sym)); +puts ("yululuy"); + return false; + } +// return already_defined(env, tag.sym, tag.loc); + int ret = already_defined(env, tag.sym, tag.loc); +printf("ret %i\n", ret); + return ret; } ANN static Arg_List fptr_arg_list(const Env env, const Fptr_Def fptr) { @@ -40,23 +54,25 @@ ANN static Arg_List fptr_arg_list(const Env env, const Fptr_Def fptr) { return NULL; } -ANN static inline m_bool scan0_global(const Env env, const ae_flag flag, - const loc_t loc) { - CHECK_BB(env_storage(env, flag, loc)); - const bool global = (flag & ae_flag_global) == ae_flag_global; - if (!global) return global; +ANN static inline bool scan0_global(const Env env, const ae_flag flag, + const loc_t loc, bool *global) { + CHECK_B(env_storage(env, flag, loc)); + if (!((flag & ae_flag_global) == ae_flag_global)) return true; if (!env->class_def) { env_push_global(env); if (env->context) env->context->global = true; - return GW_OK; + *global = true; + return true; } ERR_B(loc, _("can't declare as global in class def")) } -ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { +ANN bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { const loc_t loc = fptr->base->td->tag.loc; - CHECK_BB(env_access(env, fptr->base->flag, loc)); - CHECK_BB(scan0_defined(env, fptr->base->tag)); + CHECK_B(env_access(env, fptr->base->flag, loc)); + CHECK_B(scan0_defined(env, fptr->base->tag)); + const bool global = GET_FLAG(fptr->base, global); + UNSET_FLAG(fptr->base, global); const Arg_List args = fptr_arg_list(env, fptr); Func_Base *const fbase = new_func_base(env->gwion->mp, cpy_type_decl(env->gwion->mp, fptr->base->td), insert_symbol("func"), args, ae_flag_static | ae_flag_private, loc); @@ -65,10 +81,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef)); Type_Decl* td = new_type_decl(env->gwion->mp, insert_symbol(env->gwion->type[et_closure]->name), loc); const Class_Def cdef = new_class_def(env->gwion->mp, ae_flag_final, fptr->base->tag.sym, td, body, loc); - if(GET_FLAG(fptr->base, global)) { - SET_FLAG(cdef, global); - UNSET_FLAG(fptr->base, global); - } + if(global) SET_FLAG(cdef, global); if(fptr->base->tmpl) { fbase->tmpl = cpy_tmpl(env->gwion->mp, fptr->base->tmpl); if(!fptr->base->tmpl->call) @@ -144,7 +157,7 @@ ANN static void typedef_simple(const Env env, const Type_Def tdef, set_tflag(t, tflag_union); } -ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, +ANN static bool typedef_complex(const Env env, const Type_Def tdef, const Type base) { const ae_flag flag = base->info->cdef ? base->info->cdef->flag : 0; const Class_Def cdef = new_class_def(env->gwion->mp, flag, tdef->tag.sym, @@ -152,22 +165,23 @@ ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, NULL, tdef->ext->tag.loc); const bool final = GET_FLAG(base, final); if(final) UNSET_FLAG(base, final); - CHECK_BB(scan0_class_def(env, cdef)); + CHECK_B(scan0_class_def(env, cdef)); tdef->type = cdef->base.type; cdef->base.tmpl = tdef->tmpl; // check cpy set_tflag(tdef->type, tflag_cdef); if(final) SET_FLAG(base, final); - return GW_OK; + return true; } -ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { - CHECK_BB(env_access(env, tdef->ext->flag, tdef->ext->tag.loc)); +ANN bool scan0_type_def(const Env env, const Type_Def tdef) { + CHECK_B(scan0_defined(env, tdef->tag)); + CHECK_B(env_access(env, tdef->ext->flag, tdef->ext->tag.loc)); DECL_OB(const Type, base, = known_type(env, tdef->ext)); - CHECK_BB(scan0_defined(env, tdef->tag)); - DECL_BB(const m_bool, global, = scan0_global(env, tdef->ext->flag, tdef->ext->tag.loc)); + bool global = false; + CHECK_B(scan0_global(env, tdef->ext->flag, tdef->ext->tag.loc, &global)); if (!tdef->ext->types && (!tdef->ext->array || !tdef->ext->array->exp)) typedef_simple(env, tdef, base); - else CHECK_BB(typedef_complex(env, tdef, base)); + else CHECK_B(typedef_complex(env, tdef, base)); mk_class(env, tdef->type, tdef->tag.loc); if (tdef->when) set_tflag(tdef->type, tflag_contract); if (tdef->type != base && !tdef->distinct && !tdef->when) @@ -186,7 +200,7 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { set_tflag(tdef->type, tflag_infer); } if (global) env_pop(env, 0); - return GW_OK; + return true; } ANN static Type enum_type(const Env env, const Enum_Def edef) { @@ -198,12 +212,13 @@ ANN static Type enum_type(const Env env, const Enum_Def edef) { return t; } -ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) { - CHECK_BB(scan0_defined(env, edef->tag)); - DECL_BB(const m_bool, global, = scan0_global(env, edef->flag, edef->tag.loc)); +ANN bool scan0_enum_def(const Env env, const Enum_Def edef) { + CHECK_B(scan0_defined(env, edef->tag)); + bool global = false; + CHECK_B(scan0_global(env, edef->flag, edef->tag.loc, &global)); edef->type = enum_type(env, edef); if (global) env_pop(env, 0); - return GW_OK; + return true; } static INSTR(StructAssign) { @@ -234,7 +249,7 @@ static OP_EMIT(opem_struct_assign) { instr->m_val = -SZ_INT; instr->m_val2 = t->size - SZ_INT; } else emit_regmove(emit, -SZ_INT); - return GW_OK; + return true; } ANN static OP_CHECK(opck_struct_assign) { @@ -278,15 +293,16 @@ ANN static void union_tmpl(const Env env, const Union_Def udef) { } } -ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { - DECL_BB(const m_bool, global, = scan0_global(env, udef->flag, udef->tag.loc)); - CHECK_BB(scan0_defined(env, udef->tag)); +ANN bool scan0_union_def(const Env env, const Union_Def udef) { + bool global = false; + CHECK_B(scan0_global(env, udef->flag, udef->tag.loc, &global)); + CHECK_B(scan0_defined(env, udef->tag)); udef->type = union_type(env, udef->tag.sym, udef->tag.loc); SET_ACCESS(udef, udef->type); if (udef->tmpl) union_tmpl(env, udef); if (global) env_pop(env, 0); set_tflag(udef->type, tflag_scan0); - return GW_OK; + return true; } ANN static inline void cdef_flag(const Class_Def cdef, const Type t) { @@ -314,35 +330,37 @@ ANN static inline Type scan0_final(const Env env, Type_Decl *td) { ANN static Type cdef_parent(const Env env, const Class_Def cdef) { if (cflag(cdef, cflag_struct)) return env->gwion->type[et_compound]; if (!cdef->base.ext) return env->gwion->type[et_object]; + bool ok = true; Exp* e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL; while(e) { if(!is_prim_int(e)) - ERR_O(e->loc, "non null array type extension must be literal"); + ERR_OK(ok, e->loc, "non null array type extension must be literal"); e = e->next; } if (tmpl_base(cdef->base.tmpl)) return get_parent_base(env, cdef->base.ext); const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_BO(template_push_types(env, cdef->base.tmpl)); + if (tmpl) CHECK_O(template_push_types(env, cdef->base.tmpl)); const Type t = scan0_final(env, cdef->base.ext); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); - return t; + return ok ? t : NULL; } -ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t loc) { +ANN static bool find_traits(const Env env, ID_List traits, const loc_t loc) { + bool ok = true; for(uint32_t i = 0; i < traits->len; i++) { Symbol xid = *mp_vector_at(traits, Symbol, i); if (!nspc_lookup_trait1(env->curr, xid)) { gwerr_basic(_("can't find trait"), NULL, NULL, env->name, loc, 0); did_you_mean_trait(env->curr, s_name(xid)); env_set_error(env, true); - return GW_ERROR; + ok = false; } } - return GW_OK; + return ok; } ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { - CHECK_BO(scan0_defined(env, cdef->base.tag)); + CHECK_O(scan0_defined(env, cdef->base.tag)); DECL_OO(const Type, parent, = cdef_parent(env, cdef)); if(GET_FLAG(cdef, global) && isa(parent, env->gwion->type[et_closure]) < 0 && !type_global(env, parent)) { gwerr_basic(_("parent type is not global"), NULL, NULL, env->name, cdef->base.ext ? cdef->base.ext->tag.loc : cdef->base.tag.loc, 0); @@ -350,7 +368,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { env_set_error(env, true); return NULL; } - if (cdef->traits) CHECK_BO(find_traits(env, cdef->traits, cdef->base.tag.loc)); + if (cdef->traits) CHECK_O(find_traits(env, cdef->traits, cdef->base.tag.loc)); const Type t = new_type(env->gwion->mp, s_name(cdef->base.tag.sym), parent); if (cflag(cdef, cflag_struct)) { t->size = 0; @@ -367,24 +385,24 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { } -ANN static m_bool _spread_tmpl(const Env env, const Type t, const Spread_Def spread) { +ANN static bool _spread_tmpl(const Env env, const Type t, const Spread_Def spread) { if(t->info->value->from->owner_class) - CHECK_BB(_spread_tmpl(env, t->info->value->from->owner_class, spread)); + CHECK_B(_spread_tmpl(env, t->info->value->from->owner_class, spread)); const Tmpl *tmpl = get_tmpl(t); - if(!tmpl || !tmpl->call) return GW_OK; + if(!tmpl || !tmpl->call) return true; if(is_spread_tmpl(tmpl)) - CHECK_BB(spread_ast(env, spread, tmpl)); - return GW_OK; + CHECK_B(spread_ast(env, spread, tmpl)); + return true; } -ANN static m_bool spread_tmpl(const Env env, const Spread_Def spread) { - if(env->class_def) CHECK_BB(_spread_tmpl(env, env->class_def, spread)); - if(!env->func) return GW_OK; +ANN static bool spread_tmpl(const Env env, const Spread_Def spread) { + if(env->class_def) CHECK_B(_spread_tmpl(env, env->class_def, spread)); + if(!env->func) return true; const Tmpl *tmpl = env->func->def->base->tmpl; - if(!tmpl || !tmpl->call) return GW_OK; + if(!tmpl || !tmpl->call) return true; if(is_spread_tmpl(tmpl)) - CHECK_BB(spread_ast(env, spread, tmpl)); - return GW_OK; + CHECK_B(spread_ast(env, spread, tmpl)); + return true; } ANN static bool spreadable(const Env env) { @@ -401,28 +419,32 @@ ANN static bool spreadable(const Env env) { return false; } -ANN static m_bool scan0_stmt_list(const Env env, Stmt_List l) { +ANN static bool scan0_stmt_list(const Env env, Stmt_List l) { + bool ok = true; for(m_uint i = 0; i < l->len; i++) { Stmt* stmt = mp_vector_at(l, Stmt, i); if (stmt->stmt_type == ae_stmt_pp) { if (stmt->d.stmt_pp.pp_type == ae_pp_include) env->name = stmt->d.stmt_pp.data; - else if (stmt->d.stmt_pp.pp_type == ae_pp_import) - CHECK_BB(plugin_ini(env->gwion, stmt->d.stmt_pp.data, stmt->loc)); + else if (stmt->d.stmt_pp.pp_type == ae_pp_import) { + if(plugin_ini(env->gwion, stmt->d.stmt_pp.data, stmt->loc) < 0) + ok = false; + } } else if (stmt->stmt_type == ae_stmt_spread) { if(!spreadable(env)) - ERR_B(stmt->loc, "spread statement outside of variadic environment"); + ERR_OK(ok, stmt->loc, "spread statement outside of variadic environment"); if(!env->context->extend) env->context->extend = new_mp_vector(env->gwion->mp, Section, 0); - CHECK_BB(spread_tmpl(env, &stmt->d.stmt_spread)); + if(!spread_tmpl(env, &stmt->d.stmt_spread)) + ok = false; } } - return GW_OK; + return ok; } -ANN m_bool scan0_func_def(const Env env, const Func_Def fdef) { +ANN bool scan0_func_def(const Env env, const Func_Def fdef) { const Ast old_extend = env->context ? env->context->extend : NULL; - if(!fdef->base->tmpl || !fdef->base->tmpl->call) return GW_OK; + if(!fdef->base->tmpl || !fdef->base->tmpl->call) return true; if(env->context) { if(fdef->base->tmpl && fdef->base->tmpl->call && is_spread_tmpl(fdef->base->tmpl)) { struct Func_ fake = {.name = s_name(fdef->base->tag.sym), .def = fdef }, *const former = @@ -435,11 +457,12 @@ ANN m_bool scan0_func_def(const Env env, const Func_Def fdef) { env->func = former; env->context->extend = old_extend; }} - return GW_OK; + return true; } -ANN static m_bool scan0_extend_def(const Env env, const Extend_Def xdef) { +ANN static bool scan0_extend_def(const Env env, const Extend_Def xdef) { DECL_OB(const Type, t, = known_type(env, xdef->td)); + bool ok = true; if(type_global(env, t)) { for(uint32_t i = 0; i < xdef->traits->len; i++) { const Symbol xid = *mp_vector_at(xdef->traits, Symbol, i); @@ -449,16 +472,18 @@ ANN static m_bool scan0_extend_def(const Env env, const Extend_Def xdef) { gwerr_basic("trait should be declared global", NULL, NULL, trait->filename, trait->loc, 0); gwerr_secondary("from the request ", env->name, xdef->td->tag.loc); env_set_error(env, true); + ok = false; } } } xdef->type = t; - return GW_OK; + return ok; } -ANN static m_bool _scan0_trait_def(const Env env, const Trait_Def pdef) { - CHECK_BB(scan0_defined(env, pdef->tag)); - DECL_BB(const m_bool, global, = scan0_global(env, pdef->flag, pdef->tag.loc)); +ANN static bool _scan0_trait_def(const Env env, const Trait_Def pdef) { + CHECK_B(scan0_defined(env, pdef->tag)); + bool global = false; + CHECK_B(scan0_global(env, pdef->flag, pdef->tag.loc, &global)); const Trait trait = new_trait(env->gwion->mp, pdef->tag.loc); trait->loc = pdef->tag.loc; trait->name = s_name(pdef->tag.sym); @@ -466,14 +491,15 @@ ANN static m_bool _scan0_trait_def(const Env env, const Trait_Def pdef) { nspc_add_trait(env->curr, pdef->tag.sym, trait); if(global) env_pop(env, 0); Ast ast = pdef->body; - if(!ast) return GW_OK; // ??? + if(!ast) return true; // ??? + bool ok = true; for(m_uint i = 0; i < ast->len; i++) { Section *section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_func) { const Func_Def fdef = section->d.func_def; if (fdef->base->flag != ae_flag_none && fdef->base->flag != (ae_flag_none | ae_flag_abstract)) - ERR_B(fdef->base->tag.loc, "Trait function must be declared without qualifiers"); + ERR_OK(ok, fdef->base->tag.loc, "Trait function must be declared without qualifiers"); if (!trait->fun) trait->fun = new_mp_vector(env->gwion->mp, Func_Def, 0); mp_vector_add(env->gwion->mp, &trait->fun, Func_Def, fdef); } else if (section->section_type == ae_section_stmt) { @@ -481,15 +507,15 @@ ANN static m_bool _scan0_trait_def(const Env env, const Trait_Def pdef) { for(uint32_t i = 0; i < list->len; i++) { Stmt* stmt = mp_vector_at(list, Stmt, i); if(stmt->d.stmt_exp.val->exp_type != ae_exp_decl) - ERR_B(stmt->loc, "trait can only contains variable requests and functions"); + ERR_OK(ok, stmt->loc, "trait can only contains variable requests and functions"); } } else - ERR_B(pdef->tag.loc, "invalid section for trait definition"); + ERR_OK(ok, pdef->tag.loc, "invalid section for trait definition"); } - return GW_OK; + return ok; } -ANN static m_bool scan0_trait_def(const Env env, const Trait_Def pdef) { +ANN static bool scan0_trait_def(const Env env, const Trait_Def pdef) { const Symbol s = pdef->tag.sym; const Trait exists = nspc_lookup_trait1(env->curr, s); if (exists) { @@ -498,45 +524,46 @@ ANN static m_bool scan0_trait_def(const Env env, const Trait_Def pdef) { env_set_error(env, true); return already_defined(env, s, pdef->tag.loc); } - if (pdef->traits) CHECK_BB(find_traits(env, pdef->traits, pdef->tag.loc)); + if (pdef->traits) CHECK_B(find_traits(env, pdef->traits, pdef->tag.loc)); _scan0_trait_def(env, pdef); - return GW_OK; + return true; } -ANN m_bool scan0_prim_def(const Env env, const Prim_Def pdef) { +ANN bool scan0_prim_def(const Env env, const Prim_Def pdef) { const loc_t loc = pdef->tag.loc; - CHECK_BB(env_access(env, pdef->flag, loc)); - CHECK_BB(scan0_defined(env, pdef->tag)); - DECL_BB(const m_bool, global, = scan0_global(env, pdef->flag, loc)); + CHECK_B(env_access(env, pdef->flag, loc)); + CHECK_B(scan0_defined(env, pdef->tag)); + bool global = false; + CHECK_B(scan0_global(env, pdef->flag, loc, &global)); const Type t = mk_primitive(env, s_name(pdef->tag.sym), pdef->size); add_type(env, env->curr, t); mk_class(env, t, pdef->tag.loc); t->flag = pdef->flag; if(global) env_pop(env, 0); - return GW_OK; + return true; } -HANDLE_SECTION_FUNC(scan0, m_bool, Env) +HANDLE_SECTION_FUNC(scan0, bool, Env) -ANN static m_bool scan0_class_def_inner(const Env env, const Class_Def cdef) { - CHECK_BB(isres(env, cdef->base.tag)); - CHECK_OB((cdef->base.type = scan0_class_def_init(env, cdef))); +ANN static bool scan0_class_def_inner(const Env env, const Class_Def cdef) { + CHECK_B(isres(env, cdef->base.tag)); + CHECK_B((cdef->base.type = scan0_class_def_init(env, cdef))); cdef->base.type->info->traits = cdef->traits; // should we copy the traits? set_tflag(cdef->base.type, tflag_scan0); (void)mk_class(env, cdef->base.type, cdef->base.tag.loc); add_type(env, cdef->base.type->info->value->from->owner, cdef->base.type); - const m_bool ret = cdef->body ? env_body(env, cdef, scan0_section) : GW_OK; - return ret; + return cdef->body ? env_body_b(env, cdef, scan0_section) : true; } ANN Ast spread_class(const Env env, const Ast body); -ANN m_bool scan0_class_def(const Env env, const Class_Def c) { - DECL_BB(const m_bool, global, = scan0_global(env, c->flag, c->base.tag.loc)); +ANN bool scan0_class_def(const Env env, const Class_Def c) { + bool global = false; + CHECK_B(scan0_global(env, c->flag, c->base.tag.loc, &global)); const Ast old_extend = env->context ? env->context->extend : NULL; const int cpy = tmpl_base(c->base.tmpl) || GET_FLAG(c, global); const Class_Def cdef = !cpy ? c : cpy_class_def(env->gwion->mp, c); - const m_bool ret = scan0_class_def_inner(env, cdef); + const bool ret = scan0_class_def_inner(env, cdef); if (cpy && cdef->base.type) c->base.type = cdef->base.type; if(env->context) { @@ -549,11 +576,15 @@ ANN m_bool scan0_class_def(const Env env, const Class_Def c) { return ret; } -ANN m_bool scan0_ast(const Env env, Ast *ast) { +ANN bool scan0_ast(const Env env, Ast *ast) { Ast a = *ast; + bool ok = true; for(m_uint i = 0; i < a->len; i++) { Section * section = mp_vector_at(a, Section, i); - CHECK_BB(scan0_section(env, section)); + if(!scan0_section(env, section)) { + ok = false; + section->poison = true; + } } - return GW_OK; + return ok; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7032a2df..82b5fd94 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -108,7 +108,7 @@ ANN m_bool abstract_array(const Env env, const Array_Sub array) { ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { const bool decl_ref = decl->var.td->array && !decl->var.td->array->exp; Var_Decl *const vd = &decl->var.vd; - CHECK_BB(isres(env, vd->tag)); + CHECK_b(isres(env, vd->tag)); Type t = decl->type; CHECK_BB(scan1_defined(env, vd)); const Type base = array_base_simple(t); @@ -152,7 +152,7 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { } ANN m_bool scan1_exp_decl(const Env env, Exp_Decl *const decl) { - CHECK_BB(env_storage(env, decl->var.td->flag, exp_self(decl)->loc)); + CHECK_b(env_storage(env, decl->var.td->flag, exp_self(decl)->loc)); ((Exp_Decl *)decl)->type = scan1_exp_decl_type(env, (Exp_Decl *)decl); CHECK_OB(decl->type); if(decl->args) CHECK_BB(scan1_exp(env, decl->args)); @@ -426,7 +426,7 @@ ANN static m_bool scan1_args(const Env env, Arg_List args) { for(uint32_t i = 0; i < args->len; i++) { Arg *arg = mp_vector_at(args, Arg, i); Var_Decl *const vd = &arg->var.vd; - if (vd->tag.sym) CHECK_BB(isres(env, vd->tag)); + if (vd->tag.sym) CHECK_b(isres(env, vd->tag)); if (arg->var.td) { SET_FLAG(arg->var.td, late); CHECK_OB((arg->type = void_type(env, arg->var.td))); @@ -553,7 +553,7 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, ANN static m_bool scan1_union_def_inner(const Env env, const Union_Def udef) { if (udef->tmpl && udef->tmpl->call) - CHECK_BB(template_push_types(env, udef->tmpl)); + CHECK_b(template_push_types(env, udef->tmpl)); const m_bool ret = scan1_union_def_inner_loop(env, udef); if (udef->tmpl && udef->tmpl->call) nspc_pop_type(env->gwion->mp, env->curr); return ret; @@ -731,7 +731,7 @@ ANN static inline m_bool scan1_fdef_defined(const Env env, ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { if(GET_FLAG(fdef->base, abstract) && !env->class_def) ERR_B(fdef->base->tag.loc, "file scope function can't be abstract"); - CHECK_BB(env_storage(env, fdef->base->flag, fdef->base->tag.loc)); + CHECK_b(env_storage(env, fdef->base->flag, fdef->base->tag.loc)); CHECK_BB(scan1_fdef_defined(env, fdef)); const bool global = GET_FLAG(fdef->base, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); @@ -802,7 +802,7 @@ ANN static inline Type scan1_final(const Env env, Type_Decl *td, const bool tdef ANN static m_bool cdef_parent(const Env env, const Class_Def cdef) { CHECK_OB((cdef->base.type->info->parent = scan1_final(env, cdef->base.ext, tflag(cdef->base.type, tflag_typedef)))); const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_BB(template_push_types(env, cdef->base.tmpl)); + if (tmpl) CHECK_b(template_push_types(env, cdef->base.tmpl)); const m_bool ret = scan1_parent(env, cdef); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); return ret; @@ -879,7 +879,12 @@ ANN m_bool scan1_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { Section *section = mp_vector_at(a, Section, i); - CHECK_BB(scan1_section(env, section)); +// CHECK_BB(scan1_section(env, section)); + if(section->poison) continue; + if(scan1_section(env, section) < 0) { + section->poison = true; + return GW_ERROR; + } } return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index f74c34b9..0298aa1f 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -563,7 +563,7 @@ ANN static m_bool scan2_parent(const Env env, const Class_Def cdef) { ANN static m_bool cdef_parent(const Env env, const Class_Def cdef) { const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_BB(template_push_types(env, cdef->base.tmpl)); + if (tmpl) CHECK_B(template_push_types(env, cdef->base.tmpl)); const m_bool ret = scan2_parent(env, cdef); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); return ret; @@ -622,7 +622,11 @@ ANN m_bool scan2_ast(const Env env, Ast *ast) { m_bool ret = GW_OK; for(m_uint i = 0; i < a->len; i++) { Section *section = mp_vector_at(a, Section, i); - if((ret = scan2_section(env, section)) < 0) break; + if(section->poison) continue; + if((ret = scan2_section(env, section)) < 0) { + section->poison = true; + break; + } if (section->section_type == ae_section_func && fbflag(section->d.func_def->base, fbflag_default)) { mp_vector_add(env->gwion->mp, &acc, Section, *section); diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 3444c9b1..29012c79 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -14,12 +14,20 @@ ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) { return GW_OK; } +ANN static inline bool _body_b(const Env e, Ast b, const _exp_func_b f) { + for(m_uint i = 0; i < b->len; i++) { + Section *section = mp_vector_at(b, Section, i); + CHECK_B(f(e, section)); + } + return true; +} + ANN static inline int actual(const Tmpl *tmpl) { return tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list; } ANN static inline m_bool tmpl_push(const Env env, const Tmpl *tmpl) { - return actual(tmpl) ? template_push_types(env, tmpl) : GW_ERROR; + return actual(tmpl) ? template_push_types(env, tmpl) > 0 ? GW_OK : GW_ERROR: GW_ERROR; } ANN static inline m_int _push(const Env env, const Class_Def c) { @@ -42,6 +50,14 @@ ANN m_bool scanx_body(const Env e, const Class_Def c, const _exp_func f, return ret; } +ANN bool scanx_body_b(const Env e, const Class_Def c, const _exp_func_b f, + void *d) { + const m_int scope = _push(e, c); // check me + const bool ret = _body_b(d, c->body, f); + _pop(e, c, scope); + return ret; +} + ANN static m_bool _scanx_cdef(const Env env, void *opt, const Type t, const _exp_func f_cdef, const _exp_func f_udef) { if (t->info->parent != env->gwion->type[et_union]) @@ -60,7 +76,7 @@ ANN m_bool scanx_cdef(const Env env, void *opt, const Type t, ANN m_bool scanx_fdef(const Env env, void *data, const Func_Def fdef, const _exp_func func) { - if (fdef->base->tmpl) CHECK_BB(template_push_types(env, fdef->base->tmpl)); + if (fdef->base->tmpl) CHECK_b(template_push_types(env, fdef->base->tmpl)); const bool in_try = env->scope->in_try; const m_bool ret = func(data, fdef); if (fdef->base->tmpl) nspc_pop_type(env->gwion->mp, env->curr); diff --git a/src/parse/spread.c b/src/parse/spread.c index 6b7077e4..c09e0f1f 100644 --- a/src/parse/spread.c +++ b/src/parse/spread.c @@ -11,10 +11,10 @@ #include "operator.h" #include "import.h" -ANN m_bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) { +ANN bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) { const m_str data = spread->data; char c[256]; - DECL_OB(FILE *,f, = fmemopen(data, strlen(data), "r")); + DECL_B(FILE *,f, = fmemopen(data, strlen(data), "r")); for(uint32_t i = tmpl->list->len - 1; i < tmpl->call->len; i++) { fseek(f, 0, SEEK_SET); const TmplArg targ = *mp_vector_at(tmpl->call, TmplArg, i); @@ -25,7 +25,7 @@ ANN m_bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) env_set_error(env, true); return GW_ERROR; } - DECL_OB(const Type, t, = known_type(env, targ.d.td)); + DECL_B(const Type, t, = known_type(env, targ.d.td)); struct AstGetter_ arg = {env->name, f, env->gwion->st, .ppa = env->gwion->ppa}; const m_str type = type2str(env->gwion, t, targ.d.td->tag.loc); sprintf(c, "%s=%s", s_name(spread->tag.sym), type); @@ -44,8 +44,8 @@ ANN m_bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) m_str name = s_name(sym); pparg_rem(env->gwion->ppa, name); } - if(!ast) return GW_ERROR; - CHECK_BB(scan0_ast(env, &ast)); + if(!ast) return false; + CHECK_b(scan0_ast(env, &ast)); for(uint32_t i = 0; i < ast->len; i++) { const Section section = *mp_vector_at(ast, Section, i); mp_vector_add(env->gwion->mp, &env->context->extend, Section, section); @@ -54,7 +54,7 @@ ANN m_bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) } fclose(f); mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL)); - return GW_OK; + return true; } ANN Ast spread_class(const Env env, const Ast body) { @@ -103,6 +103,7 @@ ANN Stmt_List spread_func(const Env env, const Stmt_List body) { const Ast extend = env->context->extend; Ast new_body = new_mp_vector(env->gwion->mp, Stmt, 0); uint32_t offset = 0; + bool ok = true; for(uint32_t i = 0; i < body->len; i++) { const Stmt stmt = *mp_vector_at(body, Stmt, i); if(stmt.stmt_type == ae_stmt_spread) { @@ -111,7 +112,7 @@ ANN Stmt_List spread_func(const Env env, const Stmt_List body) { if(section.section_type == ae_section_stmt && !section.d.stmt_list) break; if(section.section_type != ae_section_stmt) - ERR_O(stmt.loc, "invalid section in variadic func"); + ERR_OK(ok, stmt.loc, "invalid section in variadic func"); const Stmt_List list = section.d.stmt_list; for(uint32_t j = 0; j < list->len; j++) { const Stmt stmt = *mp_vector_at(list, Stmt, j); @@ -124,5 +125,6 @@ ANN Stmt_List spread_func(const Env env, const Stmt_List body) { } free_mp_vector(env->gwion->mp, Stmt_List, body); free_mp_vector(env->gwion->mp, Section, extend); - return new_body; + if(ok) return new_body; + return NULL; } diff --git a/src/parse/template.c b/src/parse/template.c index daaf2733..bafa91c5 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -14,16 +14,16 @@ #include "import.h" #include "spread.h" -ANN static m_bool _push_types(const Env env, const Nspc nspc, +ANN static bool _push_types(const Env env, const Nspc nspc, const Tmpl *tmpl) { Specialized_List sl = tmpl->list; TmplArg_List tl = tmpl->call; Specialized *spec = mp_vector_at(sl, Specialized, sl->len - 1); const uint32_t len = strcmp(s_name(spec->tag.sym), "...") ? sl->len : sl->len-1; - if(!tl) return GW_OK; + if(!tl) return true; for(uint32_t i = 0; i < len; i++) { - if (i >= tl->len) return GW_OK; + if (i >= tl->len) return true; TmplArg arg = *mp_vector_at(tl, TmplArg, i); if(unlikely(arg.type == tmplarg_exp)) continue; const Type t = known_type(env, arg.d.td); @@ -31,16 +31,16 @@ ANN static m_bool _push_types(const Env env, const Nspc nspc, nspc_add_type(nspc, spec->tag.sym, t); }; if(len != sl->len) return GW_OK; - return tl->len == sl->len ? GW_OK : GW_ERROR; + return tl->len == sl->len; } -ANN static m_bool push_types(const Env env, const Nspc nspc, const Tmpl *tmpl) { +ANN static bool push_types(const Env env, const Nspc nspc, const Tmpl *tmpl) { const Type t = env->class_def; if (t) { env->class_def = t->info->value->from->owner_class; env->curr = t->info->value->from->owner; } - const m_bool ret = _push_types(env, nspc, tmpl); + const bool ret = _push_types(env, nspc, tmpl); if (t) { env->class_def = t; env->curr = t->nspc; @@ -48,15 +48,15 @@ ANN static m_bool push_types(const Env env, const Nspc nspc, const Tmpl *tmpl) { return ret; } -ANN static m_bool _template_push(const Env env, const Type t) { +ANN static bool _template_push(const Env env, const Type t) { if (t->info->value->from->owner_class) - CHECK_BB(template_push(env, t->info->value->from->owner_class)); + CHECK_B(template_push(env, t->info->value->from->owner_class)); return tflag(t, tflag_tmpl) ? push_types(env, t->nspc, get_tmpl(t)) - : GW_OK; + : true; } -ANN m_bool template_push(const Env env, const Type t) { +ANN bool template_push(const Env env, const Type t) { nspc_push_type(env->gwion->mp, env->curr); return _template_push(env, t); } @@ -116,11 +116,11 @@ ANN m_bool const_generic_typecheck(const Env env, const Specialized *spec, const return GW_OK; } -ANN m_bool template_push_types(const Env env, const Tmpl *tmpl) { +ANN bool template_push_types(const Env env, const Tmpl *tmpl) { nspc_push_type(env->gwion->mp, env->curr); if (tmpl->call) check_call(env, tmpl); - if (push_types(env, env->curr, tmpl) > 0) return GW_OK; - POP_RET(GW_ERROR); + if (push_types(env, env->curr, tmpl) > 0) return true; + POP_RET(false); } ANN Tmpl *mk_tmpl(const Env env, const Tmpl *tm, const TmplArg_List types) { diff --git a/src/parse/traverse.c b/src/parse/traverse.c index 06c69f19..cb759eb5 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -4,7 +4,7 @@ #include "traverse.h" ANN m_bool traverse_ast(const Env env, Ast *const ast) { - CHECK_BB(scan0_ast(env, ast)); + CHECK_b(scan0_ast(env, ast)); CHECK_BB(scan1_ast(env, ast)); CHECK_BB(scan2_ast(env, ast)); return check_ast(env, ast); @@ -17,7 +17,7 @@ ANN m_bool traverse_exp(const Env env, Exp* exp) { } ANN static m_bool _traverse_func_def(const Env env, const Func_Def fdef) { - CHECK_BB(scan0_func_def(env, fdef)); + CHECK_b(scan0_func_def(env, fdef)); CHECK_BB(scan1_func_def(env, fdef)); CHECK_BB(scan2_func_def(env, fdef)); return check_func_def(env, fdef); @@ -41,7 +41,7 @@ ANN m_bool traverse_union_def(const Env env, const Union_Def def) { } ANN m_bool traverse_enum_def(const Env env, const Enum_Def def) { - CHECK_BB(scan0_enum_def(env, def)); + CHECK_b(scan0_enum_def(env, def)); CHECK_BB(scan1_enum_def(env, def)); // CHECK_BB(scan2_enum_def(env, def)); // return check_enum_def(env, def); @@ -49,14 +49,14 @@ ANN m_bool traverse_enum_def(const Env env, const Enum_Def def) { } ANN m_bool traverse_fptr_def(const Env env, const Fptr_Def def) { - CHECK_BB(scan0_fptr_def(env, def)); + CHECK_b(scan0_fptr_def(env, def)); CHECK_BB(scan1_fptr_def(env, def)); CHECK_BB(scan2_fptr_def(env, def)); return check_fptr_def(env, def); } ANN m_bool traverse_type_def(const Env env, const Type_Def def) { - CHECK_BB(scan0_type_def(env, def)); + CHECK_b(scan0_type_def(env, def)); CHECK_BB(scan1_type_def(env, def)); CHECK_BB(scan2_type_def(env, def)); return check_type_def(env, def); diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 56944958..3548dbe2 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -97,7 +97,7 @@ ANN static inline Type find(const Env env, Type_Decl *td) { ANN static inline Type find1(const Env env, const Type base, Type_Decl *td) { if (!td->fptr) return scan_type(env, base, td); if (!td->fptr->cdef->base.type) { - CHECK_BO(scan0_fptr_def(env, td->fptr)); + CHECK_O(scan0_fptr_def(env, td->fptr)); CHECK_BO(traverse_fptr_def(env, td->fptr)); } return td->fptr->cdef->base.type; diff --git a/src/pass.c b/src/pass.c index e077012f..7ae91d14 100644 --- a/src/pass.c +++ b/src/pass.c @@ -11,8 +11,15 @@ #define N_PASS 2 #define N_SCANPASS 4 +static m_bool typecheck_ast(const Env env, Ast *ast) { + CHECK_BB(traverse_ast(env, ast)); + if(env->scope->poison)env->context->error = true; + if(env->context->error)return GW_ERROR; + return GW_OK; +} + static const m_str default_passes_name[2] = {"check", "emit"}; -static const compilation_pass default_passes[4] = {traverse_ast, emit_ast}; +static const compilation_pass default_passes[4] = {typecheck_ast, emit_ast}; static const m_str scan_passes_name[4] = {"scan0", "scan1", "scan2", "type_check"}; static const compilation_pass scan_passes[4] = {scan0_ast, scan1_ast, scan2_ast, -- 2.43.0