Ignore:
Timestamp:
Apr 17, 2020, 10:16:25 PM (5 years ago)
Author:
chronos
Message:
  • Added: Simple pascal code generator.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/USource.pas

    r202 r203  
    1212  TFunctions = class;
    1313
     14  { TValue }
     15
    1416  TValue = class
    15   end;
     17    function Clone: TValue; virtual;
     18  end;
     19
     20  { TValueString }
    1621
    1722  TValueString = class(TValue)
    1823    Value: string;
    19   end;
     24    function Clone: TValue; override;
     25  end;
     26
     27  { TValueInteger }
    2028
    2129  TValueInteger = class(TValue)
    2230    Value: Integer;
    23   end;
     31    function Clone: TValue; override;
     32  end;
     33
     34  { TValueBoolean }
    2435
    2536  TValueBoolean = class(TValue)
    2637    Value: Boolean;
     38    function Clone: TValue; override;
    2739  end;
    2840
     
    140152  end;
    141153
    142   TExpressionOperandType = (otVariable, otConstant, otFunctionCall);
     154  TExpressionOperandType = (otVariableRef, otConstantRef, otConstantDirect, otFunctionCall);
    143155
    144156  { TExpressionOperand }
     
    148160    VariableRef: TVariable;
    149161    ConstantRef: TConstant;
     162    ConstantDirect: TConstant;
    150163    FunctionCall: TFunctionCall;
    151164    function GetType: TType; override;
     165    constructor Create;
     166    destructor Destroy; override;
    152167  end;
    153168
     
    225240implementation
    226241
     242{ TValueBoolean }
     243
     244function TValueBoolean.Clone: TValue;
     245begin
     246  Result := TValueBoolean.Create;
     247  TValueBoolean(Result).Value := Value;
     248end;
     249
     250{ TValueInteger }
     251
     252function TValueInteger.Clone: TValue;
     253begin
     254  Result := TValueInteger.Create;
     255  TValueInteger(Result).Value := Value;
     256end;
     257
     258{ TValueString }
     259
     260function TValueString.Clone: TValue;
     261begin
     262  Result := TValueString.Create;
     263  TValueString(Result).Value := Value;
     264end;
     265
     266{ TValue }
     267
     268function TValue.Clone: TValue;
     269begin
     270  Result := nil;
     271end;
     272
    227273{ TForToDo }
    228274
     
    254300begin
    255301  if OperandType = otFunctionCall then Result := FunctionCall.FunctionDef.ResultType
    256   else if OperandType = otConstant then Result := ConstantRef.TypeRef
    257   else if OperandType = otVariable then Result := VariableRef.TypeRef
     302  else if OperandType = otConstantRef then Result := ConstantRef.TypeRef
     303  else if OperandType = otConstantDirect then Result := ConstantDirect.TypeRef
     304  else if OperandType = otVariableRef then Result := VariableRef.TypeRef
    258305  else raise Exception.Create('Unsupported operand type');
     306end;
     307
     308constructor TExpressionOperand.Create;
     309begin
     310end;
     311
     312destructor TExpressionOperand.Destroy;
     313begin
     314  if Assigned(ConstantDirect) then ConstantDirect.Free;
    259315end;
    260316
Note: See TracChangeset for help on using the changeset viewer.