Skip to content

Commit a1b2693

Browse files
committed
py: remove further unnecessary emit_verbatim code.
1 parent e388f10 commit a1b2693

File tree

6 files changed

+44
-149
lines changed

6 files changed

+44
-149
lines changed

py/compile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ static void cpython_c_tuple(compiler_t *comp, py_parse_node_t pn, py_parse_node_
383383
} else {
384384
vstr_printf(vstr, ")");
385385
}
386-
EMIT(load_const_verbatim_start);
387386
EMIT(load_const_verbatim_str, vstr_str(vstr));
388-
EMIT(load_const_verbatim_end);
389387
vstr_free(vstr);
390388
} else {
391389
if (!PY_PARSE_NODE_IS_NULL(pn)) {
@@ -1221,9 +1219,7 @@ void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) {
12211219

12221220
// build the "fromlist" tuple
12231221
#if MICROPY_EMIT_CPYTHON
1224-
EMIT(load_const_verbatim_start);
12251222
EMIT(load_const_verbatim_str, "('*',)");
1226-
EMIT(load_const_verbatim_end);
12271223
#else
12281224
EMIT(load_const_str, qstr_from_str_static("*"), false);
12291225
EMIT(build_tuple, 1);
@@ -1259,9 +1255,7 @@ void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) {
12591255
vstr_printf(vstr, ",");
12601256
}
12611257
vstr_printf(vstr, ")");
1262-
EMIT(load_const_verbatim_start);
12631258
EMIT(load_const_verbatim_str, vstr_str(vstr));
1264-
EMIT(load_const_verbatim_end);
12651259
vstr_free(vstr);
12661260
}
12671261
#else

py/emit.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ typedef struct _emit_method_table_t {
3838
void (*load_const_dec)(emit_t *emit, qstr qstr);
3939
void (*load_const_id)(emit_t *emit, qstr qstr);
4040
void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes);
41-
void (*load_const_verbatim_start)(emit_t *emit);
42-
void (*load_const_verbatim_int)(emit_t *emit, int val);
43-
void (*load_const_verbatim_str)(emit_t *emit, const char *str);
44-
void (*load_const_verbatim_strn)(emit_t *emit, const char *str, int len);
45-
void (*load_const_verbatim_quoted_str)(emit_t *emit, qstr qstr, bool bytes);
46-
void (*load_const_verbatim_end)(emit_t *emit);
41+
void (*load_const_verbatim_str)(emit_t *emit, const char *str); // only needed for emitcpy
4742
void (*load_fast)(emit_t *emit, qstr qstr, int local_num);
4843
void (*load_deref)(emit_t *emit, qstr qstr, int local_num);
4944
void (*load_closure)(emit_t *emit, qstr qstr, int local_num);

py/emitbc.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,28 +266,8 @@ static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
266266
}
267267
}
268268

269-
static void emit_bc_load_const_verbatim_start(emit_t *emit) {
270-
emit_pre(emit, 1);
271-
assert(0);
272-
}
273-
274-
static void emit_bc_load_const_verbatim_int(emit_t *emit, int val) {
275-
assert(0);
276-
}
277-
278269
static void emit_bc_load_const_verbatim_str(emit_t *emit, const char *str) {
279-
assert(0);
280-
}
281-
282-
static void emit_bc_load_const_verbatim_strn(emit_t *emit, const char *str, int len) {
283-
assert(0);
284-
}
285-
286-
static void emit_bc_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) {
287-
assert(0);
288-
}
289-
290-
static void emit_bc_load_const_verbatim_end(emit_t *emit) {
270+
// not needed/supported for BC
291271
assert(0);
292272
}
293273

