From 1d7a3c6444eab5a02d899f789f2a57cfdcbc5a84 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 30 Sep 2017 18:02:35 -0400 Subject: [PATCH] Document hacky customize arg count better. --- uncompyle6/parser.py | 18 ++++++++++++------ uncompyle6/scanners/scanner2.py | 10 ++++++++-- uncompyle6/scanners/scanner3.py | 8 ++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 1cb57371..ee18b737 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -44,21 +44,25 @@ class PythonParser(GenericASTBuilder): else: return self.ast_first_offset(ast[0]) - def add_unique_rule(self, rule, opname, count, customize): + def add_unique_rule(self, rule, opname, arg_count, customize): """Add rule to grammar, but only if it hasn't been added previously - opname and count are used in the customize() semantic the actions - to add the semantic action rule. Often, count is not used. + opname and stack_count are used in the customize() semantic + the actions to add the semantic action rule. Stack_count is + used in custom opcodes like MAKE_FUNCTION to indicate how + many arguments it has. Often it is not used. """ if rule not in self.new_rules: # print("XXX ", rule) # debug self.new_rules.add(rule) self.addRule(rule, nop_func) - customize[opname] = count + customize[opname] = arg_count pass return def add_unique_rules(self, rules, customize): - """Add rules (a list of string) to grammar + """Add rules (a list of string) to grammar. Note that + the rules must not be those that set arg_count in the + custom dictionary. """ for rule in rules: if len(rule) == 0: @@ -68,7 +72,9 @@ class PythonParser(GenericASTBuilder): return def add_unique_doc_rules(self, rules_str, customize): - """Add rules (a docstring-like list of rules) to grammar + """Add rules (a docstring-like list of rules) to grammar. + Note that the rules must not be those that set arg_count in the + custom dictionary. """ rules = [r.strip() for r in rules_str.split("\n")] self.add_unique_rules(rules, customize) diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index 66957a47..9c2d62b0 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -93,12 +93,18 @@ class Scanner2(Scanner): for instr in bytecode.get_instructions(co): print(instr._disassemble()) - # Container for tokens + # list of tokens/instructions tokens = [] + # "customize" is a dict whose keys are nonterminals + # and the value is the argument stack entries for that + # nonterminal. The count is a little hoaky. It is mostly + # not used, but sometimes it is. + # "customize" is a dict whose keys are nonterminals customize = {} + if self.is_pypy: - customize['PyPy'] = 1 + customize['PyPy'] = 0 Token = self.Token # shortcut diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 5beedb0e..c006dfc4 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -169,12 +169,16 @@ class Scanner3(Scanner): for instr in bytecode.get_instructions(co): print(instr._disassemble()) - # Container for tokens + # list of tokens/instructions tokens = [] + # "customize" is a dict whose keys are nonterminals + # and the value is the argument stack entries for that + # nonterminal. The count is a little hoaky. It is mostly + # not used, but sometimes it is. customize = {} if self.is_pypy: - customize['PyPy'] = 1 + customize['PyPy'] = 0 self.code = array('B', co.co_code) self.build_lines_data(co)