Special handling for opcodes, such as those that take a variable number of arguments -- we add a new entry for each in TABLE_R.
(self, customize)
| 910 | self.prune() |
| 911 | |
| 912 | def customize(self, customize): |
| 913 | """ |
| 914 | Special handling for opcodes, such as those that take a variable number |
| 915 | of arguments -- we add a new entry for each in TABLE_R. |
| 916 | """ |
| 917 | for k, v in list(customize.items()): |
| 918 | if k in self.TABLE_R: |
| 919 | continue |
| 920 | op = k[: k.rfind("_")] |
| 921 | |
| 922 | if k.startswith("CALL_METHOD"): |
| 923 | # This happens in PyPy and Python 3.7+ |
| 924 | self.TABLE_R[k] = ("%c(%P)", (0, "expr"), (1, -1, ", ", 100)) |
| 925 | elif self.version >= (3, 6) and k.startswith("CALL_FUNCTION_KW"): |
| 926 | self.TABLE_R[k] = ("%c(%P)", (0, "expr"), (1, -1, ", ", 100)) |
| 927 | elif op == "CALL_FUNCTION": |
| 928 | self.TABLE_R[k] = ( |
| 929 | "%c(%P)", |
| 930 | (0, "expr"), |
| 931 | (1, -1, ", ", PRECEDENCE["yield"] - 1), |
| 932 | ) |
| 933 | elif op in ( |
| 934 | "CALL_FUNCTION_VAR", |
| 935 | "CALL_FUNCTION_VAR_KW", |
| 936 | "CALL_FUNCTION_KW", |
| 937 | ): |
| 938 | # FIXME: handle everything in customize. |
| 939 | # Right now, some of this is here, and some in that. |
| 940 | |
| 941 | if v == 0: |
| 942 | template_str = "%c(%C" # '%C' is a dummy here ... |
| 943 | p2 = (0, 0, None) # because of the None in this |
| 944 | else: |
| 945 | template_str = "%c(%C, " |
| 946 | p2 = (1, -2, ", ") |
| 947 | if op == "CALL_FUNCTION_VAR": |
| 948 | # Python 3.5 only puts optional args (the VAR part) |
| 949 | # the lowest down the stack |
| 950 | if self.version == (3, 5): |
| 951 | if template_str == "%c(%C, ": |
| 952 | entry = ("%c(*%C, %c)", 0, p2, -2) |
| 953 | elif template_str == "%c(%C": |
| 954 | entry = ("%c(*%C)", 0, (1, 100, "")) |
| 955 | elif self.version == (3, 4): |
| 956 | # CALL_FUNCTION_VAR's top element of the stack contains |
| 957 | # the variable argument list |
| 958 | if v == 0: |
| 959 | template_str = "%c(*%c)" |
| 960 | entry = (template_str, 0, -2) |
| 961 | else: |
| 962 | template_str = "%c(%C, *%c)" |
| 963 | entry = (template_str, 0, p2, -2) |
| 964 | else: |
| 965 | template_str += "*%c)" |
| 966 | entry = (template_str, 0, p2, -2) |
| 967 | elif op == "CALL_FUNCTION_KW": |
| 968 | template_str += "**%c)" |
| 969 | entry = (template_str, 0, p2, -2) |
no test coverage detected