unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PaxCompiler, PaxProgram;

type
  TForm1 = class(TForm)
    PaxCompiler1: TPaxCompiler;
    PaxPascalLanguage1: TPaxPascalLanguage;
    PaxProgram1: TPaxProgram;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  t: Integer;
begin
  PaxCompiler1.Reset;
  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);

  PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName);

  PaxCompiler1.AddCode('1', 'procedure P();');
  PaxCompiler1.AddCode('1', 'var');
  PaxCompiler1.AddCode('1', '  d1, d2: Double;');
  PaxCompiler1.AddCode('1', '  I: Integer;');
  PaxCompiler1.AddCode('1', 'begin');
  PaxCompiler1.AddCode('1', '  d1 := 5.4;');
  PaxCompiler1.AddCode('1', '  d2 := 9009960.3;');
  PaxCompiler1.AddCode('1', '  I := 0;');
  PaxCompiler1.AddCode('1', '  while d1 < d2 do');
  PaxCompiler1.AddCode('1', '  begin');
  PaxCompiler1.AddCode('1', '    Inc(I);');
  PaxCompiler1.AddCode('1', '    d1 := d1 + 0.5;');
  PaxCompiler1.AddCode('1', '  end;');
  PaxCompiler1.AddCode('1', 'end;');
  PaxCompiler1.AddCode('1', 'begin');
  PaxCompiler1.AddCode('1', '  P();');
  PaxCompiler1.AddCode('1', 'end.');
  if PaxCompiler1.Compile(PaxProgram1) then
  begin
    t := GetTickCount;
    PaxProgram1.Run;
    ShowMessage(IntToStr(GetTickCount - t));
  end
  else
    for I:=0 to PaxCompiler1.ErrorCount - 1 do
      ShowMessage(PaxCompiler1.ErrorMessage[I]);
end;

procedure P();
var
  d1, d2: Double;
  I: Integer;
begin
  d1 := 5.4;
  d2 := 9009960.3;
  I := 0;
  while d1 < d2 do
  begin
    Inc(I);
    d1 := d1 + 0.5;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  t: Integer;
begin
  t := GetTickCount;
  P;
  ShowMessage(IntToStr(GetTickCount - t));
end;

end.
