Skip to content

Commit 39b465c

Browse files
committed
py/compile2: Optimise emitter label indices to save a word of heap.
A port of d94bc67
1 parent 20f1bd0 commit 39b465c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

py/compile2.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
// TODO need to mangle __attr names
4545

46+
#define INVALID_LABEL (0xffff)
47+
4648
typedef enum {
4749
// define rules with a compile function
4850
#define DEF_RULE(rule, comp, kind, ...) PN_##rule,
@@ -959,7 +961,7 @@ STATIC void compile_del_stmt(compiler_t *comp, const byte *p, const byte *ptop)
959961

960962
STATIC void compile_break_stmt(compiler_t *comp, const byte *p, const byte *ptop) {
961963
(void)ptop;
962-
if (comp->break_label == 0) {
964+
if (comp->break_label == INVALID_LABEL) {
963965
compile_syntax_error(comp, p, "'break' outside loop");
964966
}
965967
assert(comp->cur_except_level >= comp->break_continue_except_level);
@@ -968,7 +970,7 @@ STATIC void compile_break_stmt(compiler_t *comp, const byte *p, const byte *ptop
968970

969971
STATIC void compile_continue_stmt(compiler_t *comp, const byte *p, const byte *ptop) {
970972
(void)ptop;
971-
if (comp->continue_label == 0) {
973+
if (comp->continue_label == INVALID_LABEL) {
972974
compile_syntax_error(comp, p, "'continue' outside loop");
973975
}
974976
assert(comp->cur_except_level >= comp->break_continue_except_level);
@@ -2840,7 +2842,7 @@ STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) {
28402842
STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
28412843
comp->pass = pass;
28422844
comp->scope_cur = scope;
2843-
comp->next_label = 1;
2845+
comp->next_label = 0;
28442846
EMIT_ARG(start_pass, pass, scope);
28452847

28462848
if (comp->pass == MP_PASS_SCOPE) {
@@ -3019,7 +3021,7 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
30193021
STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
30203022
comp->pass = pass;
30213023
comp->scope_cur = scope;
3022-
comp->next_label = 1;
3024+
comp->next_label = 0;
30233025

30243026
if (scope->kind != SCOPE_FUNCTION) {
30253027
compile_syntax_error(comp, NULL, "inline assembler must be a function");
@@ -3273,6 +3275,8 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
32733275
comp->source_file = source_file;
32743276
comp->is_repl = is_repl;
32753277
comp->co_data = parse_tree->co_data;
3278+
comp->break_label = INVALID_LABEL;
3279+
comp->continue_label = INVALID_LABEL;
32763280

32773281
// create the array of scopes
32783282
comp->num_scopes = pt_small_int_value(pt_next(parse_tree->root));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy