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

Legend:

Unmodified
Added
Removed
  • 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.
Note: See TracChangeset for help on using the changeset viewer.