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

Change: Unreachable range for default only switch should target CB_FAILED #328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion nml/actions/action2var.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,20 @@ def parse_varaction2(switch_block):
# Computed result is not returned, but there are no ranges
# Add one range, to avoid the nvar == 0 bear trap
offset += 10
range_result, range_comment = parse_result(
expression.SpriteGroupRef(expression.Identifier("CB_FAILED", None), [], None),
action_list,
act6,
offset,
varaction2,
none_result,
switch_block.var_range,
)
varaction2.ranges.append(
VarAction2Range(
expression.ConstantNumeric(1),
expression.ConstantNumeric(0),
expression.ConstantNumeric(0),
range_result,
"Bogus range to avoid nvar == 0",
)
)
Expand Down
Binary file modified regression/expected/013_train_callback.grf
Binary file not shown.
18 changes: 9 additions & 9 deletions regression/expected/013_train_callback.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ FF
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_weight_switch
52 * 53 02 00 FD 89
52 * 53 02 00 FF 89
47 00 \dx000000FF
\b4
\wx8012 \dx00000013 \dx00000013 // 19 .. 19: return 18;
Expand All @@ -159,11 +159,11 @@ FF
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_name_switch
53 * 30 02 00 FF 89
53 * 30 02 00 FD 89
1A 20 \dx0000DC00
\2sto 1A 00 \dx00000100
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FD \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx8000 // default: return string(STR_JUST_STRING);

// param[125] = (param[1] * 5000)
Expand Down Expand Up @@ -263,11 +263,11 @@ FF
31 01

// Name: @action3_0
74 * 33 02 00 FD 89
74 * 33 02 00 FF 89
10 00 \dx000000FF
\b2
\wx00FE \dx00000014 \dx00000014 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000016 \dx00000016 // bulk_wagon_cb_weight_switch;
\wx00FF \dx00000016 \dx00000016 // bulk_wagon_cb_weight_switch;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_1
Expand All @@ -279,22 +279,22 @@ FF
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_2
76 * 33 02 00 FD 89
76 * 33 02 00 FF 89
0C 00 \dx0000FFFF
\b2
\wx00FE \dx00000015 \dx00000015 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000036 \dx00000036 // @action3_0;
\wx00FF \dx00000036 \dx00000036 // @action3_0;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_3
77 * 33 02 00 FC 89
0C 00 \dx0000FFFF
\b2
\wx00FB \dx00000036 \dx00000036 // @action3_1;
\wx00FF \dx00000161 \dx00000161 // bulk_wagon_cb_name_switch;
\wx00FD \dx00000161 \dx00000161 // bulk_wagon_cb_name_switch;
\wx00FC // bulk_wagon_graphics_switch;

78 * 12 03 00 01 FF \wx0074 \b1
FF \wx00FC // @action3_3;
\wx00FD // @action3_2;
\wx00FF // @action3_2;

Binary file modified regression/expected/019_switch.grf
Binary file not shown.
50 changes: 25 additions & 25 deletions regression/expected/019_switch.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,66 @@
2 * 52 08 08 "NML\19" "NML regression test" 00 "A test newgrf testing NML" 00
3 * 51 04 00 FF 03 \wxD000 "\98coal" 00 "\98diamonds" 00 "\98Extra info for coal mine: \7B" 00

// Name: @CB_FAILED_PROD
4 * 15 02 0A FF 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
5 * 23 02 0A FF 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FF // Non-graphics callback, return graphics result

// Name: return_switch
4 * 38 02 0A FF 89
6 * 38 02 0A FE 89
24 60 \dxFFFFFFFF \dxFFFFF862 \dx00000001
\2psto 1A 00 \dx00000001
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FF \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx8000 // default: return 0;

// Name: coal_mine_subtype_switch
// a : register 80
5 * 48 02 0A FF 89
7 * 48 02 0A FE 89
7D 80 20 \dxFFFFFFFF // a
\2psto 1A 20 \dx00000000
\2r 02 00 \dx000000FF
\b2
\wx8000 \dx00000000 \dx0000000A // 0 .. 10: return string(STR_COALMINE_MONTH_0_10);
\wx00FF \dx0000000D \dx0000000D // 13 .. 13: return_switch;
\wx00FE \dx0000000D \dx0000000D // 13 .. 13: return_switch;
\wx8001 // default: return string(STR_COALMINE_MONTH_11);

6 * 11 00 0A \b2 01 FF \wx0000
8 * 11 00 0A \b2 01 FF \wx0000
08 00
09 00

7 * 11 00 0A \b2 01 FF \wx0000
9 * 11 00 0A \b2 01 FF \wx0000
21 40
22 03

// Name: @return_action_0
8 * 30 02 0A FF 89
10 * 30 02 0A FE 89
1A 20 \dx00000004
\2sto 1A 00 \dx00000080
\b1
\wx00FF \dx00000000 \dx00000000 // coal_mine_subtype_switch
\wx00FF // coal_mine_subtype_switch
\wx00FE \dx00000000 \dx00000000 // coal_mine_subtype_switch
\wx00FE // coal_mine_subtype_switch