@@ -718,12 +698,7 @@ const emit_method_table_t emit_bc_method_table = {
718698
emit_bc_load_const_dec,
719699
emit_bc_load_const_id,
720700
emit_bc_load_const_str,
721-
emit_bc_load_const_verbatim_start,
722-
emit_bc_load_const_verbatim_int,
723701
emit_bc_load_const_verbatim_str,
724-
emit_bc_load_const_verbatim_strn,
725-
emit_bc_load_const_verbatim_quoted_str,
726-
emit_bc_load_const_verbatim_end,
727702
emit_bc_load_fast,
728703
emit_bc_load_deref,
729704
emit_bc_load_closure,

py/emitcpy.c

Lines changed: 42 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ struct _emit_t {
2828
int *label_offsets;
2929
};
3030

31-
// forward declaration
32-
static void emit_cpy_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes);
33-
3431
emit_t *emit_cpython_new(uint max_num_labels) {
3532
emit_t *emit = m_new(emit_t, 1);
3633
emit->max_num_labels = max_num_labels;
@@ -176,85 +173,59 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
176173
}
177174
}
178175

179-
static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
180-
emit_pre(emit, 1, 3);
181-
if (emit->pass == PASS_3) {
182-
printf("LOAD_CONST ");
183-
emit_cpy_load_const_verbatim_quoted_str(emit, qstr, bytes);
184-
printf("\n");
176+
static void print_quoted_str(qstr qstr, bool bytes) {
177+
const char *str = qstr_str(qstr);
178+
int len = strlen(str);
179+
bool has_single_quote = false;
180+
bool has_double_quote = false;
181+
for (int i = 0; i < len; i++) {
182+
if (str[i] == '\'') {
183+
has_single_quote = true;
184+
} else if (str[i] == '"') {
185+
has_double_quote = true;
186+
}
187+
}
188+
if (bytes) {
189+
printf("b");
190+
}
191+
bool quote_single = false;
192+
if (has_single_quote && !has_double_quote) {
193+
printf("\"");
194+
} else {
195+
quote_single = true;
196+
printf("'");
197+
}
198+
for (int i = 0; i < len; i++) {
199+
if (str[i] == '\n') {
200+
printf("\\n");
201+
} else if (str[i] == '\\') {
202+
printf("\\\\");
203+
} else if (str[i] == '\'' && quote_single) {
204+
printf("\\'");
205+
} else {
206+
printf("%c", str[i]);
207+
}
208+
}
209+
if (has_single_quote && !has_double_quote) {
210+
printf("\"");
211+
} else {
212+
printf("'");
185213
}
186214
}
187215

188-
static void emit_cpy_load_const_verbatim_start(emit_t *emit) {
216+
static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
189217
emit_pre(emit, 1, 3);
190218
if (emit->pass == PASS_3) {
191219
printf("LOAD_CONST ");
192-
}
193-
}
194-
195-
static void emit_cpy_load_const_verbatim_int(emit_t *emit, int val) {
196-
if (emit->pass == PASS_3) {
197-
printf("%d", val);
220+
print_quoted_str(qstr, bytes);
221+
printf("\n");
198222
}
199223
}
200224

201225
static void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
226+
emit_pre(emit, 1, 3);
202227
if (emit->pass == PASS_3) {
203-
printf("%s", str);
204-
}
205-
}
206-
207-
static void emit_cpy_load_const_verbatim_strn(emit_t *emit, const char *str, int len) {
208-
if (emit->pass == PASS_3) {
209-
printf("%.*s", len, str);
210-
}
211-
}
212-
213-
static void emit_cpy_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) {
214-
if (emit->pass == PASS_3) {
215-
const char *str = qstr_str(qstr);
216-
int len = strlen(str);
217-
bool has_single_quote = false;
218-
bool has_double_quote = false;
219-
for (int i = 0; i < len; i++) {
220-
if (str[i] == '\'') {
221-
has_single_quote = true;
222-
} else if (str[i] == '"') {
223-
has_double_quote = true;
224-
}
225-
}
226-
if (bytes) {
227-
printf("b");
228-
}
229-
bool quote_single = false;
230-
if (has_single_quote && !has_double_quote) {
231-
printf("\"");
232-
} else {
233-
quote_single = true;
234-
printf("'");
235-
}
236-
for (int i = 0; i < len; i++) {
237-
if (str[i] == '\n') {
238-
printf("\\n");
239-
} else if (str[i] == '\\') {
240-
printf("\\\\");
241-
} else if (str[i] == '\'' && quote_single) {
242-
printf("\\'");
243-
} else {
244-
printf("%c", str[i]);
245-
}
246-
}
247-
if (has_single_quote && !has_double_quote) {
248-
printf("\"");
249-
} else {
250-
printf("'");
251-
}
252-
}
253-
}
254-
255-
static void emit_cpy_load_const_verbatim_end(emit_t *emit) {
256-
if (emit->pass == PASS_3) {
257-
printf("\n");
228+
printf("LOAD_CONST %s\n", str);
258229
}
259230
}
260231

