-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgforth-server.fs
More file actions
39 lines (32 loc) · 1.17 KB
/
gforth-server.fs
File metadata and controls
39 lines (32 loc) · 1.17 KB
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
\ gforth-serverclient.fs
\ author: uho@xlerb.de
\
\ This is part of the gforth integration with IPython notebook
\
\ This script implements a gforth server program that communicates with
\ a client via pipes "forth-in" and "forth-out".
\ start this gforth server by issuing the command
\
\ gforth gforth-server.fs -e "start"
\ patch all output to go via outfile
: becomes ( <name> new-xt -- ) \ makes <name> behave as new-xt
here >r
>r ' >body dp !
postpone ahead r> >body dp ! postpone THEN
r> dp !
;
:noname ; becomes >stderr
: forth-in ( -- addr len ) s" forth-in" ; \ named pipe for client->server communication: mkfifo forth-in
: forth-out ( -- addr len ) s" forth-out" ; \ named pipe for server->client communication: mkfifo forth-out
: server ( -- )
." gforth server ready" cr
BEGIN
forth-in r/o open-file
?dup 0=
WHILE ( )
forth-out w/o open-file throw to outfile-id
['] include-file catch ?dup IF <# DoError clearstacks ELSE ." ok" cr outfile-id flush-file throw THEN
outfile-id stdout to outfile-id close-file throw
REPEAT
." gforth server died with " . bye ;
: start ( -- ) server ;