From a1b2693161183fb6052271d8ea1809e48d75d144 Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 12 Dec 2013 15:34:40 +0000 Subject: [PATCH] py: remove further unnecessary emit_verbatim code. --- py/compile.c | 6 --- py/emit.h | 7 +-- py/emitbc.c | 27 +---------- py/emitcpy.c | 120 +++++++++++++++++------------------------------- py/emitnative.c | 30 ------------ py/emitpass1.c | 5 -- 6 files changed, 45 insertions(+), 150 deletions(-) diff --git a/py/compile.c b/py/compile.c index 5fbf623b2..ea0bbc2d5 100644 --- a/py/compile.c +++ b/py/compile.c @@ -383,9 +383,7 @@ static void cpython_c_tuple(compiler_t *comp, py_parse_node_t pn, py_parse_node_ } else { vstr_printf(vstr, ")"); } - EMIT(load_const_verbatim_start); EMIT(load_const_verbatim_str, vstr_str(vstr)); - EMIT(load_const_verbatim_end); vstr_free(vstr); } else { if (!PY_PARSE_NODE_IS_NULL(pn)) { @@ -1221,9 +1219,7 @@ void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) { // build the "fromlist" tuple #if MICROPY_EMIT_CPYTHON - EMIT(load_const_verbatim_start); EMIT(load_const_verbatim_str, "('*',)"); - EMIT(load_const_verbatim_end); #else EMIT(load_const_str, qstr_from_str_static("*"), false); EMIT(build_tuple, 1); @@ -1259,9 +1255,7 @@ void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) { vstr_printf(vstr, ","); } vstr_printf(vstr, ")"); - EMIT(load_const_verbatim_start); EMIT(load_const_verbatim_str, vstr_str(vstr)); - EMIT(load_const_verbatim_end); vstr_free(vstr); } #else diff --git a/py/emit.h b/py/emit.h index fdfe76437..62a149e10 100644 --- a/py/emit.h +++ b/py/emit.h @@ -38,12 +38,7 @@ typedef struct _emit_method_table_t { void (*load_const_dec)(emit_t *emit, qstr qstr); void (*load_const_id)(emit_t *emit, qstr qstr); void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes); - void (*load_const_verbatim_start)(emit_t *emit); - void (*load_const_verbatim_int)(emit_t *emit, int val); - void (*load_const_verbatim_str)(emit_t *emit, const char *str); - void (*load_const_verbatim_strn)(emit_t *emit, const char *str, int len); - void (*load_const_verbatim_quoted_str)(emit_t *emit, qstr qstr, bool bytes); - void (*load_const_verbatim_end)(emit_t *emit); + void (*load_const_verbatim_str)(emit_t *emit, const char *str); // only needed for emitcpy void (*load_fast)(emit_t *emit, qstr qstr, int local_num); void (*load_deref)(emit_t *emit, qstr qstr, int local_num); void (*load_closure)(emit_t *emit, qstr qstr, int local_num); diff --git a/py/emitbc.c b/py/emitbc.c index 880c10807..e1632f37f 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -266,28 +266,8 @@ static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) { } } -static void emit_bc_load_const_verbatim_start(emit_t *emit) { - emit_pre(emit, 1); - assert(0); -} - -static void emit_bc_load_const_verbatim_int(emit_t *emit, int val) { - assert(0); -} - static void emit_bc_load_const_verbatim_str(emit_t *emit, const char *str) { - assert(0); -} - -static void emit_bc_load_const_verbatim_strn(emit_t *emit, const char *str, int len) { - assert(0); -} - -static void emit_bc_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) { - assert(0); -} - -static void emit_bc_load_const_verbatim_end(emit_t *emit) { + // not needed/supported for BC assert(0); } @@ -718,12 +698,7 @@ const emit_method_table_t emit_bc_method_table = { emit_bc_load_const_dec, emit_bc_load_const_id, emit_bc_load_const_str, - emit_bc_load_const_verbatim_start, - emit_bc_load_const_verbatim_int, emit_bc_load_const_verbatim_str, - emit_bc_load_const_verbatim_strn, - emit_bc_load_const_verbatim_quoted_str, - emit_bc_load_const_verbatim_end, emit_bc_load_fast, emit_bc_load_deref, emit_bc_load_closure, diff --git a/py/emitcpy.c b/py/emitcpy.c index a1d03ec4c..cb8bef479 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -28,9 +28,6 @@ struct _emit_t { int *label_offsets; }; -// forward declaration -static void emit_cpy_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes); - emit_t *emit_cpython_new(uint max_num_labels) { emit_t *emit = m_new(emit_t, 1); emit->max_num_labels = max_num_labels; @@ -176,85 +173,59 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) { } } +static void print_quoted_str(qstr qstr, bool bytes) { + const char *str = qstr_str(qstr); + int len = strlen(str); + bool has_single_quote = false; + bool has_double_quote = false; + for (int i = 0; i < len; i++) { + if (str[i] == '\'') { + has_single_quote = true; + } else if (str[i] == '"') { + has_double_quote = true; + } + } + if (bytes) { + printf("b"); + } + bool quote_single = false; + if (has_single_quote && !has_double_quote) { + printf("\""); + } else { + quote_single = true; + printf("'"); + } + for (int i = 0; i < len; i++) { + if (str[i] == '\n') { + printf("\\n"); + } else if (str[i] == '\\') { + printf("\\\\"); + } else if (str[i] == '\'' && quote_single) { + printf("\\'"); + } else { + printf("%c", str[i]); + } + } + if (has_single_quote && !has_double_quote) { + printf("\""); + } else { + printf("'"); + } +} + static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { emit_pre(emit, 1, 3); if (emit->pass == PASS_3) { printf("LOAD_CONST "); - emit_cpy_load_const_verbatim_quoted_str(emit, qstr, bytes); + print_quoted_str(qstr, bytes); printf("\n"); } } -static void emit_cpy_load_const_verbatim_start(emit_t *emit) { - emit_pre(emit, 1, 3); - if (emit->pass == PASS_3) { - printf("LOAD_CONST "); - } -} - -static void emit_cpy_load_const_verbatim_int(emit_t *emit, int val) { - if (emit->pass == PASS_3) { - printf("%d", val); - } -} - static void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) { + emit_pre(emit, 1, 3); if (emit->pass == PASS_3) { - printf("%s", str); - } -} - -static void emit_cpy_load_const_verbatim_strn(emit_t *emit, const char *str, int len) { - if (emit->pass == PASS_3) { - printf("%.*s", len, str); - } -} - -static void emit_cpy_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) { - if (emit->pass == PASS_3) { - const char *str = qstr_str(qstr); - int len = strlen(str); - bool has_single_quote = false; - bool has_double_quote = false; - for (int i = 0; i < len; i++) { - if (str[i] == '\'') { - has_single_quote = true; - } else if (str[i] == '"') { - has_double_quote = true; - } - } - if (bytes) { - printf("b"); - } - bool quote_single = false; - if (has_single_quote && !has_double_quote) { - printf("\""); - } else { - quote_single = true; - printf("'"); - } - for (int i = 0; i < len; i++) { - if (str[i] == '\n') { - printf("\\n"); - } else if (str[i] == '\\') { - printf("\\\\"); - } else if (str[i] == '\'' && quote_single) { - printf("\\'"); - } else { - printf("%c", str[i]); - } - } - if (has_single_quote && !has_double_quote) { - printf("\""); - } else { - printf("'"); - } - } -} - -static void emit_cpy_load_const_verbatim_end(emit_t *emit) { - if (emit->pass == PASS_3) { - printf("\n"); + printf("LOAD_CONST %s\n", str); } } @@ -845,12 +816,7 @@ const emit_method_table_t emit_cpython_method_table = { emit_cpy_load_const_dec, emit_cpy_load_const_id, emit_cpy_load_const_str, - emit_cpy_load_const_verbatim_start, - emit_cpy_load_const_verbatim_int, emit_cpy_load_const_verbatim_str, - emit_cpy_load_const_verbatim_strn, - emit_cpy_load_const_verbatim_quoted_str, - emit_cpy_load_const_verbatim_end, emit_cpy_load_fast, emit_cpy_load_deref, emit_cpy_load_closure, diff --git a/py/emitnative.c b/py/emitnative.c index 29acee9e8..17d217c97 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -629,36 +629,11 @@ static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) { } } -static void emit_native_load_const_verbatim_start(emit_t *emit) { - // not supported/needed for viper - assert(0); -} - -static void emit_native_load_const_verbatim_int(emit_t *emit, int val) { - // not supported/needed for viper - assert(0); -} - static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) { // not supported/needed for viper assert(0); } -static void emit_native_load_const_verbatim_strn(emit_t *emit, const char *str, int len) { - // not supported/needed for viper - assert(0); -} - -static void emit_native_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) { - // not supported/needed for viper - assert(0); -} - -static void emit_native_load_const_verbatim_end(emit_t *emit) { - // not supported/needed for viper - assert(0); -} - static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) { vtype_kind_t vtype = emit->local_vtype[local_num]; if (vtype == VTYPE_UNBOUND) { @@ -1273,12 +1248,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = { emit_native_load_const_dec, emit_native_load_const_id, emit_native_load_const_str, - emit_native_load_const_verbatim_start, - emit_native_load_const_verbatim_int, emit_native_load_const_verbatim_str, - emit_native_load_const_verbatim_strn, - emit_native_load_const_verbatim_quoted_str, - emit_native_load_const_verbatim_end, emit_native_load_fast, emit_native_load_deref, emit_native_load_closure, diff --git a/py/emitpass1.c b/py/emitpass1.c index f14ccc511..5526c2d5d 100644 --- a/py/emitpass1.c +++ b/py/emitpass1.c @@ -188,9 +188,4 @@ const emit_method_table_t emit_pass1_method_table = { (void*)emit_pass1_dummy, (void*)emit_pass1_dummy, (void*)emit_pass1_dummy, - (void*)emit_pass1_dummy, - (void*)emit_pass1_dummy, - (void*)emit_pass1_dummy, - (void*)emit_pass1_dummy, - (void*)emit_pass1_dummy, };