Changeset 5


Ignore:
Timestamp:
Feb 9, 2012, 2:51:41 PM (12 years ago)
Author:
chronos
Message:
  • Added: BrainFuck code examples.
  • Added: View of data memory in interpretter.
  • Added: Show execution information in interpretter form.
Location:
trunk
Files:
9 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LazFuckIDE.lps

    r4 r5  
    1010        <IsPartOfProject Value="True"/>
    1111        <UnitName Value="LazFuckIDE"/>
    12         <UsageCount Value="23"/>
     12        <UsageCount Value="25"/>
    1313      </Unit0>
    1414      <Unit1>
     
    1818        <ResourceBaseClass Value="Form"/>
    1919        <UnitName Value="UMainForm"/>
    20         <IsVisibleTab Value="True"/>
    2120        <EditorIndex Value="0"/>
    2221        <WindowIndex Value="0"/>
    23         <TopLine Value="133"/>
    24         <CursorPos X="10" Y="146"/>
    25         <UsageCount Value="23"/>
     22        <TopLine Value="116"/>
     23        <CursorPos X="1" Y="131"/>
     24        <UsageCount Value="25"/>
    2625        <Loaded Value="True"/>
    2726        <LoadedDesigner Value="True"/>
     
    3332        <EditorIndex Value="3"/>
    3433        <WindowIndex Value="0"/>
    35         <TopLine Value="104"/>
    36         <CursorPos X="1" Y="117"/>
    37         <UsageCount Value="23"/>
     34        <TopLine Value="1"/>
     35        <CursorPos X="50" Y="2"/>
     36        <UsageCount Value="25"/>
    3837        <Loaded Value="True"/>
    3938      </Unit2>
     
    4443        <ResourceBaseClass Value="Form"/>
    4544        <UnitName Value="UInterpreterForm"/>
     45        <IsVisibleTab Value="True"/>
    4646        <EditorIndex Value="2"/>
    4747        <WindowIndex Value="0"/>
    48         <TopLine Value="11"/>
    49         <CursorPos X="19" Y="6"/>
    50         <UsageCount Value="23"/>
     48        <TopLine Value="51"/>
     49        <CursorPos X="37" Y="64"/>
     50        <UsageCount Value="25"/>
    5151        <Loaded Value="True"/>
    5252        <LoadedDesigner Value="True"/>
     
    7878        <TopLine Value="46"/>
    7979        <CursorPos X="47" Y="65"/>
    80         <UsageCount Value="20"/>
     80        <UsageCount Value="22"/>
    8181        <Loaded Value="True"/>
    8282      </Unit6>
     
    8787    <JumpHistory Count="30" HistoryIndex="29">
    8888      <Position1>
    89         <Filename Value="UBrainFuck.pas"/>
    90         <Caret Line="121" Column="1" TopLine="104"/>
     89        <Filename Value="UMainForm.pas"/>
     90        <Caret Line="90" Column="29" TopLine="77"/>
    9191      </Position1>
    9292      <Position2>
    93         <Filename Value="UBrainFuck.pas"/>
    94         <Caret Line="125" Column="1" TopLine="104"/>
     93        <Filename Value="UMainForm.pas"/>
     94        <Caret Line="79" Column="37" TopLine="61"/>
    9595      </Position2>
    9696      <Position3>
    97         <Filename Value="UBrainFuck.pas"/>
    98         <Caret Line="121" Column="1" TopLine="104"/>
     97        <Filename Value="UMainForm.pas"/>
     98        <Caret Line="70" Column="13" TopLine="63"/>
    9999      </Position3>
    100100      <Position4>
    101         <Filename Value="UBrainFuck.pas"/>
    102         <Caret Line="123" Column="1" TopLine="104"/>
     101        <Filename Value="UMainForm.pas"/>
     102        <Caret Line="118" Column="1" TopLine="116"/>
    103103      </Position4>
    104104      <Position5>
    105         <Filename Value="UBrainFuck.pas"/>
    106         <Caret Line="125" Column="1" TopLine="104"/>
     105        <Filename Value="UMainForm.pas"/>
     106        <Caret Line="130" Column="1" TopLine="124"/>
    107107      </Position5>
    108108      <Position6>
    109         <Filename Value="UBrainFuck.pas"/>
    110         <Caret Line="130" Column="1" TopLine="117"/>
     109        <Filename Value="UMainForm.pas"/>
     110        <Caret Line="140" Column="3" TopLine="132"/>
    111111      </Position6>
    112112      <Position7>
    113         <Filename Value="UBrainFuck.pas"/>
    114         <Caret Line="123" Column="14" TopLine="117"/>
     113        <Filename Value="UMainForm.pas"/>
     114        <Caret Line="129" Column="10" TopLine="126"/>
    115115      </Position7>
    116116      <Position8>
    117         <Filename Value="UBrainFuck.pas"/>
    118         <Caret Line="117" Column="1" TopLine="104"/>
     117        <Filename Value="UMainForm.pas"/>
     118        <Caret Line="72" Column="15" TopLine="59"/>
    119119      </Position8>
    120120      <Position9>
    121         <Filename Value="UBrainFuck.pas"/>
    122         <Caret Line="123" Column="1" TopLine="104"/>
     121        <Filename Value="UMainForm.pas"/>
     122        <Caret Line="130" Column="3" TopLine="127"/>
    123123      </Position9>
    124124      <Position10>
    125         <Filename Value="UBrainFuck.pas"/>
    126         <Caret Line="125" Column="1" TopLine="104"/>
     125        <Filename Value="UMainForm.pas"/>
     126        <Caret Line="157" Column="42" TopLine="132"/>
    127127      </Position10>
    128128      <Position11>
    129         <Filename Value="UBrainFuck.pas"/>
    130         <Caret Line="71" Column="42" TopLine="67"/>
     129        <Filename Value="UMainForm.pas"/>
     130        <Caret Line="59" Column="15" TopLine="46"/>
    131131      </Position11>
    132132      <Position12>
    133133        <Filename Value="UMainForm.pas"/>
    134         <Caret Line="98" Column="35" TopLine="40"/>
     134        <Caret Line="106" Column="24" TopLine="89"/>
    135135      </Position12>
    136136      <Position13>
    137137        <Filename Value="UMainForm.pas"/>
    138         <Caret Line="99" Column="35" TopLine="74"/>
     138        <Caret Line="97" Column="19" TopLine="94"/>
    139139      </Position13>
    140140      <Position14>
    141141        <Filename Value="UMainForm.pas"/>
    142         <Caret Line="101" Column="35" TopLine="76"/>
     142        <Caret Line="110" Column="54" TopLine="100"/>
    143143      </Position14>
    144144      <Position15>
    145145        <Filename Value="UMainForm.pas"/>
    146         <Caret Line="114" Column="1" TopLine="91"/>
     146        <Caret Line="146" Column="12" TopLine="133"/>
    147147      </Position15>
    148148      <Position16>
    149149        <Filename Value="UMainForm.pas"/>
    150         <Caret Line="68" Column="31" TopLine="48"/>
     150        <Caret Line="102" Column="42" TopLine="100"/>
    151151      </Position16>
    152152      <Position17>
    153153        <Filename Value="UMainForm.pas"/>
    154         <Caret Line="90" Column="29" TopLine="77"/>
     154        <Caret Line="125" Column="54" TopLine="100"/>
    155155      </Position17>
    156156      <Position18>
    157         <Filename Value="UMainForm.pas"/>
    158         <Caret Line="79" Column="37" TopLine="61"/>
     157        <Filename Value="UInterpreterForm.pas"/>
     158        <Caret Line="6" Column="19" TopLine="9"/>
    159159      </Position18>
    160160      <Position19>
    161         <Filename Value="UMainForm.pas"/>
    162         <Caret Line="70" Column="13" TopLine="63"/>
     161        <Filename Value="UInterpreterForm.pas"/>
     162        <Caret Line="53" Column="1" TopLine="23"/>
    163163      </Position19>
    164164      <Position20>
    165         <Filename Value="UMainForm.pas"/>
    166         <Caret Line="118" Column="1" TopLine="116"/>
     165        <Filename Value="UInterpreterForm.pas"/>
     166        <Caret Line="54" Column="1" TopLine="29"/>
    167167      </Position20>
    168168      <Position21>
    169         <Filename Value="UMainForm.pas"/>
    170         <Caret Line="130" Column="1" TopLine="124"/>
     169        <Filename Value="UInterpreterForm.pas"/>
     170        <Caret Line="56" Column="77" TopLine="34"/>
    171171      </Position21>
    172172      <Position22>
    173         <Filename Value="UMainForm.pas"/>
    174         <Caret Line="140" Column="3" TopLine="132"/>
     173        <Filename Value="UBrainFuck.pas"/>
     174        <Caret Line="37" Column="5" TopLine="24"/>
    175175      </Position22>
    176176      <Position23>
    177         <Filename Value="UMainForm.pas"/>
    178         <Caret Line="129" Column="10" TopLine="126"/>
     177        <Filename Value="UInterpreterForm.pas"/>
     178        <Caret Line="56" Column="77" TopLine="34"/>
    179179      </Position23>
    180180      <Position24>
    181         <Filename Value="UMainForm.pas"/>
    182         <Caret Line="72" Column="15" TopLine="59"/>
     181        <Filename Value="UInterpreterForm.pas"/>
     182        <Caret Line="57" Column="77" TopLine="35"/>
    183183      </Position24>
    184184      <Position25>
    185         <Filename Value="UMainForm.pas"/>
    186         <Caret Line="130" Column="3" TopLine="127"/>
     185        <Filename Value="UInterpreterForm.pas"/>
     186        <Caret Line="59" Column="77" TopLine="36"/>
    187187      </Position25>
    188188      <Position26>
    189         <Filename Value="UMainForm.pas"/>
    190         <Caret Line="157" Column="42" TopLine="132"/>
     189        <Filename Value="UInterpreterForm.pas"/>
     190        <Caret Line="40" Column="15" TopLine="22"/>
    191191      </Position26>
    192192      <Position27>
    193         <Filename Value="UMainForm.pas"/>
    194         <Caret Line="59" Column="15" TopLine="46"/>
     193        <Filename Value="UInterpreterForm.pas"/>
     194        <Caret Line="14" Column="1" TopLine="19"/>
    195195      </Position27>
    196196      <Position28>
    197         <Filename Value="UMainForm.pas"/>
    198         <Caret Line="106" Column="24" TopLine="89"/>
     197        <Filename Value="UInterpreterForm.pas"/>
     198        <Caret Line="67" Column="24" TopLine="54"/>
    199199      </Position28>
    200200      <Position29>
    201         <Filename Value="UMainForm.pas"/>
    202         <Caret Line="97" Column="19" TopLine="94"/>
     201        <Filename Value="UInterpreterForm.pas"/>
     202        <Caret Line="81" Column="21" TopLine="63"/>
    203203      </Position29>
    204204      <Position30>
    205         <Filename Value="UMainForm.pas"/>
    206         <Caret Line="110" Column="54" TopLine="100"/>
     205        <Filename Value="UInterpreterForm.pas"/>
     206        <Caret Line="64" Column="3" TopLine="51"/>
    207207      </Position30>
    208208    </JumpHistory>
  • trunk/UBrainFuck.pas

    r3 r5  
    66
    77uses
    8   Classes, SysUtils, Dialogs;
     8  Classes, SysUtils, Dialogs, Forms;
    99
    1010type
     
    3535    Input: string;
    3636    InputPosition: Integer;
     37    StepCount: Integer;
    3738    procedure Reset;
    3839    procedure SingleStep;
     
    4849  SProgramLowerLimit = 'Program run over lower limit';
    4950  SProgramUpperLimit = 'Program run over upper limit';
     51  SReadInputError = 'Read input error';
    5052
    5153{ TBrainFuckInterpreter }
     
    6062  Character: string;
    6163begin
    62   Character := Copy(Input, InputPosition, 1);
    63   Result := Ord(Character[1]);
    64   Inc(InputPosition);
     64  if InputPosition < Length(Input) then begin
     65    Character := Copy(Input, InputPosition, 1);
     66    Result := Ord(Character[1]);
     67    Inc(InputPosition);
     68  end else
     69    raise Exception.Create(SReadInputError);
    6570end;
    6671
     
    8489    Memory[I] := 0;
    8590  SetLength(Loop, 0);
     91  StepCount := 0;
    8692end;
    8793
     
    129135  end;
    130136  Inc(SourcePosition);
     137  Inc(StepCount);
    131138end;
    132139
     
    134141begin
    135142  Reset;
    136   while SourcePosition < Length(Source) do
     143  while SourcePosition < Length(Source) do begin
    137144    SingleStep;
     145    Application.ProcessMessages;
     146  end;
    138147end;
    139148
  • trunk/UInterpreterForm.lfm

    r2 r5  
    11object InterpreterForm: TInterpreterForm
    2   Left = 305
    3   Height = 450
    4   Top = 124
    5   Width = 614
     2  Left = 242
     3  Height = 509
     4  Top = 116
     5  Width = 762
    66  Caption = 'Runtime'
    7   ClientHeight = 450
    8   ClientWidth = 614
     7  ClientHeight = 509
     8  ClientWidth = 762
    99  LCLVersion = '0.9.31'
    10   object Panel1: TPanel
     10  object Panel3: TPanel
    1111    Left = 0
    12     Height = 234
     12    Height = 509
    1313    Top = 0
    14     Width = 614
    15     Align = alTop
     14    Width = 323
     15    Align = alLeft
    1616    BevelOuter = bvNone
    17     ClientHeight = 234
    18     ClientWidth = 614
     17    ClientHeight = 509
     18    ClientWidth = 323
    1919    TabOrder = 0
    20     object MemoInput: TMemo
     20    object Panel1: TPanel
     21      Left = 0
     22      Height = 242
     23      Top = 0
     24      Width = 323
     25      Align = alTop
     26      BevelOuter = bvNone
     27      ClientHeight = 242
     28      ClientWidth = 323
     29      TabOrder = 0
     30      object MemoInput: TMemo
     31        Left = 8
     32        Height = 210
     33        Top = 24
     34        Width = 309
     35        Anchors = [akTop, akLeft, akRight, akBottom]
     36        TabOrder = 0
     37      end
     38      object Label1: TLabel
     39        Left = 8
     40        Height = 14
     41        Top = 8
     42        Width = 31
     43        Caption = 'Input:'
     44        ParentColor = False
     45      end
     46    end
     47    object Splitter1: TSplitter
     48      Cursor = crVSplit
     49      Left = 0
     50      Height = 5
     51      Top = 242
     52      Width = 323
     53      Align = alTop
     54      ResizeAnchor = akTop
     55    end
     56    object Panel2: TPanel
     57      Left = 0
     58      Height = 262
     59      Top = 247
     60      Width = 323
     61      Align = alClient
     62      BevelOuter = bvNone
     63      ClientHeight = 262
     64      ClientWidth = 323
     65      TabOrder = 2
     66      object Label2: TLabel
     67        Left = 8
     68        Height = 14
     69        Top = 6
     70        Width = 39
     71        Caption = 'Output:'
     72        ParentColor = False
     73      end
     74      object MemoOutput: TMemo
     75        Left = 8
     76        Height = 237
     77        Top = 22
     78        Width = 309
     79        Anchors = [akTop, akLeft, akRight, akBottom]
     80        TabOrder = 0
     81      end
     82    end
     83  end
     84  object Splitter2: TSplitter
     85    Left = 323
     86    Height = 509
     87    Top = 0
     88    Width = 5
     89  end
     90  object Panel4: TPanel
     91    Left = 328
     92    Height = 509
     93    Top = 0
     94    Width = 434
     95    Align = alClient
     96    BevelOuter = bvNone
     97    ClientHeight = 509
     98    ClientWidth = 434
     99    TabOrder = 2
     100    object Label3: TLabel
     101      Left = 0
     102      Height = 14
     103      Top = 8
     104      Width = 82
     105      Caption = 'Program pointer:'
     106      ParentColor = False
     107    end
     108    object LabelProgramPointer: TLabel
     109      Left = 112
     110      Height = 14
     111      Top = 8
     112      Width = 10
     113      Caption = '   '
     114      ParentColor = False
     115    end
     116    object Label5: TLabel
     117      Left = 1
     118      Height = 14
     119      Top = 24
     120      Width = 80
     121      Caption = 'Memory pointer:'
     122      ParentColor = False
     123    end
     124    object LabelMemoryPointer: TLabel
     125      Left = 112
     126      Height = 14
     127      Top = 24
     128      Width = 10
     129      Caption = '   '
     130      ParentColor = False
     131    end
     132    object Label4: TLabel
     133      Left = 1
     134      Height = 14
     135      Top = 42
     136      Width = 67
     137      Caption = 'Step counter:'
     138      ParentColor = False
     139    end
     140    object LabelStepCounter: TLabel
     141      Left = 112
     142      Height = 14
     143      Top = 42
     144      Width = 10
     145      Caption = '   '
     146      ParentColor = False
     147    end
     148    object ListViewMemory: TListView
    21149      Left = 8
    22       Height = 202
    23       Top = 24
    24       Width = 600
     150      Height = 384
     151      Top = 120
     152      Width = 422
    25153      Anchors = [akTop, akLeft, akRight, akBottom]
     154      Columns = <     
     155        item
     156          Caption = 'Address'
     157          Width = 80
     158        end     
     159        item
     160          Caption = 'Data'
     161          Width = 300
     162        end>
     163      Font.Height = -11
     164      Font.Name = 'Courier New'
     165      OwnerData = True
     166      ParentFont = False
     167      ReadOnly = True
    26168      TabOrder = 0
     169      ViewStyle = vsReport
     170      OnData = ListViewMemoryData
    27171    end
    28     object Label1: TLabel
     172    object Label6: TLabel
    29173      Left = 8
    30174      Height = 14
    31       Top = 8
    32       Width = 31
    33       Caption = 'Input:'
     175      Top = 104
     176      Width = 43
     177      Caption = 'Memory:'
    34178      ParentColor = False
    35179    end
    36180  end
    37   object Panel2: TPanel
    38     Left = 0
    39     Height = 216
    40     Top = 234
    41     Width = 614
    42     Align = alClient
    43     BevelOuter = bvNone
    44     ClientHeight = 216
    45     ClientWidth = 614
    46     TabOrder = 1
    47     object Label2: TLabel
    48       Left = 8
    49       Height = 14
    50       Top = 6
    51       Width = 39
    52       Caption = 'Output:'
    53       ParentColor = False
    54     end
    55     object MemoOutput: TMemo
    56       Left = 8
    57       Height = 191
    58       Top = 22
    59       Width = 600
    60       Anchors = [akTop, akLeft, akRight, akBottom]
    61       TabOrder = 0
    62     end
     181  object Timer1: TTimer
     182    Interval = 500
     183    OnTimer = Timer1Timer
     184    left = 495
     185    top = 61
    63186  end
    64187end
  • trunk/UInterpreterForm.pas

    r2 r5  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls;
     9  ExtCtrls, ComCtrls;
     10
     11const
     12  RowSize = 16;
    1013
    1114type
     
    1619    Label1: TLabel;
    1720    Label2: TLabel;
     21    Label3: TLabel;
     22    Label4: TLabel;
     23    Label6: TLabel;
     24    LabelStepCounter: TLabel;
     25    LabelProgramPointer: TLabel;
     26    Label5: TLabel;
     27    LabelMemoryPointer: TLabel;
     28    ListViewMemory: TListView;
    1829    MemoInput: TMemo;
    1930    MemoOutput: TMemo;
    2031    Panel1: TPanel;
    2132    Panel2: TPanel;
     33    Panel3: TPanel;
     34    Panel4: TPanel;
     35    Splitter1: TSplitter;
     36    Splitter2: TSplitter;
     37    Timer1: TTimer;
     38    procedure ListViewMemoryData(Sender: TObject; Item: TListItem);
     39    procedure Timer1Timer(Sender: TObject);
    2240  private
    2341    { private declarations }
    2442  public
    25     { public declarations }
     43    procedure RefreshListViewMemory;
    2644  end;
    2745
     
    3149implementation
    3250
     51uses
     52  UMainForm;
     53
    3354{$R *.lfm}
     55
     56{ TInterpreterForm }
     57
     58procedure TInterpreterForm.Timer1Timer(Sender: TObject);
     59begin
     60  LabelProgramPointer.Caption := IntToStr(MainForm.BrainFuckInterpreter.SourcePosition);
     61  LabelMemoryPointer.Caption := IntToStr(MainForm.BrainFuckInterpreter.MemoryPosition);
     62  LabelStepCounter.Caption := IntToStr(MainForm.BrainFuckInterpreter.StepCount);
     63  RefreshListViewMemory;
     64  MemoOutput.Lines.Text := MainForm.BrainFuckInterpreter.Output;
     65end;
     66
     67procedure TInterpreterForm.RefreshListViewMemory;
     68begin
     69  ListViewMemory.Items.Count := Trunc(Length(MainForm.BrainFuckInterpreter.Memory) / RowSize);
     70  ListViewMemory.Refresh;
     71end;
     72
     73procedure TInterpreterForm.ListViewMemoryData(Sender: TObject; Item: TListItem);
     74var
     75  Row: string;
     76  I: Integer;
     77begin
     78  with MainForm.BrainFuckInterpreter do
     79  if (Item.Index >= 0) and (Item.Index < Trunc(Length(Memory) / RowSize)) then begin
     80    Item.Caption := IntToHex(Item.Index * RowSize, 8);
     81    Row := '';
     82    for I := 0 to RowSize - 1 do
     83      Row := Row + ' ' + IntToHex(Memory[Item.Index * RowSize + I], 2);
     84    Item.SubItems.Add(Row);
     85  end;
     86end;
    3487
    3588end.
  • trunk/UMainForm.lfm

    r4 r5  
    840840  end
    841841  object OpenDialog1: TOpenDialog
    842     DefaultExt = '.bf'
    843     Filter = 'BrainFuck (*.bf)|*.bf|Any file (*.*)|*.*'
     842    DefaultExt = '.b'
     843    Filter = 'BrainFuck (*.b)|*.b|Any file (*.*)|*.*'
    844844    left = 192
    845845    top = 157
    846846  end
    847847  object SaveDialog1: TSaveDialog
    848     DefaultExt = '.bf'
    849     Filter = 'BrainFuck (*.bf)|*.bf|Any file (*.*)|*.*'
     848    DefaultExt = '.b'
     849    Filter = 'BrainFuck (*.b)|*.b|Any file (*.*)|*.*'
    850850    left = 192
    851851    top = 208
  • trunk/UMainForm.pas

    r4 r5  
    8989procedure TMainForm.FormShow(Sender: TObject);
    9090begin
    91   UpdateInterface;
     91  AProjectNew.Execute;
    9292end;
    9393
     
    129129  BrainFuckInterpreter.Source := MemoSource.Lines.Text;
    130130  BrainFuckInterpreter.Run;
    131   InterpreterForm.MemoOutput.Lines.Text := BrainFuckInterpreter.Output;
    132131end;
    133132
Note: See TracChangeset for help on using the changeset viewer.