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/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
Note: See TracChangeset for help on using the changeset viewer.