Ignore:
Timestamp:
Nov 25, 2020, 12:18:45 AM (3 years ago)
Author:
chronos
Message:
  • Added: Support for more expression operators.
  • Added: Support for brackets in expressions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UExecutor.pas

    r221 r222  
    9292    function ExecuteStrToInt(Params: array of TValue): TValue;
    9393    function ExecuteBooleanAssign(Params: array of TValue): TValue;
     94    function ExecuteBooleanNot(Params: array of TValue): TValue;
    9495    function ExecuteBooleanEqual(Params: array of TValue): TValue;
    9596    function ExecuteBooleanNotEqual(Params: array of TValue): TValue;
     
    101102    function ExecuteIntegerAdd(Params: array of TValue): TValue;
    102103    function ExecuteIntegerSub(Params: array of TValue): TValue;
     104    function ExecuteIntegerMul(Params: array of TValue): TValue;
     105    function ExecuteIntegerIntDiv(Params: array of TValue): TValue;
     106    function ExecuteIntegerMod(Params: array of TValue): TValue;
    103107    function ExecuteIntegerEqual(Params: array of TValue): TValue;
    104108    function ExecuteIntegerNotEqual(Params: array of TValue): TValue;
     109    function ExecuteIntegerLesser(Params: array of TValue): TValue;
     110    function ExecuteIntegerHigher(Params: array of TValue): TValue;
     111    function ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue;
     112    function ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue;
     113    function ExecuteIntegerAnd(Params: array of TValue): TValue;
     114    function ExecuteIntegerOr(Params: array of TValue): TValue;
     115    function ExecuteIntegerXor(Params: array of TValue): TValue;
     116    function ExecuteIntegerShr(Params: array of TValue): TValue;
     117    function ExecuteIntegerShl(Params: array of TValue): TValue;
    105118    procedure InitExecutorBlock(ExecutorBlock: TExecutorBlock; Block: TBlock);
    106119  public
     
    121134    function ExecuteExpressionOperation(Block: TExecutorBlock; Expression: TExpressionOperation): TValue;
    122135    function ExecuteExpressionOperand(Block: TExecutorBlock; Expression: TExpressionOperand): TValue;
     136    function ExecuteExpressionBrackets(Block: TExecutorBlock; Expression: TExpressionBrackets): TValue;
    123137    procedure Run;
    124138    procedure Output(Text: string);
     
    323337end;
    324338
     339function TExecutor.ExecuteBooleanNot(Params: array of TValue): TValue;
     340begin
     341  Result := TValueBoolean.Create;
     342  TValueBoolean(Result).Value := not TValueBoolean(Params[0]).Value;
     343end;
     344
    325345function TExecutor.ExecuteBooleanEqual(Params: array of TValue): TValue;
    326346begin
     
    377397end;
    378398
     399function TExecutor.ExecuteIntegerMul(Params: array of TValue): TValue;
     400begin
     401  Result := TValueInteger.Create;
     402  TValueInteger(Result).Value := TValueInteger(Params[0]).Value * TValueInteger(Params[1]).Value;
     403end;
     404
     405function TExecutor.ExecuteIntegerIntDiv(Params: array of TValue): TValue;
     406begin
     407  Result := TValueInteger.Create;
     408  TValueInteger(Result).Value := TValueInteger(Params[0]).Value div TValueInteger(Params[1]).Value;
     409end;
     410
     411function TExecutor.ExecuteIntegerMod(Params: array of TValue): TValue;
     412begin
     413  Result := TValueInteger.Create;
     414  TValueInteger(Result).Value := TValueInteger(Params[0]).Value mod TValueInteger(Params[1]).Value;
     415end;
     416
    379417function TExecutor.ExecuteIntegerEqual(Params: array of TValue): TValue;
    380418begin
     
    387425  Result := TValueBoolean.Create;
    388426  TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <> TValueInteger(Params[1]).Value;
     427end;
     428
     429function TExecutor.ExecuteIntegerLesser(Params: array of TValue): TValue;
     430begin
     431  Result := TValueBoolean.Create;
     432  TValueBoolean(Result).Value := TValueInteger(Params[0]).Value < TValueInteger(Params[1]).Value;
     433end;
     434
     435function TExecutor.ExecuteIntegerHigher(Params: array of TValue): TValue;
     436begin
     437  Result := TValueBoolean.Create;
     438  TValueBoolean(Result).Value := TValueInteger(Params[0]).Value > TValueInteger(Params[1]).Value;
     439end;
     440
     441function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue;
     442begin
     443  Result := TValueBoolean.Create;
     444  TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <= TValueInteger(Params[1]).Value;
     445end;
     446
     447function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue;
     448begin
     449  Result := TValueBoolean.Create;
     450  TValueBoolean(Result).Value := TValueInteger(Params[0]).Value >= TValueInteger(Params[1]).Value;
     451end;
     452
     453function TExecutor.ExecuteIntegerAnd(Params: array of TValue): TValue;
     454begin
     455  Result := TValueInteger.Create;
     456  TValueInteger(Result).Value := TValueInteger(Params[0]).Value and TValueInteger(Params[1]).Value;
     457end;
     458
     459function TExecutor.ExecuteIntegerOr(Params: array of TValue): TValue;
     460begin
     461  Result := TValueInteger.Create;
     462  TValueInteger(Result).Value := TValueInteger(Params[0]).Value or TValueInteger(Params[1]).Value;
     463end;
     464
     465function TExecutor.ExecuteIntegerXor(Params: array of TValue): TValue;
     466begin
     467  Result := TValueInteger.Create;
     468  TValueInteger(Result).Value := TValueInteger(Params[0]).Value xor TValueInteger(Params[1]).Value;
     469end;
     470
     471function TExecutor.ExecuteIntegerShr(Params: array of TValue): TValue;
     472begin
     473  Result := TValueInteger.Create;
     474  TValueInteger(Result).Value := TValueInteger(Params[0]).Value shr TValueInteger(Params[1]).Value;
     475end;
     476
     477function TExecutor.ExecuteIntegerShl(Params: array of TValue): TValue;
     478begin
     479  Result := TValueInteger.Create;
     480  TValueInteger(Result).Value := TValueInteger(Params[0]).Value shl TValueInteger(Params[1]).Value;
    389481end;
    390482
     
    410502          ExecutorFunction.Callback := ExecuteBooleanNotEqual;
    411503        end;
     504        if ExecutorFunction.FunctionDef.Name = '_Not' then begin
     505          ExecutorFunction.Callback := ExecuteBooleanNot;
     506        end else
    412507      end else
    413508      if ExecutorType.TypeRef.Name = 'string' then begin
     
    435530          ExecutorFunction.Callback := ExecuteIntegerSub;
    436531        end else
     532        if ExecutorFunction.FunctionDef.Name = '_Mul' then begin
     533          ExecutorFunction.Callback := ExecuteIntegerMul;
     534        end else
     535        if ExecutorFunction.FunctionDef.Name = '_IntDiv' then begin
     536          ExecutorFunction.Callback := ExecuteIntegerIntDiv;
     537        end else
     538        if ExecutorFunction.FunctionDef.Name = '_IntMod' then begin
     539          ExecutorFunction.Callback := ExecuteIntegerMod;
     540        end else
    437541        if ExecutorFunction.FunctionDef.Name = '_Equal' then begin
    438542          ExecutorFunction.Callback := ExecuteIntegerEqual;
     
    440544        if ExecutorFunction.FunctionDef.Name = '_NotEqual' then begin
    441545          ExecutorFunction.Callback := ExecuteIntegerNotEqual;
     546        end;
     547        if ExecutorFunction.FunctionDef.Name = '_Lesser' then begin
     548          ExecutorFunction.Callback := ExecuteIntegerLesser;
     549        end else
     550        if ExecutorFunction.FunctionDef.Name = '_Higher' then begin
     551          ExecutorFunction.Callback := ExecuteIntegerHigher;
     552        end;
     553        if ExecutorFunction.FunctionDef.Name = '_LesserOrEqual' then begin
     554          ExecutorFunction.Callback := ExecuteIntegerLesserOrEqual;
     555        end else
     556        if ExecutorFunction.FunctionDef.Name = '_HigherOrEqual' then begin
     557          ExecutorFunction.Callback := ExecuteIntegerHigherOrEqual;
     558        end;
     559        if ExecutorFunction.FunctionDef.Name = '_And' then begin
     560          ExecutorFunction.Callback := ExecuteIntegerAnd;
     561        end;
     562        if ExecutorFunction.FunctionDef.Name = '_Or' then begin
     563          ExecutorFunction.Callback := ExecuteIntegerOr;
     564        end;
     565        if ExecutorFunction.FunctionDef.Name = '_Xor' then begin
     566          ExecutorFunction.Callback := ExecuteIntegerXor;
     567        end;
     568        if ExecutorFunction.FunctionDef.Name = '_Shr' then begin
     569          ExecutorFunction.Callback := ExecuteIntegerShr;
     570        end;
     571        if ExecutorFunction.FunctionDef.Name = '_Shl' then begin
     572          ExecutorFunction.Callback := ExecuteIntegerShl;
    442573        end;
    443574      end;
     
    692823  if Expression is TExpressionOperand then
    693824    Result := ExecuteExpressionOperand(Block, TExpressionOperand(Expression))
    694   else raise Exception.Create('Unknown expression class.');
     825  else
     826  if Expression is TExpressionBrackets then
     827    Result := ExecuteExpressionBrackets(Block, TExpressionBrackets(Expression))
     828  else
     829  raise Exception.Create('Unknown expression class.');
    695830end;
    696831
     
    733868end;
    734869
     870function TExecutor.ExecuteExpressionBrackets(Block: TExecutorBlock;
     871  Expression: TExpressionBrackets): TValue;
     872begin
     873  Result := ExecuteExpression(Block, Expression.Expression);
     874end;
     875
    735876procedure TExecutor.Run;
    736877begin
Note: See TracChangeset for help on using the changeset viewer.