Ignore:
Timestamp:
Feb 11, 2012, 10:56:03 PM (12 years ago)
Author:
chronos
Message:
  • Added: Action to shrink source code by remove all non printable characters.
  • Added: Optimalization for generated code by Delphi and PHP compiler. All same language commands laying side by side will be converted to single generated operation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/UCompilerPHP.pas

    r19 r20  
    3131var
    3232  I: Integer;
     33  Sum: Integer;
     34
     35function CheckOccurence(C: Char): Integer;
     36begin
     37  Result := 1;
     38  if Optimization = coNormal then
     39  while ((I + 1) <= Length(Source)) and (Source[I + 1] = C) do begin
     40    Inc(Result);
     41    Inc(I)
     42  end;
     43end;
     44
    3345begin
    3446  Indent := 0;
     
    4153  for I := 1 to Length(Source) do begin
    4254    case Source[I] of
    43       '>': AddLine('$Position++;');
    44       '<': AddLine('$Position--;');
    45       '+': AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + 1);');
    46       '-': AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - 1);');
     55      '>': begin
     56        Sum := CheckOccurence('>');
     57        AddLine('$Position = $Position + ' + IntToStr(Sum) + ';');
     58      end;
     59      '<': begin
     60        Sum := CheckOccurence('<');
     61        AddLine('$Position = $Position - ' + IntToStr(Sum) + ';');
     62      end;
     63      '+': begin
     64        Sum := CheckOccurence('+');
     65        AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + ' + IntToStr(Sum) + ');');
     66      end;
     67      '-': begin
     68        Sum := CheckOccurence('-');
     69        AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - ' + IntToStr(Sum) + ');');
     70      end;
    4771      '.': AddLine('echo($Memory[$Position]);');
    4872      ',': AddLine('$Memory[$Position] = fgetc(STDIN);');
Note: See TracChangeset for help on using the changeset viewer.