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/Source.pas

    r224 r230  
    44
    55uses
    6   Classes, SysUtils, Contnrs;
     6  Classes, SysUtils, Generics.Collections;
    77
    88type
     
    2424  end;
    2525
    26   TFields = class(TObjectList)
     26  TFields = class(TObjectList<TField>)
    2727  end;
    2828
     
    5050  end;
    5151
    52   { TSourceNodes }
    53 
    54   TSourceNodes = class(TSourceNode)
     52  { TSourceNodeList }
     53
     54  TSourceNodeList<T> = class(TSourceNode)
    5555  private
    5656    Parent: TSourceNode;
    5757    function GetCount: Integer;
    58     function GetItem(Index: Integer): TObject;
    59     procedure SetItem(Index: Integer; AValue: TObject);
    60   public
    61     List: TObjectList;
     58    function GetItem(Index: Integer): T;
     59    procedure SetItem(Index: Integer; AValue: T);
     60  public
     61    List: TObjectList<TSourceNode>;
    6262    procedure Clear;
    63     function Add(AObject: TObject): Integer;
     63    function Add(AObject: T): Integer;
    6464    constructor Create;
    6565    destructor Destroy; override;
    66     property Items[Index: Integer]: TObject read GetItem write SetItem; default;
     66    property Items[Index: Integer]: T read GetItem write SetItem; default;
    6767    property Count: Integer read GetCount;
    6868  end;
     
    115115  { TTypes }
    116116
    117   TTypes = class(TSourceNodes)
     117  TTypes = class(TSourceNodeList<TType>)
    118118    function SearchByName(Name: string): TType;
    119119    function AddNew(Name: string): TType;
     
    136136  { TVariables }
    137137
    138   TVariables = class(TSourceNodes)
     138  TVariables = class(TSourceNodeList<TVariable>)
    139139    function SearchByName(Name: string): TVariable;
    140140  end;
     
    157157  { TConstants }
    158158
    159   TConstants = class(TSourceNodes)
     159  TConstants = class(TSourceNodeList<TConstant>)
    160160    function SearchByName(Name: string): TConstant;
    161161    function AddNew(Name: string): TConstant;
    162162  end;
     163
     164  TFunctionParamKind = (pkNormal, pkVar, pkConst);
    163165
    164166  TFunctionParameter = class(TSourceNode)
    165167    Name: string;
    166168    TypeRef: TType;
     169    Kind: TFunctionParamKind;
    167170  end;
    168171
    169172  { TFunctionParameters }
    170173
    171   TFunctionParameters = class(TSourceNodes)
     174  TFunctionParameters = class(TSourceNodeList<TFunctionParameter>)
    172175    function SearchByName(Name: string): TFunctionParameter;
    173176    function AddNew(Name: string; TypeRef: TType): TFunctionParameter;
     
    195198  { TFunctions }
    196199
    197   TFunctions = class(TSourceNodes)
     200  TFunctions = class(TSourceNodeList<TFunction>)
    198201    ParentType: TType;
    199202    function SearchByName(Name: string): TFunction;
     
    204207  end;
    205208
    206   TCommands = class(TSourceNodes)
     209  TCommands = class(TSourceNodeList<TCommand>)
    207210  end;
    208211
     
    302305  end;
    303306
    304   TExpressions = class(TSourceNodes)
     307  TExpressions = class(TSourceNodeList<TExpression>)
    305308  end;
    306309
     
    565568end;
    566569
    567 { TSourceNodes }
    568 
    569 function TSourceNodes.GetCount: Integer;
     570{ TSourceNodeList }
     571
     572function TSourceNodeList<T>.GetCount: Integer;
    570573begin
    571574  Result := List.Count;
    572575end;
    573576
    574 function TSourceNodes.GetItem(Index: Integer): TObject;
    575 begin
    576   Result := List[Index];
    577 end;
    578 
    579 procedure TSourceNodes.SetItem(Index: Integer; AValue: TObject);
     577function TSourceNodeList<T>.GetItem(Index: Integer): T;
     578begin
     579  Result := T(List[Index]);
     580end;
     581
     582procedure TSourceNodeList<T>.SetItem(Index: Integer; AValue: T);
    580583begin
    581584  List[Index] := AValue;
    582585end;
    583586
    584 procedure TSourceNodes.Clear;
     587procedure TSourceNodeList<T>.Clear;
    585588begin
    586589  List.Clear;
    587590end;
    588591
    589 function TSourceNodes.Add(AObject: TObject): Integer;
     592function TSourceNodeList<T>.Add(AObject: T): Integer;
    590593begin
    591594  Result := List.Add(AObject);
    592595end;
    593596
    594 constructor TSourceNodes.Create;
    595 begin
    596   List := TObjectList.Create;
    597 end;
    598 
    599 destructor TSourceNodes.Destroy;
     597constructor TSourceNodeList<T>.Create;
     598begin
     599  List := TObjectList<TSourceNode>.Create;
     600end;
     601
     602destructor TSourceNodeList<T>.Destroy;
    600603begin
    601604  FreeAndNil(List);
     
    10951098procedure TExpressionOperation.SetValue(Index: Integer; var Value);
    10961099begin
    1097   Items[Index] := TObject(Value);
     1100  Items[Index] := TExpression(Value);
    10981101end;
    10991102
Note: See TracChangeset for help on using the changeset viewer.