-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval.pas
117 lines (97 loc) · 3.67 KB
/
eval.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
(*----------------------------------------------------------------------------*)
(* Author: Joachim Pimiskern, 1994-2004 *)
(*----------------------------------------------------------------------------*)
unit Eval;
interface
uses
classes, sysutils,
LspGlobl,
winprocs;
procedure DoEval(Source, Dest: TStream);
function GetListFromStream(Source: TStream): pNode;
implementation
uses
lspmain, lspinit, lspcreat, lsplists, lspinout, lsperr,
lsplock,
forms, dialogs;
(*-----------------------------------------------------------------------------*)
(* Aufgabe: Stream Source laden und elementweise auswerten. Die Ausgaben dabei *)
(* nach Dest schreiben. *)
(*-----------------------------------------------------------------------------*)
procedure DoEval(Source, Dest: TStream);
var InputNode : pNode;
OutputNode : pNode;
Res : pNode;
begin
InputNode := nil;
OutputNode := nil;
Res := nil;
LspLockNodeAddress(@InputNode);
LspLockNodeAddress(@OutputNode);
LspLockNodeAddress(@Res);
try
LspNew(InputNode);
InputNode^.Typ := cLspStream;
InputNode^.StreamVal := Source;
if (Dest <> nil) then
begin
LspNew(OutputNode);
OutputNode^.Typ := cLspStream;
OutputNode^.StreamVal := Dest;
end
else
OutputNode := nil;
try
Source.seek(0,0);
repeat
Res := LspRead(InputNode);
if (Res <> cLspEndOfFile) then
LspPrint(LspEval(Res,MainTask.Environment),OutputNode);
Application.ProcessMessages;
until (Res = cLspEndOfFile);
(*----------------------------------------------------------*)
(* 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 ! *)
(*----------------------------------------------------------*)
finally
if (InputNode <> nil) then
InputNode^.StreamVal := nil;
if (OutputNode <> nil) then
OutputNode^.StreamVal := nil;
end;
finally
LspUnlockNodeAddress(@InputNode);
LspUnlockNodeAddress(@OutputNode);
LspUnlockNodeAddress(@Res);
end;
end;
(*----------------------------------------------------------------------------*)
(* Einen Delphi-Stream einlesen und Liste aller Ausdruecke zurueckgeben *)
(*----------------------------------------------------------------------------*)
function GetListFromStream(Source: TStream): pNode;
var StreamNode: pNode;
exp : pNode;
begin
LspNew(StreamNode);
StreamNode^.Typ := cLspStream;
StreamNode^.Flags := 42;
StreamNode^.StreamVal := Source;
Source.seek(0,0);
Result := nil;
repeat
exp := LspRead(StreamNode);
if (exp <> cLspEndOfFile) then
Result := LspCons(exp,Result);
until (exp = cLspEndOfFile);
(*--------------------------------------------------------------------------*)
(* Stream-Info verbergen, siehe oben. *)
(*--------------------------------------------------------------------------*)
StreamNode^.StreamVal := nil;
Result := LspReverse(Result);
end;
end.