@@ -112,7 +112,6 @@ Copyright @copyright{} 1995, 1996, 1997, 1998, 2000, 2003 Free Software Foundati
112
112
@center Bernd Paysan
113
113
@center Jens Wilke
114
114
@sp 3
115
- @center This manual is permanently under construction and was last updated on 15-Mar-2000
116
115
117
116
@comment The following two commands start the copyright page.
118
117
@page
@@ -179,6 +178,7 @@ Gforth Environment
179
178
* Command-line editing::
180
179
* Environment variables:: that affect how Gforth starts up
181
180
* Gforth Files:: What gets installed and where
181
+ * Gforth in pipes::
182
182
* Startup speed:: When 35ms is not fast enough ...
183
183
184
184
Forth Tutorial
@@ -363,6 +363,7 @@ Other I/O
363
363
* String Formats:: How Forth stores strings in memory
364
364
* Displaying characters and strings:: Other stuff
365
365
* Input:: Input
366
+ * Pipes:: How to create your own pipes
366
367
367
368
Locals
368
369
@@ -1027,6 +1028,7 @@ material in this chapter.
1027
1028
* Command-line editing::
1028
1029
* Environment variables:: that affect how Gforth starts up
1029
1030
* Gforth Files:: What gets installed and where
1031
+ * Gforth in pipes::
1030
1032
* Startup speed:: When 35ms is not fast enough ...
1031
1033
@end menu
1032
1034
@@ -1353,7 +1355,7 @@ are not set.
1353
1355
1354
1356
1355
1357
@comment ----------------------------------------------
1356
- @node Gforth Files, Startup speed , Environment variables, Gforth Environment
1358
+ @node Gforth Files, Gforth in pipes , Environment variables, Gforth Environment
1357
1359
@section Gforth files
1358
1360
@cindex Gforth files
1359
1361
@@ -1383,7 +1385,59 @@ You can select different places for installation by using
1383
1385
@code{configure} options (listed with @code{configure --help}).
1384
1386
1385
1387
@comment ----------------------------------------------
1386
- @node Startup speed, , Gforth Files, Gforth Environment
1388
+ @node Gforth in pipes, Startup speed, Gforth Files, Gforth Environment
1389
+ @section Gforth in pipes
1390
+ @cindex pipes, Gforth as part of
1391
+
1392
+ Gforth can be used in pipes created elsewhere (described here). It can
1393
+ also create pipes on its own (@pxref{Pipes}).
1394
+
1395
+ @cindex input from pipes
1396
+ If you pipe into Gforth, your program should read with @code{read-file}
1397
+ or @code{read-line} from @code{stdin} (@pxref{General files}).
1398
+ @code{Key} does not recognize the end of input. Words like
1399
+ @code{accept} echo the input and are therefore usually not useful for
1400
+ reading from a pipe. You have to invoke the Forth program with an OS
1401
+ command-line option, as you have no chance to use the Forth command line
1402
+ (the text interpreter would try to interpret the pipe input).
1403
+
1404
+ @cindex output in pipes
1405
+ You can output to a pipe with @code{type}, @code{emit}, @code{cr} etc.
1406
+
1407
+ @cindex silent exiting from Gforth
1408
+ When you write to a pipe that has been closed at the other end, Gforth
1409
+ receives a SIGPIPE signal (``pipe broken''). Gforth translates this
1410
+ into the exception @code{broken-pipe-error}. If your application does
1411
+ not catch that exception, the system catches it and exits, usually
1412
+ silently (unless you were working on the Forth command line; then it
1413
+ prints an error message and exits). This is usually the desired
1414
+ behaviour.
1415
+
1416
+ If you do not like this behaviour, you have to catch the exception
1417
+ yourself, and react to it.
1418
+
1419
+ Here's an example of an invocation of Gforth that is usable in a pipe:
1420
+
1421
+ @example
1422
+ gforth -e ": foo begin pad dup 10 stdin read-file throw dup while \
1423
+ type repeat ; foo bye"
1424
+ @end example
1425
+
1426
+ This example just copies the input verbatim to the output. A very
1427
+ simple pipe containing this example looks like this:
1428
+
1429
+ @example
1430
+ cat startup.fs |
1431
+ gforth -e ": foo begin pad dup 80 stdin read-file throw dup while \
1432
+ type repeat ; foo bye"|
1433
+ head
1434
+ @end example
1435
+
1436
+ @cindex stderr and pipes
1437
+ Pipes involving Gforth's @code{stderr} output do not work.
1438
+
1439
+ @comment ----------------------------------------------
1440
+ @node Startup speed, , Gforth in pipes, Gforth Environment
1387
1441
@section Startup speed
1388
1442
@cindex Startup speed
1389
1443
@cindex speed, startup
@@ -1397,7 +1451,11 @@ If startup speed is a problem, you may consider the following ways to
1397
1451
improve it; or you may consider ways to reduce the number of startups
1398
1452
(for example, by using Fast-CGI).
1399
1453
1400
- The first step to improve startup speed is to statically link Gforth, by
1454
+ An easy step that influences Gforth startup speed is the use of the
1455
+ @option{--no-dynamic} option; this decreases image loading speed, but
1456
+ increases compile-time and run-time.
1457
+
1458
+ Another step to improve startup speed is to statically link Gforth, by
1401
1459
building it with @code{XLDFLAGS=-static}. This requires more memory for
1402
1460
the code and will therefore slow down the first invocation, but
1403
1461
subsequent invocations avoid the dynamic linking overhead. Another
@@ -8550,6 +8608,9 @@ doc-resize-file
8550
8608
8551
8609
doc-slurp-file
8552
8610
doc-slurp-fid
8611
+ doc-stdin
8612
+ doc-stdout
8613
+ doc-stderr
8553
8614
8554
8615
@c ---------------------------------------------------------
8555
8616
@node Search Paths, , General files, Files
@@ -8830,6 +8891,7 @@ doc-block-included
8830
8891
* String Formats:: How Forth stores strings in memory
8831
8892
* Displaying characters and strings:: Other stuff
8832
8893
* Input:: Input
8894
+ * Pipes:: How to create your own pipes
8833
8895
@end menu
8834
8896
8835
8897
@node Simple numeric output, Formatted numeric output, Other I/O, Other I/O
@@ -9127,7 +9189,7 @@ definition of @code{my-char}.
9127
9189
9128
9190
9129
9191
9130
- @node Input, , Displaying characters and strings, Other I/O
9192
+ @node Input, Pipes , Displaying characters and strings, Other I/O
9131
9193
@subsection Input
9132
9194
@cindex input
9133
9195
@cindex I/O - see input
@@ -9155,6 +9217,27 @@ doc-expect
9155
9217
doc-span
9156
9218
9157
9219
9220
+ @node Pipes, , Input, Other I/O
9221
+ @subsection Pipes
9222
+ @cindex pipes, creating your own
9223
+
9224
+ In addition to using Gforth in pipes created by other processes
9225
+ (@pxref{Gforth in pipes}), you can create your own pipe with
9226
+ @code{open-pipe}, and read from or write to it.
9227
+
9228
+ doc-open-pipe
9229
+ doc-close-pipe
9230
+
9231
+ If you write to a pipe, Gforth can throw a @code{broken-pipe-error}; if
9232
+ you don't catch this exception, Gforth will catch it and exit, usually
9233
+ silently (@pxref{Gforth in pipes}). Since you probably do not want
9234
+ this, you should wrap a @code{catch} or @code{try} block around the code
9235
+ from @code{open-pipe} to @code{close-pipe}, so you can deal with the
9236
+ problem yourself, and then return to regular processing.
9237
+
9238
+ doc-broken-pipe-error
9239
+
9240
+
9158
9241
@c -------------------------------------------------------------
9159
9242
@node Locals, Structures, Other I/O, Words
9160
9243
@section Locals
@@ -11696,6 +11779,8 @@ in @file{compat/assert.fs}.
11696
11779
@cindex singlestep Debugger
11697
11780
@cindex debugging Singlestep
11698
11781
11782
+ The singlestep debugger does not work in this release.
11783
+
11699
11784
When you create a new word there's often the need to check whether it
11700
11785
behaves correctly or not. You can do this by typing @code{dbg
11701
11786
badword}. A debug session might look like this:
@@ -15078,7 +15163,7 @@ disassemble the code of primitives with @code{see} on some architectures.
15078
15163
@cindex Gforth performance
15079
15164
15080
15165
On RISCs the Gforth engine is very close to optimal; i.e., it is usually
15081
- impossible to write a significantly faster engine.
15166
+ impossible to write a significantly faster threaded-code engine.
15082
15167
15083
15168
On register-starved machines like the 386 architecture processors
15084
15169
improvements are possible, because @code{gcc} does not utilize the
@@ -15090,7 +15175,8 @@ Sieve benchmark on a 486DX2/66 than Gforth compiled with
15090
15175
with gcc-2.95 and gforth-0.4.9; now the most important virtual machine
15091
15176
registers fit in real registers (and we can even afford to use the TOS
15092
15177
optimization), resulting in a speedup of 1.14 on the sieve over the
15093
- earlier results.
15178
+ earlier results. And dynamic superinstructions provide another speedup
15179
+ (but only around a factor 1.2 on the 486).
15094
15180
15095
15181
@cindex Win32Forth performance
15096
15182
@cindex NT Forth performance
@@ -15099,7 +15185,7 @@ earlier results.
15099
15185
@cindex PFE performance
15100
15186
@cindex TILE performance
15101
15187
The potential advantage of assembly language implementations is not
15102
- necessarily realized in complete Forth systems: We compared Gforth-0.4 .9
15188
+ necessarily realized in complete Forth systems: We compared Gforth-0.5 .9
15103
15189
(direct threaded, compiled with @code{gcc-2.95.1} and
15104
15190
@code{-DFORCE_REG}) with Win32Forth 1.2093 (newer versions are
15105
15191
reportedly much faster), LMI's NT Forth (Beta, May 1994) and Eforth
@@ -15127,12 +15213,12 @@ scaled by the time taken by Gforth (in other words, it shows the speedup
15127
15213
factor that Gforth achieved over the other systems).
15128
15214
15129
15215
@example
15130
- relative Win32- NT eforth This-
15131
- time Gforth Forth Forth eforth +opt PFE Forth TILE
15132
- sieve 1.00 1.60 1.32 1.60 0.98 1.82 3.67 9.91
15133
- bubble 1.00 1.55 1.66 1.75 1.04 1.78 4.58
15134
- matmul 1.00 1.71 1.57 1.69 0.86 1.83 4.74
15135
- fib 1.00 1.76 1.54 1.41 1.00 2.01 3.45 4.96
15216
+ relative Win32- NT eforth This-
15217
+ time Gforth Forth Forth eforth +opt PFE Forth TILE
15218
+ sieve 1.00 2.16 1.78 2.16 1.32 2.46 4.96 13.37
15219
+ bubble 1.00 1.93 2.07 2.18 1.29 2.21 5.70
15220
+ matmul 1.00 1.92 1.76 1.90 0.96 2.06 5.32
15221
+ fib 1.00 2.32 2.03 1.86 1.31 2.64 4.55 6.54
15136
15222
@end example
15137
15223
15138
15224
You may be quite surprised by the good performance of Gforth when
@@ -15144,11 +15230,6 @@ but costly method for relocating the Forth image: like @code{cforth}, it
15144
15230
computes the actual addresses at run time, resulting in two address
15145
15231
computations per @code{NEXT} (@pxref{Image File Background}).
15146
15232
15147
- Only Eforth with the peephole optimizer performs comparable to
15148
- Gforth. The speedups achieved with peephole optimization of threaded
15149
- code are quite remarkable. Adding a peephole optimizer to Gforth should
15150
- cause similar speedups.
15151
-
15152
15233
The speedup of Gforth over PFE, ThisForth and TILE can be easily
15153
15234
explained with the self-imposed restriction of the latter systems to
15154
15235
standard C, which makes efficient threading impossible (however, the
@@ -15161,8 +15242,8 @@ The performance of Gforth on 386 architecture processors varies widely
15161
15242
with the version of @code{gcc} used. E.g., @code{gcc-2.5.8} failed to
15162
15243
allocate any of the virtual machine registers into real machine
15163
15244
registers by itself and would not work correctly with explicit register
15164
- declarations, giving a 1.5 times slower engine (on a 486DX2/66 running
15165
- the Sieve) than the one measured above.
15245
+ declarations, giving a significantly slower engine (on a 486DX2/66
15246
+ running the Sieve) than the one measured above.
15166
15247
15167
15248
Note that there have been several releases of Win32Forth since the
15168
15249
release presented here, so the results presented above may have little
@@ -15176,8 +15257,8 @@ Translating Forth to Efficient C}} by M. Anton Ertl and Martin
15176
15257
Maierhofer (presented at EuroForth '95), an indirect threaded version of
15177
15258
Gforth is compared with Win32Forth, NT Forth, PFE, ThisForth, and
15178
15259
several native code systems; that version of Gforth is slower on a 486
15179
- than the direct threaded version used here. You can find a newer version
15180
- of these measurements at
15260
+ than the version used here. You can find a newer version of these
15261
+ measurements at
15181
15262
@uref{http://www.complang.tuwien.ac.at/forth/performance.html}. You can
15182
15263
find numbers for Gforth on various machines in @file{Benchres}.
15183
15264
0 commit comments