Changeset 49 for trunk


Ignore:
Timestamp:
Jul 12, 2012, 9:56:58 AM (12 years ago)
Author:
chronos
Message:
  • Added: Optimization of sequence [-] in PHP target.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r48 r49  
    11object MainForm: TMainForm
    2   Left = 236
     2  Left = 223
    33  Height = 430
    4   Top = 144
     4  Top = 176
    55  Width = 670
    66  Caption = 'LazFuck'
  • trunk/Target/UTargetPHP.pas

    r48 r49  
    5757end;
    5858
     59function CheckClear: Boolean;
     60begin
     61  Result := (FSourceCode[I] = '[') and (Length(FSourceCode) >= I + 2) and
     62    (FSourceCode[I + 1] = '-') and (FSourceCode[I + 2] = ']');
     63end;
     64
    5965begin
    6066  inherited;
     
    6672  AddLine('$Memory = str_repeat("\0", 30000);');
    6773  AddLine('$Position = 0;');
    68   for I := 1 to Length(FSourceCode) do begin
     74  I := 1;
     75  while (I <= Length(FSourceCode)) do begin
    6976    case FSourceCode[I] of
    7077      '>': begin
     
    8794      ',': AddLine('$Memory[$Position] = fgetc(STDIN);');
    8895      '[': begin
    89         AddLine('while($Memory[$Position] != "\0") {');
    90         Inc(Indent);
     96        if CheckClear then begin
     97          AddLine('$Memory[$Position] = "\0";');
     98          Inc(I, 2);
     99        end else begin
     100          AddLine('while($Memory[$Position] != "\0") {');
     101          Inc(Indent);
     102        end;
    91103      end;
    92104      ']': begin
     
    95107      end;
    96108    end;
     109    Inc(I);
    97110  end;
    98111  AddLine('');
Note: See TracChangeset for help on using the changeset viewer.