|
1 | 1 | import re
|
2 | 2 | from collections import defaultdict
|
3 | 3 | from itertools import chain, count
|
4 |
| -from string import capwords |
| 4 | +from string import capwords, ascii_uppercase as letters |
5 | 5 |
|
6 | 6 | try:
|
7 | 7 | from . import Errors
|
@@ -86,11 +86,14 @@ def __init__(self, tree, indent_size=3):
|
86 | 86 | self.tree = tree
|
87 | 87 | self.indent_size = indent_size
|
88 | 88 | self.indent_level = 0
|
89 |
| - # Reserved: |
| 89 | + # Reserved Global Indices |
90 | 90 | # 0: Map ID
|
91 | 91 | self.global_reserved = 1
|
92 | 92 | self.global_index = count(self.global_reserved)
|
93 | 93 | self.player_index = count()
|
| 94 | + self.global_varconst = iter(letters[1:]) |
| 95 | + self.player_varconst = iter(letters[1:]) |
| 96 | + self.varconsts = {} |
94 | 97 | self.curblock = []
|
95 | 98 |
|
96 | 99 | @property
|
@@ -181,10 +184,31 @@ def visitOWID(self, node, scope):
|
181 | 184 | raise Errors.SyntaxError('\'{}\' expected {} arguments ({}), received {}'.format(
|
182 | 185 | name, len(node.args), ', '.join(map(lambda arg: arg.__name__, node.args)), len(node.children)),
|
183 | 186 | pos=node._pos)
|
184 |
| - for index, types in enumerate(zip(node.args, node.children)): |
| 187 | + else: |
| 188 | + pass #wait shorthand |
| 189 | + for index, types in enumerate(zip(node.args, node.children[:])): |
185 | 190 | arg, child = types
|
186 | 191 | if arg is None:
|
187 | 192 | continue
|
| 193 | + elif arg == Variable: |
| 194 | + try: |
| 195 | + assert type(child) in (GlobalVar, PlayerVar) |
| 196 | + if child.name not in self.varconsts: |
| 197 | + constgen = self.global_varconst if type(child) == GlobalVar else self.player_varconst |
| 198 | + try: |
| 199 | + varconst = next(constgen) |
| 200 | + self.varconsts[child.name] = Raw(code=varconst) |
| 201 | + if type(child) == GlobalVar: |
| 202 | + code = 'Set Global Variable({}, {});\n'.format(varconst, self.visit(child, scope)) + code |
| 203 | + else: |
| 204 | + code = 'Set Player Variable({}, {}, {});\n'.format(self.visit(child.player, varconst, self.visit(child, scope))) + code |
| 205 | + except StopIteration: |
| 206 | + raise Errors.InvalidParameter('Exceeded maximum number of chase variables (25) for this type.', pos=child._pos) |
| 207 | + node.children[index] = self.varconsts[child.name] |
| 208 | + except AssertionError: |
| 209 | + raise Errors.InvalidParameter('Expected variable in chase variable expression, received {}'.format( |
| 210 | + child.__class__.__name__), pos=child._pos) |
| 211 | + continue |
188 | 212 | extends = arg._extends if hasattr(arg, '_extends') else []
|
189 | 213 | values = list(flatten(arg.get_values()))
|
190 | 214 | if 'ANY' in values:
|
|
0 commit comments