Skip to content

Commit

Permalink
Misc small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Oct 14, 2019
1 parent 764ce6a commit e0dfea6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lapdecompile/bb.py
Expand Up @@ -360,7 +360,8 @@ def ingest(bblocks, instructions, show_assembly):
# then parsing will pick up the parameters from instruction where the stacking occurs
# Testing on RETURN is kind of a hack.
if (stack_effect < 0 and not
(inst.kind.startswith("CALL_") or inst.kind == "RETURN")):
(inst.kind.startswith("CALL_") or inst.kind in
("DISCARD", "RETURN", "UNBIND"))):
for j in range(stack_effect, 0):
new_instructions.append(Token("STACK-ACCESS", -j, offset))
stack_effect = 0
Expand Down
14 changes: 9 additions & 5 deletions lapdecompile/parser.py
Expand Up @@ -73,7 +73,7 @@ def p_elisp_grammar(self, args):
# expr_stmt is an expr where the value it produces
# might not be needed. List-like things like
# progn or let fall into this category.
# expr_stmt's are maximimal in that the instruction after
# expr_stmt's are maximal in that the instruction after
# the expr_stmt doesn't consume it unless it is consumed
# for control-flow decision.
# For example "constant" is an "expr', but not an
Expand Down Expand Up @@ -258,18 +258,18 @@ def p_elisp_grammar(self, args):
not_expr ::= expr GOTO-IF-NOT-NIL
and_form ::= expr GOTO-IF-NIL-ELSE-POP expr opt_come_from opt_label
and_form ::= expr GOTO-IF-NIL expr opt_comp_from opt_label
and_form ::= expr GOTO-IF-NIL expr opt_come_from opt_label
expr_or_stacked ::= expr
expr_or_stacked ::= STACK-ACCESS
expr ::= call_exprn
expr ::= call_expr0
expr ::= call_expr1
expr ::= call_expr2
expr ::= call_expr3
expr ::= call_expr4
expr ::= call_expr5
expr ::= call_expr9
call_expr0 ::= name_expr CALL_0
call_expr1 ::= name_expr expr_or_stacked CALL_1
call_expr2 ::= name_expr expr_or_stacked expr_or_stacked CALL_2
Expand All @@ -278,6 +278,9 @@ def p_elisp_grammar(self, args):
expr_or_stacked CALL_4
call_expr5 ::= name_expr expr_or_stacked expr_or_stacked expr_or_stacked
expr_or_stacked expr_or_stacked CALL_5
call_expr9 ::= name_expr expr_or_stacked expr_or_stacked expr_or_stacked
expr_or_stacked expr_or_stacked expr_or_stacked expr_or_stacked expr_or_stacked
expr_or_stacked CALL_9
name_expr ::= CONSTANT
Expand Down Expand Up @@ -351,7 +354,7 @@ def p_elisp_grammar(self, args):
unary_op ::= THREADP
unary_op ::= TYPE-OF
unary_op ::= USER-PTRP
unary_op ::= VECTOR_OR_CHAR-TABLEP
unary_op ::= VECTOR-OR-CHAR-TABLEP
unary_op ::= VECTORP
nullary_expr ::= nullary_op
Expand All @@ -371,6 +374,7 @@ def p_elisp_grammar(self, args):
pop_expr ::= VARREF DUP CDR VARSET CAR-SAFE
setq_form ::= expr VARSET
setq_form ::= expr STACK-ACCESS VARSET
setq_form_dup ::= expr DUP VARSET
setq_form_stacked ::= expr_stacked DUP VARSET
setq_form_stacking ::= expr DUP VARSET
Expand Down Expand Up @@ -469,7 +473,7 @@ def add_unique_rule(self, rule, opname):

def add_custom_rules(self, tokens, customize):
for opname, v in customize.items():
if re.match(r"^LIST|CONCAT|CALL", opname):
if re.match(r"^LIST|CONCAT", opname):
opname_base = opname[:opname.index('_')]
if opname_base[-1] == 'N':
opname_base = opname_base[:-1]
Expand Down
3 changes: 3 additions & 0 deletions lapdecompile/scanner.py
Expand Up @@ -97,6 +97,9 @@ def fn_scanner_internal(self, name, fn_type):
label = None
while self.cur_index < self.line_count:
line = self.lines[self.cur_index]
if line.startswith("#"):
self.cur_index += 1
continue
fields = line.split()
if len(fields) == 0:
break
Expand Down
2 changes: 1 addition & 1 deletion lapdecompile/semantics.py
Expand Up @@ -402,7 +402,7 @@ def n_call_expr1(self, node):
args = node[-1].attr
self.template_engine(("(%p%Q %l%P)", 0, 0, (1, args + 1), 1), node)
self.prune()
n_call_expr2 = n_call_expr3 = n_call_expr4 = n_call_expr5 = n_call_expr1
n_call_expr2 = n_call_expr3 = n_call_expr4 = n_call_expr5 = n_call_expr9 = n_call_expr1

def n_let_form_star(self, node):
if node[0] == "varlist" and len(node[0]) == 1:
Expand Down

0 comments on commit e0dfea6

Please sign in to comment.