@@ -845,12 +816,7 @@ const emit_method_table_t emit_cpython_method_table = {
845816
emit_cpy_load_const_dec,
846817
emit_cpy_load_const_id,
847818
emit_cpy_load_const_str,
848-
emit_cpy_load_const_verbatim_start,
849-
emit_cpy_load_const_verbatim_int,
850819
emit_cpy_load_const_verbatim_str,
851-
emit_cpy_load_const_verbatim_strn,
852-
emit_cpy_load_const_verbatim_quoted_str,
853-
emit_cpy_load_const_verbatim_end,
854820
emit_cpy_load_fast,
855821
emit_cpy_load_deref,
856822
emit_cpy_load_closure,

py/emitnative.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -629,36 +629,11 @@ static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
629629
}
630630
}
631631

632-
static void emit_native_load_const_verbatim_start(emit_t *emit) {
633-
// not supported/needed for viper
634-
assert(0);
635-
}
636-
637-
static void emit_native_load_const_verbatim_int(emit_t *emit, int val) {
638-
// not supported/needed for viper
639-
assert(0);
640-
}
641-
642632
static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
643633
// not supported/needed for viper
644634
assert(0);
645635
}
646636

647-
static void emit_native_load_const_verbatim_strn(emit_t *emit, const char *str, int len) {
648-
// not supported/needed for viper
649-
assert(0);
650-
}
651-
652-
static void emit_native_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) {
653-
// not supported/needed for viper
654-
assert(0);
655-
}
656-
657-
static void emit_native_load_const_verbatim_end(emit_t *emit) {
658-
// not supported/needed for viper
659-
assert(0);
660-
}
661-
662637
static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
663638
vtype_kind_t vtype = emit->local_vtype[local_num];
664639
if (vtype == VTYPE_UNBOUND) {
@@ -1273,12 +1248,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
12731248
emit_native_load_const_dec,
12741249
emit_native_load_const_id,
12751250
emit_native_load_const_str,
1276-
emit_native_load_const_verbatim_start,
1277-
emit_native_load_const_verbatim_int,
12781251
emit_native_load_const_verbatim_str,
1279-
emit_native_load_const_verbatim_strn,
1280-
emit_native_load_const_verbatim_quoted_str,
1281-
emit_native_load_const_verbatim_end,
12821252
emit_native_load_fast,
12831253
emit_native_load_deref,
12841254
emit_native_load_closure,

py/emitpass1.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,4 @@ const emit_method_table_t emit_pass1_method_table = {
188188
(void*)emit_pass1_dummy,
189189
(void*)emit_pass1_dummy,
190190
(void*)emit_pass1_dummy,
191-
(void*)emit_pass1_dummy,
192-
(void*)emit_pass1_dummy,
193-
(void*)emit_pass1_dummy,
194-
(void*)emit_pass1_dummy,
195-
(void*)emit_pass1_dummy,
196191
};

0 commit comments

Comments
 (0)