Ignore:
Timestamp:
Aug 29, 2017, 5:12:18 PM (7 years ago)
Author:
chronos
Message:
  • Added: New optimization using relative indexes to eliminate lots of pointer inc/dec operations.
  • Added: New command "multiply" extended command to replace while loops used for cell multiplication. Also added related optimization.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetDelphi.pas

    r72 r86  
    1414  TTargetDelphi = class(TBFTarget)
    1515  private
     16    function GetMemoryCell: string;
    1617  public
    1718    constructor Create; override;
     
    3839end;
    3940
     41function TTargetDelphi.GetMemoryCell: string;
     42begin
     43  Result := 'Memory[Pos';
     44  if FProgram[FProgramIndex].RelIndex > 0 then
     45    Result := Result + ' + ' + IntToStr(FProgram[FProgramIndex].RelIndex)
     46  else if FProgram[FProgramIndex].RelIndex < 0 then
     47    Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex));
     48  Result := Result + ']';
     49end;
     50
    4051procedure TTargetDelphi.Compile;
    4152begin
     
    6071      cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    6172      cmPointerDec: AddLine('Dec(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    62       cmInc: AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    63       cmDec: AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    64       cmSet: AddLine('Memory[Pos] := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    65       cmOutput: AddLine('Write(Chr(Memory[Pos]));');
    66       cmInput: AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);');
     73      cmInc: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     74      cmDec: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     75      cmSet: AddLine(GetMemoryCell + ' := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     76      cmMultipy: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     77      cmOutput: AddLine('Write(Chr(' + GetMemoryCell + '));');
     78      cmInput: AddLine('Read(ReadChar); ' + GetMemoryCell + ' := Ord(ReadChar);');
    6779      cmLoopStart: begin
    68         AddLine('while Memory[Pos] <> 0 do begin');
     80        AddLine('while ' + GetMemoryCell + ' <> 0 do begin');
    6981        Inc(Indent);
    7082      end;
Note: See TracChangeset for help on using the changeset viewer.