You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DataExpression: Implement ternary with jumps (#740)
Avoids evaluating both the true and false branch of the ternary.
This can help if you are writing an expression where one side of the
ternary might result in an invalid array access, e.g.
```
read_mail_index < inbox.size ? inbox[read_mail_index].from : ''
```
---------
Co-authored-by: James Benton <[email protected]>
Copy file name to clipboardExpand all lines: Source/Core/DataExpression.cpp
+37-22Lines changed: 37 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,6 @@ class DataParser;
50
50
The abstract machine has three registers:
51
51
R Typically results and right-hand side arguments.
52
52
L Typically left-hand side arguments.
53
-
C Typically center arguments (eg. in ternary operator).
54
53
55
54
And a stack:
56
55
S The program stack.
@@ -64,9 +63,9 @@ class DataParser;
64
63
*/
65
64
enumclassInstruction {
66
65
// clang-format off
67
-
// Assignment (register/stack) = Read (register R/L/C, instruction data D, or stack)
66
+
// Assignment (register/stack) = Read (register R/L, instruction data D, or stack)
68
67
Push = 'P', // S+ = R
69
-
Pop = 'o', // <R/L/C> = S- (D determines R/L/C)
68
+
Pop = 'o', //<R/L> = S- (D determines R/L)
70
69
Literal = 'D', // R = D
71
70
Variable = 'V', // R = DataModel.GetVariable(D) (D is an index into the variable address list)
72
71
Add = '+', // R = L + R
@@ -82,20 +81,20 @@ enum class Instruction {
82
81
GreaterEq = 'G', // R = L >= R
83
82
Equal = '=', // R = L == R
84
83
NotEqual = 'N', // R = L != R
85
-
Ternary = '?', // R = L ? C : R
86
84
NumArguments = '#', // R = D (Contains the num. arguments currently on the stack, immediately followed by a 'T' or 'E' instruction)
87
85
TransformFnc = 'T', // R = DataModel.Execute(D, A) where A = S[TOP - R, TOP]; S -= R; (D determines function name, input R the num. arguments, A the arguments)
88
86
EventFnc = 'E', // DataModel.EventCallback(D, A); S -= R;
89
87
Assign = 'A', // DataModel.SetVariable(D, R)
90
88
DynamicVariable = 'Y', // DataModel.GetVariable(DataModel.ParseAddress(R)) (Looks up a variable by path in R)
91
-
CastToInt = 'I'// R = (int)R
89
+
CastToInt = 'I', // R = (int)R
90
+
Jump = 'J', // Jumps to instruction index D
91
+
JumpIfZero = 'Z', // If R is false, jumps to instruction index D
0 commit comments