X Tutup
Skip to content

Commit 982dd65

Browse files
committed
Adds support for unary operations
1 parent 4c3c20d commit 982dd65

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

ScriptEngine.pas

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ TSECacheMap = class(TSECacheMapAncestor)
486486
tkBegin,
487487
tkEnd,
488488
tkColon,
489+
tkQuestion,
489490
tkBracketOpen,
490491
tkBracketClose,
491492
tkNegative,
@@ -533,7 +534,7 @@ TSECacheMap = class(TSECacheMapAncestor)
533534
const
534535
TokenNames: array[TSETokenKind] of String = (
535536
'EOF', '.', '+', '-', '*', 'div', 'mod', '^', '<<', '>>', 'operator assign', '=', '!=', '<',
536-
'>', '<=', '>=', '{', '}', ':', '(', ')', 'neg', 'number', 'string',
537+
'>', '<=', '>=', '{', '}', ':', '?', '(', ')', 'neg', 'number', 'string',
537538
',', 'if', 'switch', 'case', 'default', 'identity', 'function', 'fn', 'variable', 'const', 'local',
538539
'unknown', 'else', 'while', 'break', 'continue', 'yield', 'wait',
539540
'[', ']', 'and', 'or', 'xor', 'not', 'for', 'in', 'to', 'downto', 'step', 'return',
@@ -5599,6 +5600,8 @@ procedure TEvilC.Lex(const IsIncluded: Boolean = False);
55995600
end;
56005601
':':
56015602
Token.Kind := tkColon;
5603+
'?':
5604+
Token.Kind := tkQuestion;
56025605
'''', '"':
56035606
begin
56045607
PrevQuote := C;
@@ -7294,9 +7297,29 @@ procedure TEvilC.Parse;
72947297
end;
72957298
end;
72967299

7300+
var
7301+
Expr2Block,
7302+
EndBlock,
7303+
JumpEnd,
7304+
JumpExpr2: Integer;
7305+
72977306
begin
72987307
OpCountStart := Self.OpcodeInfoList.Count;
72997308
Logic;
7309+
// Handle unary
7310+
if PeekAtNextToken.Kind = tkQuestion then
7311+
begin
7312+
NextToken;
7313+
JumpExpr2 := Emit([Pointer(opJumpEqual1), False, Pointer(0)]);
7314+
ParseExpr;
7315+
NextTokenExpected([tkColon]);
7316+
JumpEnd := Emit([Pointer(opJumpUnconditional), Pointer(0)]);
7317+
Expr2Block := Self.Binary.Count;
7318+
ParseExpr;
7319+
EndBlock := Self.Binary.Count;
7320+
Patch(JumpExpr2 - 1, Pointer(Expr2Block));
7321+
Patch(JumpEnd - 1, Pointer(EndBlock));
7322+
end;
73007323
end;
73017324

73027325
procedure ParseFuncRefCallByMapRewind(const Ident: TSEIdent; const DeepCount, RewindStartAdd: Integer; const ThisRefIdent: PSEIdent = nil);

0 commit comments

Comments
 (0)
X Tutup