Changeset 90 for trunk


Ignore:
Timestamp:
Aug 29, 2017, 11:13:14 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: Infinite loop in Multiply optimization pass.
  • Modified: Made produced C# code more clean and nice.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r88 r90  
    480480    ProgramName := ExtractFileNameOnly(Core.Project.FileName);
    481481    Core.CurrentTarget.Messages.AddMessage(SCompileStart);
     482    Application.ProcessMessages;
    482483    Compile;
    483484    Core.CurrentTarget.Messages.AppendMessage(SDone);
  • trunk/Target/UTargetCSharp.pas

    r87 r90  
    6363  AddLine('using System;');
    6464  AddLine;
    65   AddLine('public class ' + ProgramName + ' {');
     65  AddLine('public class ' + ProgramName);
     66  AddLine('{');
    6667  Inc(Indent);
    67   AddLine('public static void Main() {');
     68  AddLine('public static void Main()');
     69  AddLine('{');
    6870  Inc(Indent);
    69   AddLine('char[] Memory;');
     71  AddLine('int[] Memory;');
    7072  AddLine('int Pos;');
    7173  AddLine;
    72   AddLine('Memory = new char[' + IntToStr(MemorySize) + '];');
     74  AddLine('Memory = new int[' + IntToStr(MemorySize) + '];');
    7375  AddLine('Pos = 0;');
    7476  FProgramIndex := 0;
    7577  while (FProgramIndex < Length(FProgram)) do begin
    7678    case FProgram[FProgramIndex].Command of
    77       cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    78       cmPointerDec: AddLine('Pos = Pos - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    79       cmInc: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    80       cmDec: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
    81       cmOutput: AddLine('Console.Write(' + GetMemoryCell + ');');
    82       cmInput: AddLine(GetMemoryCell + ' = Console.ReadKey().KeyChar;');
    83       cmSet: AddLine(GetMemoryCell + ' = (char)' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
    84       cmMultipy: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + (int)Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
     79      cmPointerInc: AddLine('Pos += ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     80      cmPointerDec: AddLine('Pos -= ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     81      cmInc: AddLine(GetMemoryCell + ' += ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     82      cmDec: AddLine(GetMemoryCell + ' -= ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     83      cmOutput: AddLine('Console.Write((char)' + GetMemoryCell + ');');
     84      cmInput: AddLine(GetMemoryCell + ' = (int)Console.ReadKey().KeyChar;');
     85      cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
     86      cmMultipy: begin
     87        if FProgram[FProgramIndex].Parameter = 1 then
     88          AddLine(GetMemoryCell + ' += Memory[Pos];')
     89        else
     90        if FProgram[FProgramIndex].Parameter > 0 then
     91          AddLine(GetMemoryCell + ' += Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';')
     92        else
     93        if FProgram[FProgramIndex].Parameter < 0 then
     94          AddLine(GetMemoryCell + ' -= Memory[Pos] * ' + IntToStr(Abs(FProgram[FProgramIndex].Parameter)) + ';');
     95      end;
    8596      cmLoopStart: begin
    86         AddLine('while(' + GetMemoryCell + ' != 0)');
     97        AddLine('while (' + GetMemoryCell + ' != 0)');
    8798        AddLine('{');
    8899        Inc(Indent);
  • trunk/UBFTarget.pas

    r86 r90  
    423423          NewProgram[NewProgramIndex].RelIndex := 0;
    424424          ProcessLoop := False;
     425          NumberOfBaseDecrement := 0;
    425426        end;
    426427      end;
Note: See TracChangeset for help on using the changeset viewer.