-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemomain.pas
127 lines (108 loc) · 3.89 KB
/
demomain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
(*----------------------------------------------------------------------------*)
(* Demonstration of the INFLISP lisp interpreter. *)
(* Inflisp is encapsulated in the Delphi component TLispExpression. *)
(* Author: Joachim Pimiskern. *)
(*----------------------------------------------------------------------------*)
unit demomain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Express;
type
TFormDemoMain = class(TForm)
PanelRight: TPanel;
ButtonClose: TButton;
PanelTop: TPanel;
PanelBottom: TPanel;
PanelLeft: TPanel;
PanelMiddle: TPanel;
Memo1: TMemo;
Splitter1: TSplitter;
Memo2: TMemo;
ButtonRun: TButton;
LispExpression: TLispExpression;
ButtonAbout: TButton;
procedure ButtonCloseClick(Sender: TObject);
procedure ButtonRunClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ButtonAboutClick(Sender: TObject);
private
procedure Process(input,output: TStringList);
public
end;
var
FormDemoMain: TFormDemoMain;
implementation
uses
lspglobl, lsplock, lspcreat, lspinout;
{$R *.DFM}
procedure TFormDemoMain.ButtonCloseClick(Sender: TObject);
begin
Close;
end;
procedure TFormDemoMain.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ((Key = VK_F4) and not (ssAlt in Shift)) then
ButtonRunClick(nil);
end;
procedure TFormDemoMain.ButtonRunClick(Sender: TObject);
begin
Process(TStringList(Memo1.Lines),TStringList(Memo2.Lines));
end;
procedure TFormDemoMain.Process(input,output: TStringList);
var OutputNode : pNode;
saveSTDOUT : pNode;
MemoryStream: TMemoryStream;
begin
MemoryStream := TMemoryStream.Create;
Screen.Cursor := crHourglass;
try
OutputNode := nil;
LspLockNodeAddress(@OutputNode);
try
LspNew(OutputNode);
OutputNode^.Typ := cLspStream;
OutputNode^.StreamVal := MemoryStream;
saveSTDOUT := MainTask.LspStandardOutput; // Store original STDOUT
MainTask.LspStandardOutput := OutputNode; // Redirect STDOUT to MemoryStream
try
LispExpression.Expression.Clear;
LispExpression.Expression.AddStrings(input);
LispExpression.Prepare;
LispExpression.Execute;
LspPrint(LispExpression.AsNode,OutputNode);
MemoryStream.Seek(0,0);
output.Clear;
output.LoadFromStream(MemoryStream);
finally
(*----------------------------------------------------------*)
(* Es ist notwendig, Stream-Information zu verbergen, denn *)
(* das Garbage-Collection-System von Inflisp wuerde auch *)
(* den Stream selbst vernichten, der hier aber 'von aussen' *)
(* geliefert wird. Ein LspDispose ist verboten1, denn dies *)
(* wird von Garbage-Collection oder am Programm-Ende *)
(* automatisch getan. Tut man es explizit, so geht die *)
(* AllObjects-Info verloren ! *)
(*----------------------------------------------------------*)
OutputNode^.StreamVal := nil;
MainTask.LspStandardOutput := saveSTDOUT; // Restore STDOUT
end;
finally
LspUnlockNodeAddress(@OutputNode);
end;
finally
MemoryStream.Free;
Screen.Cursor := crDefault;
end;
end;
procedure TFormDemoMain.ButtonAboutClick(Sender: TObject);
begin
ShowMessage('INFLISP' + #13#10 +
'Lisp interpreter' + #13#10 +
'Author: Joachim Pimiskern, 1994-2004' + #13#10 +
'Freeware.'
);
end;
end.