5
5
import arc .scene .ui .layout .Table ;
6
6
import arc .struct .Seq ;
7
7
import mindustry .gen .LogicIO ;
8
- import mindustry .logic .ConditionOp ;
9
8
import mindustry .logic .LAssembler ;
10
9
import mindustry .logic .LCategory ;
11
10
import mindustry .logic .LExecutor ;
12
11
import mindustry .logic .LStatement ;
13
- import mindustry .logic .LVar ;
14
12
import mindustry .ui .Styles ;
15
13
16
14
public class AssertLStatements {
@@ -32,14 +30,13 @@ public static void register() {
32
30
}
33
31
34
32
private static class AssertStatement extends LStatement {
35
- private static final ConditionOp [] conditions = {ConditionOp .lessThan , ConditionOp .lessThanEq };
36
-
33
+ public TypeAssertion type = TypeAssertion .integer ;
37
34
public String min = "0" ;
38
- public ConditionOp opMin = ConditionOp .lessThanEq ;
35
+ public AssertOp opMin = AssertOp .lessThanEq ;
39
36
public String value = "index" ;
40
- public ConditionOp opMax = ConditionOp .lessThanEq ;
41
- public String max = "length " ;
42
- public String message = "\" Array index '%s' out of bounds (%d to %d) \" " ;
37
+ public AssertOp opMax = AssertOp .lessThanEq ;
38
+ public String max = "10 " ;
39
+ public String message = "\" Array index out of bounds (0 to 10). \" " ;
43
40
44
41
@ Override
45
42
public LCategory category () {
@@ -53,22 +50,35 @@ public void build(Table t) {
53
50
t .add ("invariant: " ).padLeft (6 );
54
51
t .table (table -> {
55
52
table .color .set (category ().color );
56
- field (table , min , str -> min = str ).left ();
53
+ table .add ("type " );
54
+ table .button (b -> {
55
+ b .label (() -> type .name ());
56
+ b .clicked (() -> showSelect (b , TypeAssertion .all , type , o -> {
57
+ type = o ;
58
+ build (t );
59
+ }, 2 , cell -> cell .size (110 , 50 )));
60
+ }, Styles .logict , () -> {}).size (110 , 40 ).left ().pad (4f ).color (table .color );
61
+ table .add ("bounds " );
62
+ numField (table , min , str -> min = str );
57
63
opButton (t , table , opMin , o -> opMin = o );
58
- field (table , value , str -> value = str ). left ( );
64
+ numField (table , value , str -> value = str );
59
65
opButton (t , table , opMax , o -> opMax = o );
60
- field (table , max , str -> max = str ). left ( );
66
+ numField (table , max , str -> max = str );
61
67
table .add ("" ).growX ();
62
68
});
63
69
t .row ();
64
70
t .add ("message: " ).padLeft (6 );
65
71
field (t , message , str -> message = str ).width (0f ).growX ().padRight (3 );
66
72
}
67
73
68
- void opButton (Table parent , Table table , ConditionOp op , Cons <ConditionOp > getter ) {
74
+ void numField (Table table , String num , Cons <String > getter ) {
75
+ field (table , num , getter ).width (120 ).left ();
76
+ }
77
+
78
+ void opButton (Table parent , Table table , AssertOp op , Cons <AssertOp > getter ) {
69
79
table .button (b -> {
70
80
b .label (() -> op .symbol );
71
- b .clicked (() -> showSelect (b , conditions , op , o -> {
81
+ b .clicked (() -> showSelect (b , AssertOp . all , op , o -> {
72
82
getter .get (o );
73
83
build (parent );
74
84
}));
@@ -78,14 +88,15 @@ void opButton(Table parent, Table table, ConditionOp op, Cons<ConditionOp> gette
78
88
79
89
@ Override
80
90
public LExecutor .LInstruction build (LAssembler builder ) {
81
- return new AssertsLInstructions .AssertI (builder .var (min ), opMin , builder .var (value ),
91
+ return new AssertsLInstructions .AssertI (type , builder .var (min ), opMin , builder .var (value ),
82
92
opMax , builder .var (max ), builder .var (message ));
83
93
}
84
94
85
95
@ Override
86
96
public final void write (StringBuilder builder ) {
87
97
writer .start (builder );
88
98
writer .write (opcode );
99
+ writer .write (type .name ());
89
100
writer .write (min );
90
101
writer .write (opMin .name ());
91
102
writer .write (value );
@@ -96,12 +107,14 @@ public final void write(StringBuilder builder) {
96
107
}
97
108
98
109
public LStatement read (String [] tokens ) {
99
- if (tokens .length > 1 ) min = tokens [1 ];
100
- if (tokens .length > 2 ) opMin = mindustry .logic .ConditionOp .valueOf (tokens [2 ]);
101
- if (tokens .length > 3 ) value = tokens [3 ];
102
- if (tokens .length > 4 ) opMax = mindustry .logic .ConditionOp .valueOf (tokens [4 ]);
103
- if (tokens .length > 5 ) max = tokens [5 ];
104
- if (tokens .length > 6 ) message = tokens [6 ];
110
+ int i = 1 ;
111
+ if (tokens .length > i ) type = TypeAssertion .valueOf (tokens [i ++]);
112
+ if (tokens .length > i ) min = tokens [i ++];
113
+ if (tokens .length > i ) opMin = AssertOp .valueOf (tokens [i ++]);
114
+ if (tokens .length > i ) value = tokens [i ++];
115
+ if (tokens .length > i ) opMax = AssertOp .valueOf (tokens [i ++]);
116
+ if (tokens .length > i ) max = tokens [i ++];
117
+ if (tokens .length > i ) message = tokens [i ++];
105
118
return this ;
106
119
}
107
120
0 commit comments