Commit a1b26931 authored by Damien's avatar Damien
Browse files

py: remove further unnecessary emit_verbatim code.

parent e388f103
......@@ -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
......
......@@ -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);
......
......@@ -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,
......
......@@ -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 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);
printf("\n");
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_verbatim_start(emit_t *emit) {
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 ");
}
}
static void emit_cpy_load_const_verbatim_int(emit_t *emit, int val) {
if (emit->pass == PASS_3) {
printf("%d", val);
print_quoted_str(qstr, bytes);
printf("\n");
}
}
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,
......
......@@ -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,
......
......@@ -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,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment