Changeset 126 for trunk/Target


Ignore:
Timestamp:
Jan 14, 2022, 7:13:36 PM (2 years ago)
Author:
chronos
Message:
  • Modified: SetZero optimization made as separate step.
  • Fixed: Error during compilation in CopyMultiply optimization.
Location:
trunk/Target
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetC.pas

    r125 r126  
    7474  AddLine('Pos = 0;');
    7575  FProgramIndex := 0;
    76   while (FProgramIndex < Length(FProgram)) do begin
     76  while FProgramIndex < FProgram.Count do begin
    7777    case FProgram[FProgramIndex].Command of
    7878      cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     
    8383      cmInput: AddLine(GetMemoryCell + ' = getchar();');
    8484      cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    85       cmMultipy: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     85      cmMultiply: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    8686      cmLoopStart: begin
    8787        AddLine('while(' + GetMemoryCell + ' != 0)');
  • trunk/Target/UTargetCSharp.pas

    r125 r126  
    7575  AddLine('Pos = 0;');
    7676  FProgramIndex := 0;
    77   while (FProgramIndex < Length(FProgram)) do begin
     77  while FProgramIndex < FProgram.Count do begin
    7878    case FProgram[FProgramIndex].Command of
    7979      cmPointerInc: AddLine('Pos += ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     
    8484      cmInput: AddLine(GetMemoryCell + ' = (int)Console.ReadKey().KeyChar;');
    8585      cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    86       cmMultipy: begin
     86      cmMultiply: begin
    8787        if FProgram[FProgramIndex].Parameter = 1 then
    8888          AddLine(GetMemoryCell + ' += Memory[Pos];')
  • trunk/Target/UTargetDelphi.pas

    r125 r126  
    6767  AddLine('Pos := 0;');
    6868  FProgramIndex := 0;
    69   while (FProgramIndex < Length(FProgram)) do begin
     69  while FProgramIndex < FProgram.Count do begin
    7070    case FProgram[FProgramIndex].Command of
    7171      cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     
    7474      cmDec: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7575      cmSet: AddLine(GetMemoryCell + ' := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    76       cmMultipy: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     76      cmMultiply: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7777      cmOutput: AddLine('Write(Chr(' + GetMemoryCell + '));');
    7878      cmInput: AddLine('Read(ReadChar); ' + GetMemoryCell + ' := Ord(ReadChar);');
  • trunk/Target/UTargetFPC.pas

    r125 r126  
    6969  AddLine('Pos := 0;');
    7070  FProgramIndex := 0;
    71   while (FProgramIndex < Length(FProgram)) do begin
     71  while FProgramIndex < FProgram.Count do begin
    7272    case FProgram[FProgramIndex].Command of
    7373      cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     
    7676      cmDec: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7777      cmSet: AddLine(GetMemoryCell + ' := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    78       cmMultipy: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     78      cmMultiply: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7979      cmOutput: AddLine('Write(Chr(' + GetMemoryCell + '));');
    8080      cmInput: AddLine('Read(ReadChar); ' + GetMemoryCell + ' := Ord(ReadChar);');
  • trunk/Target/UTargetInterpretter.pas

    r125 r126  
    8383  SProgramUpperLimit = 'Program run over upper limit';
    8484  SJumpTableInsistent = 'Jump table is inconsistent';
    85   SJumpTableColision = 'Jump table colision';
     85  SJumpTableCollision = 'Jump table collision';
    8686  SProgramNotRunning = 'Program not running';
    8787  SUnsupportedCommand = 'Unsupported command';
     
    9595  with Parent do
    9696  repeat
    97     while (FProgramIndex < Length(FProgram)) and (State <> rsStopped) do begin
     97    while (FProgramIndex < FProgram.Count) and (State <> rsStopped) do begin
    9898      if State = rsRunning then begin
    9999        if FProgramBreakpoints[FProgramIndex] then begin
     
    154154  I: Integer;
    155155begin
    156   for I := 0 to Length(FProgram) - 1 do begin
     156  for I := 0 to FProgram.Count - 1 do begin
    157157    case FProgram[I].Command of
    158       cmLoopStart: FProgram[I].Parameter := 0;
    159       cmLoopEnd: FProgram[I].Parameter := 0;
     158      cmLoopStart: FProgram.Operations[I].Parameter := 0;
     159      cmLoopEnd: FProgram.Operations[I].Parameter := 0;
    160160    end;
    161161  end;
    162162
    163163  SetLength(Loop, 0);
    164   for I := 0 to Length(FProgram) - 1 do begin
     164  for I := 0 to FProgram.Count - 1 do begin
    165165    case FProgram[I].Command of
    166166      cmLoopStart: begin
     
    170170      cmLoopEnd: begin
    171171        if FProgram[I].Parameter > 0 then
    172           raise Exception.Create(SJumpTableColision);
    173         FProgram[I].Parameter := Loop[High(Loop)];
     172          raise Exception.Create(SJumpTableCollision);
     173        FProgram.Operations[I].Parameter := Loop[High(Loop)];
    174174        if FProgram[Loop[High(Loop)]].Parameter > 0 then
    175           raise Exception.Create(SJumpTableColision);
    176         FProgram[Loop[High(Loop)]].Parameter := I;
     175          raise Exception.Create(SJumpTableCollision);
     176        FProgram.Operations[Loop[High(Loop)]].Parameter := I;
    177177        SetLength(Loop, Length(Loop) - 1);
    178178      end;
     
    303303  I: Integer;
    304304begin
    305   SetLength(FProgramBreakpoints, Length(FProgram));
     305  SetLength(FProgramBreakpoints, FProgram.Count);
    306306  for I := 0 to High(FProgramBreakpoints) do
    307307    FProgramBreakpoints[I] := False;
    308308  for I := 0 to BreakPoints.Count - 1 do
    309     if TBreakPoint(BreakPoints[I]).TargetAddress < Length(FProgramBreakpoints) then
    310       FProgramBreakpoints[TBreakPoint(BreakPoints[I]).TargetAddress] := True;
     309    if BreakPoints[I].TargetAddress < Length(FProgramBreakpoints) then
     310      FProgramBreakpoints[BreakPoints[I].TargetAddress] := True;
    311311end;
    312312
     
    316316begin
    317317  Result := '';
    318   for I := 0 to Length(FProgram) - 1 do begin
     318  for I := 0 to FProgram.Count - 1 do begin
    319319    Result := Result + GetOperationText(FProgram[I]);
    320320  end;
     
    438438  // Extended commands
    439439  FCommandTable[cmSet] := CommandSet;
    440   FCommandTable[cmMultipy] := CommandMultiply;
     440  FCommandTable[cmMultiply] := CommandMultiply;
    441441end;
    442442
  • trunk/Target/UTargetJava.pas

    r125 r126  
    7474  AddLine('Pos = 0;');
    7575  FProgramIndex := 0;
    76   while (FProgramIndex < Length(FProgram)) do begin
     76  while FProgramIndex < FProgram.Count do begin
    7777    case FProgram[FProgramIndex].Command of
    7878      cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     
    8383      cmInput: AddLine(GetMemoryCell + ' = (char)System.in.read();');
    8484      cmSet: AddLine(GetMemoryCell + ' = (char)' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    85       cmMultipy: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + (int)Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     85      cmMultiply: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + (int)Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    8686      cmLoopStart: begin
    8787        AddLine('while(' + GetMemoryCell + ' != 0)');
  • trunk/Target/UTargetJavascript.pas

    r125 r126  
    6161  AddLine('');
    6262  FProgramIndex := 0;
    63   while (FProgramIndex < Length(FProgram)) do begin
     63  while FProgramIndex < FProgram.Count do begin
    6464    case FProgram[FProgramIndex].Command of
    6565      cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     
    7070      cmInput: ; //AddLine(GetMemoryCell + ' = getchar();');
    7171      cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    72       cmMultipy: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     72      cmMultiply: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    7373      cmLoopStart: begin
    7474        AddLine('while(' + GetMemoryCell + ' != 0)');
  • trunk/Target/UTargetPHP.pas

    r125 r126  
    6666  AddLine('$Position = 0;');
    6767  FProgramIndex := 0;
    68   while (FProgramIndex < Length(FProgram)) do begin
     68  while FProgramIndex < FProgram.Count do begin
    6969    case FProgram[FProgramIndex].Command of
    7070      cmPointerInc: AddLine('$Position = $Position + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     
    7777      cmInput: AddLine(GetMemoryCell + ' = fgetc(STDIN);');
    7878      cmSet: AddLine(GetMemoryCell + ' = chr(' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    79       cmMultipy: AddLine(GetMemoryCell + ' = chr(ord(' + GetMemoryCell + ') + ord($Memory[$Position]) * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     79      cmMultiply: AddLine(GetMemoryCell + ' = chr(ord(' + GetMemoryCell + ') + ord($Memory[$Position]) * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    8080      cmLoopStart: begin
    8181        AddLine('while(' + GetMemoryCell + ' != "\0") {');
  • trunk/Target/UTargetPython.pas

    r125 r126  
    104104  AddLine('position = 0');
    105105  FProgramIndex := 0;
    106   while (FProgramIndex < Length(FProgram)) do begin
     106  while FProgramIndex < FProgram.Count do begin
    107107    case FProgram[FProgramIndex].Command of
    108108      cmPointerInc: AddLine('position += ' + IntToStr(FProgram[FProgramIndex].Parameter));
     
    116116      cmInput: AddLine(GetMemoryCell + ' = ord(getchar())');
    117117      cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter));
    118       cmMultipy: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + memory[position] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     118      cmMultiply: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + memory[position] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    119119      cmLoopStart: begin
    120120        AddLine('while(' + GetMemoryCell + ' != 0):');
Note: See TracChangeset for help on using the changeset viewer.