Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Support for parameters in switches #155

Open
wants to merge 4 commits into
base: master
from

Conversation

@glx22
Copy link
Contributor

glx22 commented Jun 2, 2020

New syntax, compatible with old one:

switch (<feature>, (SELF|PARENT), <ID>(, <param_name>)*, <expression>) {
	(<range>: <return_value>;)*
	<return_value>;
}
@glx22 glx22 force-pushed the glx22:switch_param branch from 42b98e4 to 77e62da Jun 5, 2020
@glx22
Copy link
Contributor Author

glx22 commented Jun 5, 2020

It's rebased on top of #156 for easier testing

@andythenorth
Copy link
Contributor

andythenorth commented Jun 5, 2020

Works for me in Iron Horse.

@glx22 glx22 force-pushed the glx22:switch_param branch 2 times, most recently from 0ecc64c to 6816a40 Jun 6, 2020
assert self.num_refs == 0, "Action2 reference counting has {:d} dangling references.".format(self.num_refs)
file.comment("Name: " + self.name)
for c in extra_comment: file.comment(c)

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

newline here please, this isn't C++ :)

@@ -101,9 +101,10 @@ def prepare_output(self, sprite_num):
except IndexError:
raise generic.ScriptError("Unable to allocate ID for [random]switch, sprite set/layout/group or produce-block. Try reducing the number of such blocks.", self.pos)

def write_sprite_start(self, file, size):
def write_sprite_start(self, file, size, extra_comment = []):

This comment has been minimized.

This comment has been minimized.

Copy link
@glx22

glx22 Jul 5, 2020

Author Contributor

Hmm, I did it like it's done in other locations. I guess all the code needs to be checked for this issue.

@@ -38,14 +38,21 @@ class Action2Var(action2.Action2):
action2.
@ivar ranges: C{list} of L{VarAction2Range}
"""
def __init__(self, feature, name, pos, type_byte):
def __init__(self, feature, name, pos, type_byte, param_registers = []):

This comment has been minimized.

self.var_list.append(nmlop.VAL2)
self.var_list_size += 1
if refs != [expr]:
# With imbricated calls param registers can be overwritten

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

imbricated?

This comment has been minimized.

Copy link
@glx22

glx22 Jul 5, 2020

Author Contributor

I couldn't find another word. What I mean is for f(x, g(y)), x can be overwritten by y if f and g share the same param registers.

# Fill param registers for the call
tmp_vars = []
for i, param in enumerate(expr.param_list):
if i > 0:

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

not immediately clear why i == 0 is special, comment?

@@ -28,7 +28,7 @@
class Switch(switch_base_class):
def __init__(self, param_list, body, pos):
base_statement.BaseStatement.__init__(self, "switch-block", pos, False, False)
if len(param_list) != 4:
if len(param_list) < 4:
raise generic.ScriptError("Switch-block requires 4 parameters, encountered " + str(len(param_list)), pos)

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

4 or more parameters?

@@ -89,17 +117,17 @@ def __init__(self, ranges, default):
self.ranges = ranges
self.default = default

def reduce_expressions(self, var_feature):
def reduce_expressions(self, var_feature, extra_dicts = []):

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

and here

@@ -122,11 +150,11 @@ def __init__(self, min, max, result, unit = None):
self.result = result
self.unit = unit

def reduce_expressions(self, var_feature):
def reduce_expressions(self, var_feature, extra_dicts = []):

This comment has been minimized.

Copy link
@LordAro

LordAro Jul 5, 2020

Member

and here

@glx22 glx22 force-pushed the glx22:switch_param branch from 6816a40 to e22958c Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.