Ignore:
Timestamp:
Jun 26, 2023, 12:08:45 PM (17 months ago)
Author:
chronos
Message:
  • Added: Var function parameters support.
  • Added: Read and ReadLn procedures support.
  • Added: Interpreter now prints into console form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Executor.pas

    r229 r230  
    44
    55uses
    6   Classes, SysUtils, Source, Contnrs;
     6  Classes, SysUtils, Source, Generics.Collections;
    77
    88type
     
    2121  { TExecutorVariables }
    2222
    23   TExecutorVariables = class(TObjectList)
     23  TExecutorVariables = class(TObjectList<TExecutorVariable>)
    2424    function SearchByVariable(Variable: TVariable): TExecutorVariable;
    2525    function AddNew(Variable: TVariable): TExecutorVariable;
     
    3737  { TExecutorTypes }
    3838
    39   TExecutorTypes = class(TObjectList)
     39  TExecutorTypes = class(TObjectList<TExecutorType>)
    4040    function SearchByType(TypeRef: TType): TExecutorType;
    4141    function AddNew(TypeRef: TType): TExecutorType;
    4242  end;
    4343
    44   TExecutorFunctionCallback = function(Params: array of TValue): TValue of object;
     44  { TExecutorFunctionCallbackParam }
     45
     46  TExecutorFunctionCallbackParam = class
     47    Kind: TFunctionParamKind;
     48    Variable: TExecutorVariable;
     49    Value: TValue;
     50    destructor Destroy; override;
     51  end;
     52
     53  TExecutorFunctionCallback = function(Params: array of TExecutorFunctionCallbackParam):
     54    TValue of object;
    4555
    4656  { TExecutorFunction }
     
    5666  { TExecutorFunctions }
    5767
    58   TExecutorFunctions = class(TObjectList)
     68  TExecutorFunctions = class(TObjectList<TExecutorFunction>)
    5969    function SearchByFunction(FunctionDef: TFunction): TExecutorFunction;
    6070    function AddNew(FunctionDef: TFunction): TExecutorFunction;
     
    7888
    7989  TOutputEvent = procedure (Text: string) of object;
     90  TInputEvent = function: string of object;
    8091
    8192  { TExecutor }
     
    8495  private
    8596    FOnOutput: TOutputEvent;
     97    FOnInput: TInputEvent;
    8698    SystemBlock: TExecutorBlock;
    87     function ExecuteWriteLn(Params: array of TValue): TValue;
    88     function ExecuteWrite(Params: array of TValue): TValue;
    89     function ExecuteIntToStr(Params: array of TValue): TValue;
    90     function ExecuteStrToInt(Params: array of TValue): TValue;
    91     function ExecuteBooleanAssign(Params: array of TValue): TValue;
    92     function ExecuteBooleanNot(Params: array of TValue): TValue;
    93     function ExecuteBooleanEqual(Params: array of TValue): TValue;
    94     function ExecuteBooleanNotEqual(Params: array of TValue): TValue;
    95     function ExecuteStringAssign(Params: array of TValue): TValue;
    96     function ExecuteStringAdd(Params: array of TValue): TValue;
    97     function ExecuteStringEqual(Params: array of TValue): TValue;
    98     function ExecuteStringNotEqual(Params: array of TValue): TValue;
    99     function ExecuteIntegerAssign(Params: array of TValue): TValue;
    100     function ExecuteIntegerAdd(Params: array of TValue): TValue;
    101     function ExecuteIntegerSub(Params: array of TValue): TValue;
    102     function ExecuteIntegerMul(Params: array of TValue): TValue;
    103     function ExecuteIntegerIntDiv(Params: array of TValue): TValue;
    104     function ExecuteIntegerMod(Params: array of TValue): TValue;
    105     function ExecuteIntegerEqual(Params: array of TValue): TValue;
    106     function ExecuteIntegerNotEqual(Params: array of TValue): TValue;
    107     function ExecuteIntegerLesser(Params: array of TValue): TValue;
    108     function ExecuteIntegerHigher(Params: array of TValue): TValue;
    109     function ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue;
    110     function ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue;
    111     function ExecuteIntegerAnd(Params: array of TValue): TValue;
    112     function ExecuteIntegerOr(Params: array of TValue): TValue;
    113     function ExecuteIntegerXor(Params: array of TValue): TValue;
    114     function ExecuteIntegerShr(Params: array of TValue): TValue;
    115     function ExecuteIntegerShl(Params: array of TValue): TValue;
     99    function ExecuteWriteLn(Params: array of TExecutorFunctionCallbackParam): TValue;
     100    function ExecuteWrite(Params: array of TExecutorFunctionCallbackParam): TValue;
     101    function ExecuteReadLn(Params: array of TExecutorFunctionCallbackParam): TValue;
     102    function ExecuteRead(Params: array of TExecutorFunctionCallbackParam): TValue;
     103    function ExecuteIntToStr(Params: array of TExecutorFunctionCallbackParam): TValue;
     104    function ExecuteStrToInt(Params: array of TExecutorFunctionCallbackParam): TValue;
     105    function ExecuteBoolToStr(Params: array of TExecutorFunctionCallbackParam): TValue;
     106    function ExecuteStrToBool(Params: array of TExecutorFunctionCallbackParam): TValue;
     107    function ExecuteBooleanAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
     108    function ExecuteBooleanNot(Params: array of TExecutorFunctionCallbackParam): TValue;
     109    function ExecuteBooleanEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     110    function ExecuteBooleanNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     111    function ExecuteStringAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
     112    function ExecuteStringAdd(Params: array of TExecutorFunctionCallbackParam): TValue;
     113    function ExecuteStringEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     114    function ExecuteStringNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     115    function ExecuteIntegerAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
     116    function ExecuteIntegerAdd(Params: array of TExecutorFunctionCallbackParam): TValue;
     117    function ExecuteIntegerSub(Params: array of TExecutorFunctionCallbackParam): TValue;
     118    function ExecuteIntegerMul(Params: array of TExecutorFunctionCallbackParam): TValue;
     119    function ExecuteIntegerIntDiv(Params: array of TExecutorFunctionCallbackParam): TValue;
     120    function ExecuteIntegerMod(Params: array of TExecutorFunctionCallbackParam): TValue;
     121    function ExecuteIntegerEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     122    function ExecuteIntegerNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     123    function ExecuteIntegerLesser(Params: array of TExecutorFunctionCallbackParam): TValue;
     124    function ExecuteIntegerHigher(Params: array of TExecutorFunctionCallbackParam): TValue;
     125    function ExecuteIntegerLesserOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     126    function ExecuteIntegerHigherOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     127    function ExecuteIntegerAnd(Params: array of TExecutorFunctionCallbackParam): TValue;
     128    function ExecuteIntegerOr(Params: array of TExecutorFunctionCallbackParam): TValue;
     129    function ExecuteIntegerXor(Params: array of TExecutorFunctionCallbackParam): TValue;
     130    function ExecuteIntegerShr(Params: array of TExecutorFunctionCallbackParam): TValue;
     131    function ExecuteIntegerShl(Params: array of TExecutorFunctionCallbackParam): TValue;
    116132    procedure InitExecutorBlock(ExecutorBlock: TExecutorBlock; Block: TBlock);
    117133  public
     
    135151    procedure Run;
    136152    procedure Output(Text: string);
     153    function Input: string;
    137154    property OnOutput: TOutputEvent read FOnOutput write FOnOutput;
     155    property OnInput: TInputEvent read FOnInput write FOnInput;
    138156  end;
    139157
    140158
    141159implementation
     160
     161resourcestring
     162  SUnsupportedOperandType = 'Unsupported exception operand type.';
     163  SUnsupportedCommandType = 'Unsupported command type.';
     164  SExpectedBooleanValue = 'Expected boolean value.';
     165
     166{ TExecutorFunctionCallbackParam }
     167
     168destructor TExecutorFunctionCallbackParam.Destroy;
     169begin
     170  FreeAndNil(Value);
     171  inherited;
     172end;
    142173
    143174{ TExecutorFunction }
     
    293324{ TExecutor }
    294325
    295 function TExecutor.ExecuteWriteLn(Params: array of TValue): TValue;
     326function TExecutor.ExecuteWriteLn(Params: array of TExecutorFunctionCallbackParam): TValue;
    296327var
    297328  I: Integer;
     
    301332  Text := '';
    302333  for I := 0 to Length(Params) - 1 do
    303     Text := Text + TValueString(Params[I]).Value;
     334    Text := Text + TValueString(Params[I].Value).Value;
    304335  Output(Text + LineEnding);
    305336end;
    306337
    307 function TExecutor.ExecuteWrite(Params: array of TValue): TValue;
     338function TExecutor.ExecuteWrite(Params: array of TExecutorFunctionCallbackParam): TValue;
    308339var
    309340  I: Integer;
     
    313344  Text := '';
    314345  for I := 0 to Length(Params) - 1 do
    315     Text := Text + TValueString(Params[I]).Value;
     346    Text := Text + TValueString(Params[I].Value).Value;
    316347  Output(Text);
    317348end;
    318349
    319 function TExecutor.ExecuteIntToStr(Params: array of TValue): TValue;
     350function TExecutor.ExecuteReadLn(Params: array of TExecutorFunctionCallbackParam): TValue;
     351var
     352  I: Integer;
     353begin
     354  Result := nil;
     355  for I := 0 to Length(Params) - 1 do
     356    TValueString(Params[I].Variable.Value).Value := Input;
     357  Output(LineEnding);
     358end;
     359
     360function TExecutor.ExecuteRead(Params: array of TExecutorFunctionCallbackParam): TValue;
     361var
     362  I: Integer;
     363begin
     364  Result := nil;
     365  for I := 0 to Length(Params) - 1 do
     366    TValueString(Params[I].Value).Value := Input;
     367end;
     368
     369function TExecutor.ExecuteIntToStr(Params: array of TExecutorFunctionCallbackParam): TValue;
    320370begin
    321371  Result := TValueString.Create;
    322   TValueString(Result).Value := IntToStr(TValueInteger(Params[0]).Value);
    323 end;
    324 
    325 function TExecutor.ExecuteStrToInt(Params: array of TValue): TValue;
    326 begin
    327   Result := TValueInteger.Create;
    328   TValueInteger(Result).Value := StrToInt(TValueString(Params[0]).Value);
    329 end;
    330 
    331 function TExecutor.ExecuteBooleanAssign(Params: array of TValue): TValue;
    332 begin
    333   Result := TValueBoolean.Create;
    334   TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value;
    335 end;
    336 
    337 function TExecutor.ExecuteBooleanNot(Params: array of TValue): TValue;
    338 begin
    339   Result := TValueBoolean.Create;
    340   TValueBoolean(Result).Value := not TValueBoolean(Params[0]).Value;
    341 end;
    342 
    343 function TExecutor.ExecuteBooleanEqual(Params: array of TValue): TValue;
    344 begin
    345   Result := TValueBoolean.Create;
    346   TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value = TValueBoolean(Params[1]).Value;
    347 end;
    348 
    349 function TExecutor.ExecuteBooleanNotEqual(Params: array of TValue): TValue;
    350 begin
    351   Result := TValueBoolean.Create;
    352   TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value <> TValueBoolean(Params[1]).Value;
    353 end;
    354 
    355 function TExecutor.ExecuteStringAssign(Params: array of TValue): TValue;
     372  TValueString(Result).Value := IntToStr(TValueInteger(Params[0].Value).Value);
     373end;
     374
     375function TExecutor.ExecuteStrToInt(Params: array of TExecutorFunctionCallbackParam): TValue;
     376begin
     377  Result := TValueInteger.Create;
     378  TValueInteger(Result).Value := StrToInt(TValueString(Params[0].Value).Value);
     379end;
     380
     381function TExecutor.ExecuteBoolToStr(Params: array of TExecutorFunctionCallbackParam): TValue;
    356382begin
    357383  Result := TValueString.Create;
    358   TValueString(Result).Value := TValueString(Params[0]).Value;
    359 end;
    360 
    361 function TExecutor.ExecuteStringAdd(Params: array of TValue): TValue;
     384  TValueString(Result).Value := BoolToStr(TValueBoolean(Params[0].Value).Value);
     385end;
     386
     387function TExecutor.ExecuteStrToBool(Params: array of TExecutorFunctionCallbackParam): TValue;
     388begin
     389  Result := TValueBoolean.Create;
     390  TValueBoolean(Result).Value := StrToBool(TValueString(Params[0].Value).Value);
     391end;
     392
     393function TExecutor.ExecuteBooleanAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
     394begin
     395  Result := TValueBoolean.Create;
     396  TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value;
     397end;
     398
     399function TExecutor.ExecuteBooleanNot(Params: array of TExecutorFunctionCallbackParam): TValue;
     400begin
     401  Result := TValueBoolean.Create;
     402  TValueBoolean(Result).Value := not TValueBoolean(Params[0].Value).Value;
     403end;
     404
     405function TExecutor.ExecuteBooleanEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     406begin
     407  Result := TValueBoolean.Create;
     408  TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value =
     409    TValueBoolean(Params[1].Value).Value;
     410end;
     411
     412function TExecutor.ExecuteBooleanNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     413begin
     414  Result := TValueBoolean.Create;
     415  TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value <>
     416    TValueBoolean(Params[1].Value).Value;
     417end;
     418
     419function TExecutor.ExecuteStringAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
    362420begin
    363421  Result := TValueString.Create;
    364   TValueString(Result).Value := TValueString(Params[0]).Value + TValueString(Params[1]).Value;
    365 end;
    366 
    367 function TExecutor.ExecuteStringEqual(Params: array of TValue): TValue;
    368 begin
    369   Result := TValueBoolean.Create;
    370   TValueBoolean(Result).Value := TValueString(Params[0]).Value = TValueString(Params[1]).Value;
    371 end;
    372 
    373 function TExecutor.ExecuteStringNotEqual(Params: array of TValue): TValue;
    374 begin
    375   Result := TValueBoolean.Create;
    376   TValueBoolean(Result).Value := TValueString(Params[0]).Value <> TValueString(Params[1]).Value;
    377 end;
    378 
    379 function TExecutor.ExecuteIntegerAssign(Params: array of TValue): TValue;
    380 begin
    381   Result := TValueInteger.Create;
    382   TValueInteger(Result).Value := TValueInteger(Params[0]).Value;
    383 end;
    384 
    385 function TExecutor.ExecuteIntegerAdd(Params: array of TValue): TValue;
    386 begin
    387   Result := TValueInteger.Create;
    388   TValueInteger(Result).Value := TValueInteger(Params[0]).Value + TValueInteger(Params[1]).Value;
    389 end;
    390 
    391 function TExecutor.ExecuteIntegerSub(Params: array of TValue): TValue;
    392 begin
    393   Result := TValueInteger.Create;
    394   TValueInteger(Result).Value := TValueInteger(Params[0]).Value - TValueInteger(Params[1]).Value;
    395 end;
    396 
    397 function TExecutor.ExecuteIntegerMul(Params: array of TValue): TValue;
    398 begin
    399   Result := TValueInteger.Create;
    400   TValueInteger(Result).Value := TValueInteger(Params[0]).Value * TValueInteger(Params[1]).Value;
    401 end;
    402 
    403 function TExecutor.ExecuteIntegerIntDiv(Params: array of TValue): TValue;
    404 begin
    405   Result := TValueInteger.Create;
    406   TValueInteger(Result).Value := TValueInteger(Params[0]).Value div TValueInteger(Params[1]).Value;
    407 end;
    408 
    409 function TExecutor.ExecuteIntegerMod(Params: array of TValue): TValue;
    410 begin
    411   Result := TValueInteger.Create;
    412   TValueInteger(Result).Value := TValueInteger(Params[0]).Value mod TValueInteger(Params[1]).Value;
    413 end;
    414 
    415 function TExecutor.ExecuteIntegerEqual(Params: array of TValue): TValue;
    416 begin
    417   Result := TValueBoolean.Create;
    418   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value = TValueInteger(Params[1]).Value;
    419 end;
    420 
    421 function TExecutor.ExecuteIntegerNotEqual(Params: array of TValue): TValue;
    422 begin
    423   Result := TValueBoolean.Create;
    424   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <> TValueInteger(Params[1]).Value;
    425 end;
    426 
    427 function TExecutor.ExecuteIntegerLesser(Params: array of TValue): TValue;
    428 begin
    429   Result := TValueBoolean.Create;
    430   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value < TValueInteger(Params[1]).Value;
    431 end;
    432 
    433 function TExecutor.ExecuteIntegerHigher(Params: array of TValue): TValue;
    434 begin
    435   Result := TValueBoolean.Create;
    436   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value > TValueInteger(Params[1]).Value;
    437 end;
    438 
    439 function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue;
    440 begin
    441   Result := TValueBoolean.Create;
    442   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <= TValueInteger(Params[1]).Value;
    443 end;
    444 
    445 function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue;
    446 begin
    447   Result := TValueBoolean.Create;
    448   TValueBoolean(Result).Value := TValueInteger(Params[0]).Value >= TValueInteger(Params[1]).Value;
    449 end;
    450 
    451 function TExecutor.ExecuteIntegerAnd(Params: array of TValue): TValue;
    452 begin
    453   Result := TValueInteger.Create;
    454   TValueInteger(Result).Value := TValueInteger(Params[0]).Value and TValueInteger(Params[1]).Value;
    455 end;
    456 
    457 function TExecutor.ExecuteIntegerOr(Params: array of TValue): TValue;
    458 begin
    459   Result := TValueInteger.Create;
    460   TValueInteger(Result).Value := TValueInteger(Params[0]).Value or TValueInteger(Params[1]).Value;
    461 end;
    462 
    463 function TExecutor.ExecuteIntegerXor(Params: array of TValue): TValue;
    464 begin
    465   Result := TValueInteger.Create;
    466   TValueInteger(Result).Value := TValueInteger(Params[0]).Value xor TValueInteger(Params[1]).Value;
    467 end;
    468 
    469 function TExecutor.ExecuteIntegerShr(Params: array of TValue): TValue;
    470 begin
    471   Result := TValueInteger.Create;
    472   TValueInteger(Result).Value := TValueInteger(Params[0]).Value shr TValueInteger(Params[1]).Value;
    473 end;
    474 
    475 function TExecutor.ExecuteIntegerShl(Params: array of TValue): TValue;
    476 begin
    477   Result := TValueInteger.Create;
    478   TValueInteger(Result).Value := TValueInteger(Params[0]).Value shl TValueInteger(Params[1]).Value;
     422  TValueString(Result).Value := TValueString(Params[0].Value).Value;
     423end;
     424
     425function TExecutor.ExecuteStringAdd(Params: array of TExecutorFunctionCallbackParam): TValue;
     426begin
     427  Result := TValueString.Create;
     428  TValueString(Result).Value := TValueString(Params[0].Value).Value +
     429    TValueString(Params[1].Value).Value;
     430end;
     431
     432function TExecutor.ExecuteStringEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     433begin
     434  Result := TValueBoolean.Create;
     435  TValueBoolean(Result).Value := TValueString(Params[0].Value).Value =
     436    TValueString(Params[1].Value).Value;
     437end;
     438
     439function TExecutor.ExecuteStringNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     440begin
     441  Result := TValueBoolean.Create;
     442  TValueBoolean(Result).Value := TValueString(Params[0].Value).Value <>
     443    TValueString(Params[1].Value).Value;
     444end;
     445
     446function TExecutor.ExecuteIntegerAssign(Params: array of TExecutorFunctionCallbackParam): TValue;
     447begin
     448  Result := TValueInteger.Create;
     449  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value;
     450end;
     451
     452function TExecutor.ExecuteIntegerAdd(Params: array of TExecutorFunctionCallbackParam): TValue;
     453begin
     454  Result := TValueInteger.Create;
     455  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value +
     456    TValueInteger(Params[1].Value).Value;
     457end;
     458
     459function TExecutor.ExecuteIntegerSub(Params: array of TExecutorFunctionCallbackParam): TValue;
     460begin
     461  Result := TValueInteger.Create;
     462  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value -
     463    TValueInteger(Params[1].Value).Value;
     464end;
     465
     466function TExecutor.ExecuteIntegerMul(Params: array of TExecutorFunctionCallbackParam): TValue;
     467begin
     468  Result := TValueInteger.Create;
     469  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value *
     470    TValueInteger(Params[1].Value).Value;
     471end;
     472
     473function TExecutor.ExecuteIntegerIntDiv(Params: array of TExecutorFunctionCallbackParam): TValue;
     474begin
     475  Result := TValueInteger.Create;
     476  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value div
     477    TValueInteger(Params[1].Value).Value;
     478end;
     479
     480function TExecutor.ExecuteIntegerMod(Params: array of TExecutorFunctionCallbackParam): TValue;
     481begin
     482  Result := TValueInteger.Create;
     483  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value mod
     484    TValueInteger(Params[1].Value).Value;
     485end;
     486
     487function TExecutor.ExecuteIntegerEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     488begin
     489  Result := TValueBoolean.Create;
     490  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value =
     491    TValueInteger(Params[1].Value).Value;
     492end;
     493
     494function TExecutor.ExecuteIntegerNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     495begin
     496  Result := TValueBoolean.Create;
     497  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value <>
     498    TValueInteger(Params[1].Value).Value;
     499end;
     500
     501function TExecutor.ExecuteIntegerLesser(Params: array of TExecutorFunctionCallbackParam): TValue;
     502begin
     503  Result := TValueBoolean.Create;
     504  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value <
     505    TValueInteger(Params[1].Value).Value;
     506end;
     507
     508function TExecutor.ExecuteIntegerHigher(Params: array of TExecutorFunctionCallbackParam): TValue;
     509begin
     510  Result := TValueBoolean.Create;
     511  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value >
     512    TValueInteger(Params[1].Value).Value;
     513end;
     514
     515function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     516begin
     517  Result := TValueBoolean.Create;
     518  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value <=
     519    TValueInteger(Params[1].Value).Value;
     520end;
     521
     522function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue;
     523begin
     524  Result := TValueBoolean.Create;
     525  TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value >=
     526    TValueInteger(Params[1].Value).Value;
     527end;
     528
     529function TExecutor.ExecuteIntegerAnd(Params: array of TExecutorFunctionCallbackParam): TValue;
     530begin
     531  Result := TValueInteger.Create;
     532  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value and
     533    TValueInteger(Params[1].Value).Value;
     534end;
     535
     536function TExecutor.ExecuteIntegerOr(Params: array of TExecutorFunctionCallbackParam): TValue;
     537begin
     538  Result := TValueInteger.Create;
     539  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value or
     540    TValueInteger(Params[1].Value).Value;
     541end;
     542
     543function TExecutor.ExecuteIntegerXor(Params: array of TExecutorFunctionCallbackParam): TValue;
     544begin
     545  Result := TValueInteger.Create;
     546  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value xor
     547    TValueInteger(Params[1].Value).Value;
     548end;
     549
     550function TExecutor.ExecuteIntegerShr(Params: array of TExecutorFunctionCallbackParam): TValue;
     551begin
     552  Result := TValueInteger.Create;
     553  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value shr
     554    TValueInteger(Params[1].Value).Value;
     555end;
     556
     557function TExecutor.ExecuteIntegerShl(Params: array of TExecutorFunctionCallbackParam): TValue;
     558begin
     559  Result := TValueInteger.Create;
     560  TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value shl
     561    TValueInteger(Params[1].Value).Value;
    479562end;
    480563
     
    582665    if ExecutorFunction.FunctionDef.Name = 'WriteLn' then begin
    583666      ExecutorFunction.Callback := ExecuteWriteLn;
    584     end;
     667    end else
     668    if ExecutorFunction.FunctionDef.Name = 'Read' then begin
     669      ExecutorFunction.Callback := ExecuteRead;
     670    end else
     671    if ExecutorFunction.FunctionDef.Name = 'ReadLn' then begin
     672      ExecutorFunction.Callback := ExecuteReadLn;
     673    end else
    585674    if ExecutorFunction.FunctionDef.Name = 'IntToStr' then begin
    586675      ExecutorFunction.Callback := ExecuteIntToStr;
     
    588677    if ExecutorFunction.FunctionDef.Name = 'StrToInt' then begin
    589678      ExecutorFunction.Callback := ExecuteStrToInt;
     679    end else
     680    if ExecutorFunction.FunctionDef.Name = 'BoolToStr' then begin
     681      ExecutorFunction.Callback := ExecuteBoolToStr;
     682    end else
     683    if ExecutorFunction.FunctionDef.Name = 'StrToBool' then begin
     684      ExecutorFunction.Callback := ExecuteStrToBool;
    590685    end;
    591686  end;
     
    620715  else if Command is TContinue then ExecuteContinue(Block, TContinue(Command))
    621716  else if Command is TEmptyCommand then
    622   else raise Exception.Create('Unsupported command type');
     717  else raise Exception.Create(SUnsupportedCommandType);
    623718end;
    624719
     
    635730          ExecuteCommand(Block, IfThenElse.CommandElse);
    636731      end;
    637   end else raise Exception.Create('Expected boolean value.');
     732  end else raise Exception.Create(SExpectedBooleanValue);
    638733  Value.Free;
    639734end;
     
    659754        Break;
    660755      end;
    661     end else raise Exception.Create('Expected boolean value.');
     756    end else raise Exception.Create(SExpectedBooleanValue);
    662757  end;
    663758end;
     
    687782      Value.Free;
    688783      if BoolValue then Break;
    689     end else raise Exception.Create('Expected boolean value.');
     784    end else raise Exception.Create(SExpectedBooleanValue);
    690785  end;
    691786end;
     
    760855var
    761856  ExecutorFunction: TExecutorFunction;
    762   Params: array of TValue;
     857  Params: array of TExecutorFunctionCallbackParam;
    763858  I: Integer;
    764859  ExecutorVariable: TExecutorVariable;
     
    771866      SetLength(Params, FunctionCall.Params.Count);
    772867      for I := 0 to FunctionCall.Params.Count - 1 do begin
    773         Params[I] := ExecuteExpression(Block, TExpression(FunctionCall.Params[0]));
     868        Params[I] := TExecutorFunctionCallbackParam.Create;
     869        Params[I].Kind := FunctionCall.FunctionDef.Params[I].Kind;
     870        if FunctionCall.FunctionDef.Params[I].Kind = pkVar then begin
     871          Variable := TExpressionOperand(FunctionCall.Params[I]).VariableRef;
     872          //InitExecutorBlock(ExecutorFunction.Block, FunctionCall.FunctionDef.Block);
     873          ExecutorVariable := Block.GetVariable(Variable);
     874          Params[I].Variable := ExecutorVariable;
     875        end
     876        else Params[I].Value := ExecuteExpression(Block, FunctionCall.Params[I]);
    774877      end;
    775878      Result := ExecutorFunction.Callback(Params);
    776879      for I := 0 to FunctionCall.Params.Count - 1 do begin
     880        //if FunctionCall.Params[I].
    777881        Params[I].Free;
    778882      end;
     
    798902  Variable: TExecutorVariable;
    799903  ExecutorFunction: TExecutorFunction;
    800   Params: array of TValue;
     904  Params: array of TExecutorFunctionCallbackParam;
    801905begin
    802906  Value := ExecuteExpression(Block, Assignment.Expression);
     
    805909  if Assignment.Variable.TypeRef = Assignment.Expression.GetType then begin;
    806910    SetLength(Params, 1);
    807     Params[0] := Value;
     911    Params[0] := TExecutorFunctionCallbackParam.Create;
     912    Params[0].Value := Value;
    808913    Variable.Value.Free;
    809914    Variable.Value := ExecutorFunction.Callback(Params);
     
    834939  Value: TValue;
    835940  ExecutorFunction: TExecutorFunction;
    836   Params: array of TValue;
     941  Params: array of TExecutorFunctionCallbackParam;
    837942  FuncName: string;
    838943begin
     
    846951  for I := 0 to Expression.Items.Count - 1 do begin
    847952    Value := ExecuteExpression(Block, TExpression(Expression.Items[I]));
    848     Params[I] := Value;
     953    Params[I] := TExecutorFunctionCallbackParam.Create;
     954    Params[I].Value := Value;
    849955  end;
    850956  Result := ExecutorFunction.Callback(Params);
     
    862968    otConstantRef: Result := Expression.ConstantRef.Value.Clone;
    863969    otVariableRef: Result := Block.Variables.SearchByVariable(Expression.VariableRef).Value.Clone;
    864     else raise Exception.Create('Unsupported exception operand type.');
     970    else raise Exception.Create(SUnsupportedOperandType);
    865971  end;
    866972end;
     
    883989end;
    884990
     991function TExecutor.Input: string;
     992begin
     993  if Assigned(FOnInput) then
     994    Result := FOnInput;
     995end;
     996
    885997end.
    886998
Note: See TracChangeset for help on using the changeset viewer.