Ignore:
Timestamp:
Dec 4, 2014, 2:59:28 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Now commands cmInc, cmDec, cmPointerInc, cmPointerDec and cmSet use numeric parameter to merge multiple small steps to one unary operation with numeric parameter. Optimization is done on TTarget side and not on each specific targets.
  • Added: Optimization to eliminate redundant source code.
  • Added: Optimization level option in Options dialog.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetPHP.pas

    r60 r64  
    5858  FProgramIndex := 0;
    5959  while (FProgramIndex < Length(FProgram)) do begin
    60     case FProgram[FProgramIndex] of
    61       cmPointerInc: begin
    62         Sum := CheckOccurence(cmPointerInc);
    63         AddLine('$Position = $Position + ' + IntToStr(Sum) + ';');
    64       end;
    65       cmPointerDec: begin
    66         Sum := CheckOccurence(cmPointerDec);
    67         AddLine('$Position = $Position - ' + IntToStr(Sum) + ';');
    68       end;
    69       cmInc: begin
    70         Sum := CheckOccurence(cmInc);
    71         AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + ' + IntToStr(Sum) + ');');
    72       end;
    73       cmDec: begin
    74         Sum := CheckOccurence(cmDec);
    75         AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - ' + IntToStr(Sum) + ');');
    76       end;
     60    case FProgram[FProgramIndex].Command of
     61      cmPointerInc: AddLine('$Position = $Position + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     62      cmPointerDec: AddLine('$Position = $Position - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     63      cmInc: AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     64      cmDec: AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    7765      cmOutput: AddLine('echo($Memory[$Position]);');
    7866      cmInput: AddLine('$Memory[$Position] = fgetc(STDIN);');
     67      cmSet: AddLine('$Memory[$Position] = chr(' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    7968      cmLoopStart: begin
    80         if CheckClear then begin
    81           AddLine('$Memory[$Position] = "\0";');
    82           Inc(FProgramIndex, 2);
    83         end else begin
    84           AddLine('while($Memory[$Position] != "\0") {');
    85           Inc(Indent);
    86         end;
     69        AddLine('while($Memory[$Position] != "\0") {');
     70        Inc(Indent);
    8771      end;
    8872      cmLoopEnd: begin
Note: See TracChangeset for help on using the changeset viewer.