Ignore:
Timestamp:
Jan 16, 2018, 10:38:33 AM (7 years ago)
Author:
chronos
Message:
  • Modified: General definition of functions. Static functions are now dynamic predefined.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler/UFormMain.pas

    r139 r140  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   UTargetCode, USourceCode;
     9  UTargetCode, USourceCode, USourceExecutor, USourceGenerator;
    1010
    1111type
     
    1414
    1515  TForm1 = class(TForm)
     16    ButtonSend: TButton;
    1617    ButtonBuild: TButton;
     18    Edit1: TEdit;
     19    Label1: TLabel;
     20    Label2: TLabel;
     21    Label3: TLabel;
     22    Label4: TLabel;
    1723    MemoOutput: TMemo;
    1824    MemoSource: TMemo;
     25    MemoGenerator: TMemo;
    1926    procedure ButtonBuildClick(Sender: TObject);
     27    procedure ButtonSendClick(Sender: TObject);
     28    procedure FormCreate(Sender: TObject);
     29    procedure FormDestroy(Sender: TObject);
    2030    procedure FormShow(Sender: TObject);
    2131  private
    22 
     32    InputBuffer: TStringList;
     33    procedure ExecutorOutput(Text: string);
     34    function ExecutorInput: string;
    2335  public
    24     procedure ExecutorOutput(Text: string);
    2536  end;
    2637
     
    4758    Add('PrintLn Text1');
    4859    Add('PrintLn Text2');
     60    Add('InputLn Text3');
     61    Add('PrintLn Text3');
    4962  end;
    5063end;
     
    6477  Executor := TSourceExecutor.Create;
    6578  Executor.OnOutput := ExecutorOutput;
     79  Executor.OnInput := ExecutorInput;
    6680  Generator := TSourceGenerator.Create;
    6781
    6882  Compiler.Compile(MemoSource.Text, SourceCode);
     83  MemoGenerator.Text := Generator.Generate(SourceCode);
    6984  Executor.Execute(SourceCode);
    70   Generator.Generate(SourceCode);
    7185
    7286  Generator.Free;
     
    7791end;
    7892
     93procedure TForm1.ButtonSendClick(Sender: TObject);
     94begin
     95  InputBuffer.Add(Edit1.Text);
     96  Edit1.Text := '';
     97end;
     98
     99procedure TForm1.FormCreate(Sender: TObject);
     100begin
     101  InputBuffer := TStringList.Create;
     102end;
     103
     104procedure TForm1.FormDestroy(Sender: TObject);
     105begin
     106  InputBuffer.Free;
     107end;
     108
    79109procedure TForm1.ExecutorOutput(Text: string);
    80110begin
     
    82112end;
    83113
     114function TForm1.ExecutorInput: string;
     115begin
     116  while InputBuffer.Count = 0 do begin
     117    Sleep(50);
     118    Application.ProcessMessages;
     119  end;
     120  Result := InputBuffer[0];
     121  InputBuffer.Delete(0);
     122end;
     123
    84124end.
    85125
Note: See TracChangeset for help on using the changeset viewer.