Skip to content

Commit

Permalink
Share action code more effectively
Browse files Browse the repository at this point in the history
Restructure action code to match equivalent code better, create
another static function to outline code and shrink binary.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Sep 27, 2021
1 parent b425a57 commit 34342a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
21 changes: 8 additions & 13 deletions snek-gram.ll
Expand Up @@ -254,6 +254,7 @@ for-stat : FOR NAME
value_push_offset(snek_code_prev_insn());
/* push 3 - while_else_stat_off */
value_push_offset(snek_code_current());
}@ @{
for_depth--;
}@
while-else-stat
Expand Down Expand Up @@ -300,10 +301,7 @@ suite : simple-stat
expr : expr-and expr-or-p
;
expr-or-p : OR
@{
snek_code_add_op_offset(snek_op_branch_true, 0);
value_push_offset(snek_compile_prev);
}@
@ bool_branch(snek_op_branch_true); @
expr-and
@ short_second(); @
expr-or-p
Expand All @@ -312,10 +310,7 @@ expr-or-p : OR
expr-and : expr-not expr-and-p
;
expr-and-p : AND
@{
snek_code_add_op_offset(snek_op_branch_false, 0);
value_push_offset(snek_compile_prev);
}@
@ bool_branch(snek_op_branch_false); @
expr-not
@ short_second(); @
expr-and-p
Expand Down Expand Up @@ -495,10 +490,10 @@ expr-prim : OP opt-tuple CP
}@
| OS opt-actuals CS
@{
snek_offset_t num = value_pop().offset;
if (num >= 256)
snek_offset_t offset = value_pop().offset;
if (offset >= 256)
return parse_return_syntax;
snek_code_add_op_offset(snek_op_list, num);
snek_code_add_op_offset(snek_op_list, offset);
}@
{SNEK_DICT
| OC
Expand All @@ -509,8 +504,8 @@ expr-prim : OP opt-tuple CP
opt-dict-ents CC
@{
/* Fetch the number of entries compiled */
snek_offset_t num = value_pop().offset;
snek_code_add_op_offset(snek_op_dict, num);
snek_offset_t offset = value_pop().offset;
snek_code_add_op_offset(snek_op_dict, offset);
}@
}
| NAME
Expand Down
6 changes: 6 additions & 0 deletions snek-parse.c
Expand Up @@ -209,6 +209,12 @@ static inline void unop_second(void)
snek_code_add_op(value_pop().op);
}

static inline void bool_branch(snek_op_t op)
{
snek_code_add_op_offset(op, 0);
value_push_offset(snek_compile_prev);
}

#define PARSE_CODE
#include "snek-gram.h"

Expand Down

0 comments on commit 34342a1

Please sign in to comment.