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.
Location:
branches/xpascal/Generators
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Generators/GeneratorCSharp.pas

    r224 r230  
    129129  if FunctionCall.Params.Count > 0 then begin
    130130    AddText('(');
    131     for I := 0 to FunctionCall.Params.Count - 1 do
     131    for I := 0 to FunctionCall.Params.Count - 1 do begin
     132      if FunctionCall.FunctionDef.Params[I].Kind = pkVar then
     133        AddText('ref ');
    132134      GenerateExpression(Block, TExpression(FunctionCall.Params[I]));
     135    end;
    133136    AddText(')');
    134137  end;
     
    297300var
    298301  I: Integer;
     302  Param: TFunctionParameter;
    299303begin
    300304  GenerateTypeRef(FunctionDef.ResultType);
    301305  AddText(' ' + FunctionDef.Name + '(');
    302306  for I := 0 to FunctionDef.Params.Count - 1 do begin
    303     GenerateTypeRef(TFunctionParameter(FunctionDef.Params[I]).TypeRef);
     307    Param := TFunctionParameter(FunctionDef.Params[I]);
     308    if Param.Kind = pkVar then AddText('ref ');
     309    GenerateTypeRef(Param.TypeRef);
    304310    AddText(' ');
    305     AddText(TFunctionParameter(FunctionDef.Params[I]).Name);
     311    AddText(Param.Name);
    306312    if I > 0 then AddText(', ');
    307313  end;
     
    312318    if FunctionDef.InternalName = 'WriteLn' then AddTextLine('Console.Write(Text + "\n");')
    313319    else if FunctionDef.InternalName = 'Write' then AddTextLine('Console.Write(Text);')
     320    else if FunctionDef.InternalName = 'ReadLn' then AddTextLine('Text = Console.ReadLine();')
     321    else if FunctionDef.InternalName = 'Read' then AddTextLine('Text = Console.ReadLine();')
    314322    else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return Value.ToString();')
    315323    else if FunctionDef.InternalName = 'StrToInt' then begin
     
    319327      AddTextLine('  return x;');
    320328      AddTextLine('} else return 0;');
     329    end
     330    else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return Value.ToString();')
     331    else if FunctionDef.InternalName = 'StrToBool' then begin
     332      AddTextLine('bool x = false;');
     333      AddTextLine('if (bool.TryParse(Value, out x))');
     334      AddTextLine('{');
     335      AddTextLine('  return x;');
     336      AddTextLine('} else return false;');
    321337    end;
    322338
  • branches/xpascal/Generators/GeneratorPascal.pas

    r224 r230  
    231231    else if FunctionDef.InternalName = 'Write' then AddTextLine('System.Write(Text);')
    232232    else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);')
    233     else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);');
     233    else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);')
     234    else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return SysUtils.BoolToStr(Value);')
     235    else if FunctionDef.InternalName = 'StrToBool' then AddTextLine('return SysUtils.StrToBool(Value);');
    234236    Indent := Indent - 1;
    235237    AddTextLine('end;');
  • branches/xpascal/Generators/GeneratorPhp.pas

    r224 r230  
    241241    else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);')
    242242    else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;')
    243     else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;');
     243    else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;')
     244    else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return $Value;')
     245    else if FunctionDef.InternalName = 'StrToBool' then AddTextLine('return $Value;');
    244246    Indent := Indent - 1;
    245247    AddTextLine('}');
  • branches/xpascal/Generators/GeneratorXml.pas

    r224 r230  
    1111  TGeneratorXml = class(TGenerator)
    1212  private
    13     procedure GenerateNodes(SourceNodes: TSourceNodes);
     13    procedure GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>);
    1414    procedure GenerateNode(SourceNode: TSourceNode);
    1515  public
     
    2121implementation
    2222
     23resourcestring
     24  SUnsupportedNodeType = 'Unsupported node type';
     25
    2326{ TGeneratorXml }
    2427
    25 procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodes);
     28procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>);
    2629var
    2730  I: Integer;
     
    3033    if SourceNodes[I] is TSourceNode then begin
    3134      GenerateNode(TSourceNode(SourceNodes[I]));
    32     end else raise Exception.Create('Unsupported node type');
     35    end else raise Exception.Create(SUnsupportedNodeType);
    3336  end;
    3437end;
     
    4245  if SourceNode = nil then begin
    4346  end else
    44   if SourceNode is TSourceNodes then begin
    45     GenerateNodes(TSourceNodes(SourceNode))
     47  if SourceNode is TSourceNodeList<TSourceNode> then begin
     48    GenerateNodes(TSourceNodeList<TSourceNode>(SourceNode))
    4649  end else
    4750  if SourceNode is TSourceNode then begin
     
    6366    AddTextLine('</' + SourceNode.ClassName + '>');
    6467  end else
    65     raise Exception.Create('Unsupported node type');
     68    raise Exception.Create(SUnsupportedNodeType);
    6669end;
    6770
Note: See TracChangeset for help on using the changeset viewer.