From: fennecdjay Date: Mon, 26 Feb 2024 20:10:10 +0000 (+0100) Subject: :fire: more on poisoning X-Git-Tag: nightly~51 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=296a9e2801046ee978a9065bdc69d2d2f0d4457d;p=gwion.git :fire: more on poisoning --- diff --git a/include/parse.h b/include/parse.h index 3fc734a5..4edcfb79 100644 --- a/include/parse.h +++ b/include/parse.h @@ -16,6 +16,14 @@ (node)-> poison = true; \ } while(false) +#define POISON_SECTION(ok, env, node) \ + do { \ + if(node->section_type != ae_section_stmt) \ + POISON_NODE(ok, env, node); \ + else \ + env->context->error = true; \ +} while(false) + #define ERR_OK_NODE(ok, a, b, c, ...) \ do { \ env_err(env, (b), (c), ##__VA_ARGS__); \ diff --git a/src/parse/check.c b/src/parse/check.c index 3daceb3f..28c7daaf 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1354,7 +1354,7 @@ ANN Type check_exp(const Env env, Exp* exp) { env_weight(env, 1); do { if(curr->type) continue; - if(curr->poison) continue; + if(curr->poison) { ok = false; continue;} if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d)) || curr->type->error) { POISON_NODE(ok, env, curr); continue; @@ -1750,6 +1750,7 @@ ANN bool check_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->poison) { ok = false; continue;} if(!check_stmt(env, stmt)) POISON_NODE(ok, env, stmt); } @@ -2303,18 +2304,20 @@ ANN static inline void check_unhandled(const Env env) { vector_pop(v); } -ANN static void check_extend(const Env env, Ast ast) { +ANN static bool check_extend(const Env env, Ast ast) { + bool ok = true; for(m_uint i = 0; i < ast->len; i++) { Section * section = mp_vector_at(ast, Section, i); if(section->poison) continue; if(!check_section(env, section)) { - section->poison = true; + POISON_SECTION(ok, env, section); continue; } mp_vector_add(env->gwion->mp, &env->context->tree, Section, *section); } free_mp_vector(env->gwion->mp, Section, env->context->extend); env->context->extend = NULL; + return ok; } ANN bool check_ast(const Env env, Ast *ast) { @@ -2322,9 +2325,9 @@ ANN bool check_ast(const Env env, Ast *ast) { bool ok = true; for(m_uint i = 0; i < a->len; i++) { Section * section = mp_vector_at(a, Section, i); - if(section->poison) continue; + if(section->poison) { ok = false; continue;} if(!check_section(env, section)) - POISON_NODE(ok, env, section); + POISON_SECTION(ok, env, section); } if(env->context->extend) check_extend(env, env->context->extend); if(ok && vector_size(&env->scope->effects)) check_unhandled(env); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index fa1dc569..d1dede59 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -409,6 +409,7 @@ 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->poison) { ok = false; continue; } if (stmt->stmt_type == ae_stmt_pp) { if (stmt->d.stmt_pp.pp_type == ae_pp_include) env->name = stmt->d.stmt_pp.data; @@ -481,6 +482,7 @@ ANN static bool _scan0_trait_def(const Env env, const Trait_Def pdef) { bool ok = true; for(m_uint i = 0; i < ast->len; i++) { Section *section = mp_vector_at(ast, Section, i); + if(section->poison) { ok = false; continue; } if (section->section_type == ae_section_func) { const Func_Def fdef = section->d.func_def; if (fdef->base->flag != ae_flag_none && @@ -492,6 +494,7 @@ ANN static bool _scan0_trait_def(const Env env, const Trait_Def pdef) { Stmt_List list = section->d.stmt_list; for(uint32_t i = 0; i < list->len; i++) { Stmt* stmt = mp_vector_at(list, Stmt, i); + if(stmt->poison) { ok = false; continue;} if(stmt->d.stmt_exp.val->exp_type != ae_exp_decl) ERR_OK(ok, stmt->loc, "trait can only contains variable requests and functions"); } @@ -567,8 +570,9 @@ ANN bool scan0_ast(const Env env, Ast *ast) { bool ok = true; for(m_uint i = 0; i < a->len; i++) { Section * section = mp_vector_at(a, Section, i); + if(section->poison) { ok = false; continue;} if(!scan0_section(env, section)) - POISON_NODE(ok, env, section); + POISON_SECTION(ok, env, section); } return ok; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 8a1d6cf9..6474f936 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -645,6 +645,7 @@ ANN static bool scan1_stmt_list(const Env env, Stmt_List l) { bool ok = true; for(i = 0; i < l->len; i++) { Stmt* stmt = mp_vector_at(l, Stmt, i); + if(stmt->poison) { ok = false; continue;} if(!scan1_stmt(env, stmt)) { POISON_NODE(ok, env, stmt); continue; @@ -845,10 +846,12 @@ ANN static bool scan1_class_def_body(const Env env, const Class_Def cdef) { Ast body = new_mp_vector(mp, Section, 1); // room for ctor for(uint32_t i = 0; i < base->len; i++) { Section section = *mp_vector_at(base, Section, i); + if(section.poison) continue; if(section.section_type == ae_section_stmt) { Stmt_List list = section.d.stmt_list; for(uint32_t j = 0; j < list->len; j++) { Stmt* stmt = mp_vector_at(list, Stmt, j); + if(stmt->poison) continue; mp_vector_add(mp, &ctor, Stmt, *stmt); } } else mp_vector_add(mp, &body, Section, section); @@ -911,9 +914,9 @@ ANN bool scan1_ast(const Env env, Ast *ast) { bool ok = true; for(m_uint i = 0; i < a->len; i++) { Section *section = mp_vector_at(a, Section, i); - if(section->poison) continue; + if(section->poison) { ok = false; continue;} if(!scan1_section(env, section)) - POISON_NODE(ok, env, section); + POISON_SECTION(ok, env, section); } return ok; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 211fdfe7..b69d6a31 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -275,6 +275,7 @@ ANN static bool scan2_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->poison) { ok = false; continue; } if(!scan2_stmt(env, stmt)) POISON_NODE(ok, env, stmt); } @@ -634,9 +635,9 @@ ANN bool scan2_ast(const Env env, Ast *ast) { bool ok = true; for(m_uint i = 0; i < a->len; i++) { Section *section = mp_vector_at(a, Section, i); - if(section->poison) continue; + if(section->poison) { ok = false; continue;} if(!scan2_section(env, section)) { - POISON_NODE(ok, env, section); + POISON_SECTION(ok, env, section); continue; } if (section->section_type == ae_section_func && diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 2d1629b8..ccafa9e8 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -10,9 +10,9 @@ ANN static inline bool _body(const Env env, Ast ast, const _envset_func f) { bool ok = true; for(m_uint i = 0; i < ast->len; i++) { Section *section = mp_vector_at(ast, Section, i); - if(section->poison) continue; + if(section->poison) { ok = false; continue; } if(!f(env, section)) - POISON_NODE(ok, env, section); + POISON_SECTION(ok, env, section); } return ok; }