From e4f3d5e6f0bb074a0c8d2ac4b7faa3ac069accf6 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 29 Mar 2024 13:53:11 +0100 Subject: [PATCH] :art: improve escape table --- include/emit.h | 1 - include/escape.h | 1 - src/emit/emitter.c | 3 --- src/emit/escape.c | 30 ++++++++++++++---------------- src/import/import_prim.c | 2 +- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/emit.h b/include/emit.h index 8be17390..2f1764f8 100644 --- a/include/emit.h +++ b/include/emit.h @@ -37,7 +37,6 @@ typedef struct Code_ { struct EmitterInfo_ { struct Vector_ pure; - char * escape; VM_Code (*emit_code)(const Emitter); VM_Code code; bool debug; diff --git a/include/escape.h b/include/escape.h index a6e2429a..028ae078 100644 --- a/include/escape.h +++ b/include/escape.h @@ -1,6 +1,5 @@ #ifndef __ESCAPE #define __ESCAPE -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/src/emit/emitter.c b/src/emit/emitter.c index b3473321..1658f36a 100644 --- a/src/emit/emitter.c +++ b/src/emit/emitter.c @@ -5,7 +5,6 @@ #include "gwion.h" #include "instr.h" #include "emit.h" -#include "escape.h" static ANEW ANN VM_Code emit_code(const Emitter emit) { Code *const c = emit->code; @@ -22,7 +21,6 @@ ANEW Emitter new_emitter(MemPool p) { vector_init(&emit->stack); emit->info = (struct EmitterInfo_ *)mp_calloc(p, EmitterInfo); vector_init(&emit->info->pure); - emit->info->escape = escape_table(p); emit->info->emit_code = emit_code; return emit; } @@ -30,7 +28,6 @@ ANEW Emitter new_emitter(MemPool p) { ANN void free_emitter(MemPool p, Emitter a) { vector_release(&a->stack); vector_release(&a->info->pure); - mp_free2(p, 256, a->info->escape); mp_free(p, EmitterInfo, a->info); mp_free(p, Emitter, a); } diff --git a/src/emit/escape.c b/src/emit/escape.c index 65c3b8f3..d7bb0e41 100644 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@ -6,24 +6,22 @@ #include "emit.h" #include "escape.h" -char *escape_table(MemPool p) { - char *escape = (char *)mp_calloc2(p, 256); - escape['0'] = '0'; - escape['\''] = '\''; - escape['"'] = '"'; - escape['\\'] = '\\'; - escape['a'] = (char)7; // audible bell - escape['b'] = (char)8; // back space - escape['f'] = (char)12; // form feed - escape['n'] = (char)10; // new line - escape['r'] = (char)13; // carriage return - escape['t'] = (char)9; // horizontal tab - escape['v'] = (char)11; // vertical tab - return escape; -} +char escape_table[256] = { + ['0'] = '0', + ['\''] = '\'', + ['"'] = '"', + ['\\'] = '\\', + ['a'] = (char)7, // audible bell + ['b'] = (char)8, // back space + ['f'] = (char)12, // form feed + ['n'] = (char)10, // new line + ['r'] = (char)13, // carriage return + ['t'] = (char)9, // horizontal tab + ['v'] = (char)11, // vertical tab +}; static bool get_escape(const Emitter emit, const char c, char *out, const loc_t loc) { - *out = emit->info->escape[(int)c]; + *out = escape_table[(int)c]; if(out) return true; env_err(emit->env, loc, _("unrecognized escape sequence '\\%c'"), c); return false; diff --git a/src/import/import_prim.c b/src/import/import_prim.c index fdbd7502..8e010df8 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -225,7 +225,7 @@ ANN bool gwi_primitive(const Gwi gwi, const m_str name, const m_uint size, const const Env env = gwi->gwion->env; 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)) { + if(!safe_tflag(env->class_def, tflag_tmpl)) { const bool ret = scan0_prim_def(gwi->gwion->env, pdef); free_prim_def(gwi->gwion->mp, pdef); return ret; -- 2.43.0