Changeset 19


Ignore:
Timestamp:
Feb 11, 2012, 10:18:19 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Compiler moved to separate unit file.
  • Added: Compiler to PHP.
  • Added: Loading list of available compilers and list them for selection in menu Program - Target.
Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Languages/LazFuckIDE.cs.po

    r18 r19  
    189189msgstr "Nástroje"
    190190
    191 #: tmainform.menuitem40.caption
    192 msgid "Target"
    193 msgstr "Cíl"
    194 
    195191#: tmainform.menuitem5.caption
    196192msgctxt "tmainform.menuitem5.caption"
     
    202198msgstr "Program"
    203199
     200#: tmainform.menuitemtarget.caption
     201msgctxt "tmainform.menuitemtarget.caption"
     202msgid "Target"
     203msgstr "Cíl"
     204
    204205#: tmainform.toolbutton5.caption
    205206msgid "ToolButton5"
  • trunk/Languages/LazFuckIDE.po

    r18 r19  
    180180msgstr ""
    181181
    182 #: tmainform.menuitem40.caption
    183 msgid "Target"
    184 msgstr ""
    185 
    186182#: tmainform.menuitem5.caption
    187183msgctxt "tmainform.menuitem5.caption"
     
    193189msgstr ""
    194190
     191#: tmainform.menuitemtarget.caption
     192msgctxt "TMAINFORM.MENUITEMTARGET.CAPTION"
     193msgid "Target"
     194msgstr ""
     195
    195196#: tmainform.toolbutton5.caption
    196197msgid "ToolButton5"
  • trunk/LazFuckIDE.lpi

    r18 r19  
    8585      </Item5>
    8686    </RequiredPackages>
    87     <Units Count="7">
     87    <Units Count="10">
    8888      <Unit0>
    8989        <Filename Value="LazFuckIDE.lpr"/>
     
    129129        <UnitName Value="UOptionsForm"/>
    130130      </Unit6>
     131      <Unit7>
     132        <Filename Value="Compiler\UCompiler.pas"/>
     133        <IsPartOfProject Value="True"/>
     134        <UnitName Value="UCompiler"/>
     135      </Unit7>
     136      <Unit8>
     137        <Filename Value="Compiler\UCompilerDelphi.pas"/>
     138        <IsPartOfProject Value="True"/>
     139        <UnitName Value="UCompilerDelphi"/>
     140      </Unit8>
     141      <Unit9>
     142        <Filename Value="Compiler\UCompilerPHP.pas"/>
     143        <IsPartOfProject Value="True"/>
     144        <UnitName Value="UCompilerPHP"/>
     145      </Unit9>
    131146    </Units>
    132147  </ProjectOptions>
     
    139154    <SearchPaths>
    140155      <IncludeFiles Value="$(ProjOutDir)"/>
     156      <OtherUnitFiles Value="Compiler"/>
    141157      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    142158    </SearchPaths>
  • trunk/LazFuckIDE.lpr

    r15 r19  
    99  {$ENDIF}
    1010  Interfaces, // this includes the LCL widgetset
    11   Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo,
    12 UCompiledForm, UOptionsForm, CoolTranslator, Common, TemplateGenerics
     11  Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo,
     12  UCompiledForm, UOptionsForm, CoolTranslator, Common, TemplateGenerics,
     13  UCompiler, UCompilerDelphi, UCompilerPHP
    1314  { you can add units after this };
    1415
  • trunk/UBrainFuck.pas

    r18 r19  
    1111  TBrainFuckInterpretter = class;
    1212
    13   TCompilerTarget = (ctDelphi);
    14   TCompilerOptimization = (coNone, coNormal);
    15 
    16   { TBrainFuckCompiler }
    17 
    18   TBrainFuckCompiler = class
    19   private
    20     Indent: Integer;
    21     procedure AddLine(Text: string);
    22   public
    23     ProgramName: string;
    24     Source: string;
    25     Output: string;
    26     Target: TCompilerTarget;
    27     Optimization: TCompilerOptimization;
    28     procedure OptimizeSource;
    29     procedure Compile;
    30   end;
    3113
    3214  TRunState = (rsStopped, rsPaused, rsRunning);
     
    321303end;
    322304
    323 { TBrainFuckCompiler }
    324 
    325 procedure TBrainFuckCompiler.AddLine(Text: string);
    326 begin
    327   Output := Output + DupeString('  ', Indent) + Text + LineEnding;
    328 end;
    329 
    330 procedure TBrainFuckCompiler.OptimizeSource;
    331 begin
    332   // Remove redundand code
    333 
    334 end;
    335 
    336 procedure TBrainFuckCompiler.Compile;
    337 var
    338   I: Integer;
    339 begin
    340   Indent := 0;
    341   Output := '';
    342 
    343   AddLine('program ' + ProgramName + ';');
    344   AddLine('');
    345   AddLine('{$APPTYPE CONSOLE}');
    346   AddLine('');
    347   AddLine('var');
    348   AddLine('  Memory: array[0..30000] of Char;');
    349   AddLine('  Position: Integer;');
    350   AddLine('begin');
    351   Inc(Indent);
    352   for I := 1 to Length(Source) do begin
    353     case Source[I] of
    354       '>': AddLine('Inc(Position);');
    355       '<': AddLine('Dec(Position);');
    356       '+': AddLine('Memory[Position] := Succ(Memory[Position]);');
    357       '-': AddLine('Memory[Position] := Pred(Memory[Position]);');
    358       '.': AddLine('Write(Memory[Position]);');
    359       ',': AddLine('Read(Memory[Position]);');
    360       '[': begin
    361         AddLine('while Memory[Position] <> #0 do begin');
    362         Inc(Indent);
    363       end;
    364       ']': begin
    365         Dec(Indent);
    366         AddLine('end;');
    367       end;
    368     end;
    369   end;
    370   Dec(Indent);
    371   AddLine('end.');
    372 end;
    373 
    374305end.
    375306
  • trunk/UMainForm.lfm

    r18 r19  
    400400        }
    401401      end
    402       object MenuItem40: TMenuItem
     402      object MenuItemTarget: TMenuItem
    403403        Caption = 'Target'
    404404        object MenuItem21: TMenuItem
  • trunk/UMainForm.lrt

    r16 r19  
    44TMAINFORM.MENUITEM5.CAPTION=-
    55TMAINFORM.MENUITEM9.CAPTION=Program
    6 TMAINFORM.MENUITEM40.CAPTION=Target
     6TMAINFORM.MENUITEMTARGET.CAPTION=Target
    77TMAINFORM.MENUITEM21.CAPTION=New Item21
    88TMAINFORM.MENUITEM17.CAPTION=-
  • trunk/UMainForm.pas

    r18 r19  
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    99  Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils,
    10   SpecializedList;
     10  SpecializedList, UCompiler;
    1111
    1212type
     
    5959    MenuItem25: TMenuItem;
    6060    MenuItem26: TMenuItem;
    61     MenuItem40: TMenuItem;
     61    MenuItemTarget: TMenuItem;
    6262    MenuItem21: TMenuItem;
    6363    MenuItem3: TMenuItem;
     
    112112  private
    113113    procedure BrainFuckInterpreterChangeState(Sender: TObject);
     114    procedure MenuItemTargetClick(Sender: TObject);
    114115  public
    115116    Modified: Boolean;
     
    118119    BrainFuckInterpreter: TBrainFuckInterpretter;
    119120    BreakPoints: TListInteger;
     121    Compilers: TListObject; // TListObject<TCompiler>
    120122    procedure UpdateInterface;
    121123    procedure UpdateStatusBar;
     124    procedure UpdateTergetList;
    122125  end;
    123126
     
    130133
    131134uses
    132   UInterpreterForm, UApplicationInfo, UCompiledForm, UOptionsForm;
     135  UInterpreterForm, UApplicationInfo, UCompiledForm, UOptionsForm,
     136  UCompilerDelphi, UCompilerPHP;
    133137
    134138{ TMainForm }
     
    169173begin
    170174  UpdateInterface;
     175end;
     176
     177procedure TMainForm.MenuItemTargetClick(Sender: TObject);
     178var
     179  I: Integer;
     180begin
     181  with TMenuItem(Sender) do begin
     182    Checked := True;
     183    for I := 0 to Parent.Count - 1 do
     184      if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False
     185  end;
    171186end;
    172187
     
    194209end;
    195210
     211procedure TMainForm.UpdateTergetList;
     212var
     213  I: Integer;
     214  NewMenuItem: TMenuItem;
     215begin
     216  MenuItemTarget.Clear;
     217  for I := 0 to Compilers.Count - 1 do begin
     218    NewMenuItem := TMenuItem.Create(MenuItemTarget);
     219    NewMenuItem.Caption := TBrainFuckCompiler(Compilers[I]).Name;
     220    NewMenuItem.OnClick := MenuItemTargetClick;
     221    if I = 0 then NewMenuItem.Checked := True;
     222    MenuItemTarget.Add(NewMenuItem);
     223  end;
     224end;
     225
    196226procedure TMainForm.FormCreate(Sender: TObject);
    197227begin
     
    201231  BrainFuckCompiler := TBrainFuckCompiler.Create;
    202232  CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('cs');
     233  Compilers := TListObject.Create;
     234  Compilers.Add(TBrainFuckCompilerDelphi.Create);
     235  Compilers.Add(TBrainFuckCompilerPHP.Create);
     236  UpdateTergetList;
    203237end;
    204238
    205239procedure TMainForm.FormDestroy(Sender: TObject);
    206240begin
     241  Compilers.Free;
    207242  BrainFuckCompiler.Free;
    208243  BrainFuckInterpreter.Free;
     
    275310
    276311procedure TMainForm.ACompileExecute(Sender: TObject);
    277 begin
    278   BrainFuckCompiler.Source := MemoSource.Text;
    279   BrainFuckCompiler.ProgramName := ExtractFileNameOnly(ProjectFileName);
    280   BrainFuckCompiler.Compile;
    281   CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output;
    282   CompiledForm.Show;
     312var
     313  I: Integer;
     314begin
     315  I := 0;
     316  while (I < MenuItemTarget.Count) and (not MenuItemTarget.Items[I].Checked) do Inc(I);
     317  with TBrainFuckCompiler(Compilers[I]) do begin
     318    Source := MemoSource.Text;
     319    ProgramName := ExtractFileNameOnly(ProjectFileName);
     320    Compile;
     321    CompiledForm.MemoCompiled.Text := Output;
     322    CompiledForm.Show;
     323  end;
    283324end;
    284325
Note: See TracChangeset for help on using the changeset viewer.