// Name: @return_action_1
9 * 13 02 0A FE 89
11 * 13 02 0A FD 89
10 00 \dx00000001
\b0
\wx8000 // Return computed value

// Name: @CB_FAILED_PROD
10 * 15 02 0A FD 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
11 * 23 02 0A FD 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FD // Non-graphics callback, return graphics result

// Name: @action3_0
12 * 43 02 0A FD 89
12 * 43 02 0A FF 89
0C 00 \dx0000FFFF
\b3
\wx00FF \dx00000037 \dx00000037 // @return_action_0;
\wx00FE \dx00000037 \dx00000037 // @return_action_0;
\wx8002 \dx0000003A \dx0000003A // return string(STR_COALMINE_EXTRA_TEXT);
\wx00FE \dx0000003B \dx0000003B // return var[0x10, 0, 1]
\wx00FD // @CB_FAILED0A;
\wx00FD \dx0000003B \dx0000003B // return var[0x10, 0, 1]
\wx00FF // @CB_FAILED0A;

13 * 7 03 0A 01 00 \b0
\wx00FD // @action3_0;
\wx00FF // @action3_0;

Binary file modified regression/expected/033_procedure.grf
Binary file not shown.
42 changes: 21 additions & 21 deletions regression/expected/033_procedure.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@
\b0
\wx8000 // Return computed value

// Name: @CB_FAILED_PROD
4 * 15 02 0A FE 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
5 * 23 02 0A FE 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FE // Non-graphics callback, return graphics result

// Name: @return_action_0
4 * 66 02 0A FE 89
6 * 66 02 0A FD 89
1A 20 \dx00000005
\2sto 1A 20 \dx00000088
\2r 7D 86 20 \dxFFFFFFFF // a
Expand All @@ -40,7 +50,7 @@

// Name: callee
// a : register 86
5 * 67 02 0A FE 89
7 * 67 02 0A FD 89
45 30 \dx00000003
\2+ 45 38 \dx0000000F
\2sto 1A 20 \dx00000087
Expand All @@ -49,11 +59,11 @@
\2* 7D 87 20 \dxFFFFFFFF
\2+ 7D 86 00 \dxFFFFFFFF // a
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FE // default: return (a + dumb_add(5, a))
\wx00FE \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FD // default: return (a + dumb_add(5, a))

// Name: caller2
6 * 232 02 0A FD 89
8 * 232 02 0A FC 89
B3 20 \dx00000003
\2+ AA 20 \dx0000FFFF
\2sto 1A 20 \dx00000080
Expand All @@ -62,7 +72,7 @@ B3 20 \dx00000003
\2sto 1A 20 \dx00000081
\2r 1A 20 \dx00000001
\2sto 1A 20 \dx00000086
\2r 7E FE 20 \dxFFFFFFFF // callee(1)
\2r 7E FD 20 \dxFFFFFFFF // callee(1)
\2+ 5F 28 \dx0000FFFF
\2sto 1A 20 \dx00000082
\2r 43 20 \dxFFFFFFFF
Expand All @@ -89,15 +99,15 @@ B3 20 \dx00000003
\wx8000 // Return computed value

// Name: caller1
7 * 145 02 0A FF 89
9 * 145 02 0A FF 89
B3 20 \dx00000003
\2+ AA 20 \dx0000FFFF
\2sto 1A 20 \dx00000080
\2r 5F 28 \dx0000FFFF
\2sto 1A 20 \dx00000081
\2r 1A 20 \dx00000000
\2sto 1A 20 \dx00000086
\2r 7E FE 20 \dxFFFFFFFF // callee(0)
\2r 7E FD 20 \dxFFFFFFFF // callee(0)
\2sto 1A 20 \dx00000082
\2r 7D 81 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000088
Expand All @@ -112,28 +122,18 @@ B3 20 \dx00000003
\b0
\wx8000 // Return computed value

8 * 11 00 0A \b2 01 FF \wx0000
10 * 11 00 0A \b2 01 FF \wx0000
08 00
09 00

9 * 9 00 0A \b1 01 FF \wx0000
11 * 9 00 0A \b1 01 FF \wx0000
22 42

// Name: @CB_FAILED_PROD
10 * 15 02 0A FE 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
11 * 23 02 0A FE 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FE // Non-graphics callback, return graphics result

// Name: @action3_0
12 * 33 02 0A FE 89
0C 00 \dx0000FFFF
\b2
\wx00FD \dx0000003B \dx0000003B // caller2;
\wx00FC \dx0000003B \dx0000003B // caller2;
\wx00FF \dx0000015F \dx0000015F // caller1;
\wx00FE // @CB_FAILED0A;

Expand Down
Binary file modified regression/expected/036_procedure_scope.grf
Binary file not shown.
Loading