21.5 The preprocessor. 4tH 4tH Forth compiler
ಜಾಹಿರಾತು
ಜಾಹಿರಾತು
CHAPTER 21. PORTING GUIDE
21.5
The preprocessor
393
The preprocessor
5
(PP4tH) is also a very useful tool to make ANS-Forth compliant programs, especially when double numbers or floating point numbers are involved. The preprocessor supports a lot of ANS-Forth words which are not supported by 4tH like ”SYN-
ONYM”, ”ACTION-OF”, etc. It allows you to enter double numbers or floating point constants with ease, provided you included the proper preprocessor library, e.g.: f% 234.34e-2
Yes, ”F%” isn’t ANS-Forth either, but a very small library enables your ANS-Forth compiler to compile these numbers without any additional overhead, e.g.:
[DEFINED] 4TH# [IF] include 4pp/lib/float.4pp
[ELSE] s" lib/ezpp4th.4th" included
[THEN] f% 234.34e-2 f. cr
For your convenience, those words are ”state smart”, so you can use them both inside and outside definitions as this sample session shows you:
Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type ‘license’
Type ‘bye’ to exit
[DEFINED] 4TH# [IF] ok include 4pp/lib/float.4pp
ok
[ELSE] ok s" lib/ezpp4th.4th" included ok
[THEN] ok f% 234.34e-2 f. cr 2.3434
ok
: test f% 234.34e-2 f. cr ; ok test 2.3434
ok see test
: test
2.343400E0 f. cr ; ok
Of course, you can write double number or floating point programs without the preprocessor, but they will contain a lot of ”noise” words and are neither easy to read nor to maintain.
Using the preprocessor really simplifies your life in these circumstances.
21.6
Converting ANS-Forth programs to 4tH
4tH is a subset of ANS-Forth, so it might be difficult to find a program that will run on 4tH without at least some rewriting. And there is no guarantee that it will work, because most
ANS-Forth programs weren’t written with 4tH in mind. We’ll list the major pitfalls:
• Programs requiring unsupported words or most words from the FACILITY, FA-
CILITY EXT, SEARCH and SEARCH EXT wordsets are generally impossible to port.
5
See section 18.
CHAPTER 21. PORTING GUIDE 394
• Definitions manipulating the dictionary or the stacks. But 4tH has no dictionary and does not allow direct access to the stacks.
• Definitions that switch between interpretation and compilation mode. 4tH either interprets or compiles; you cannot switch between the two on the fly. User-defined
’IMMEDIATE’ words generally don’t work.
• Definitions using ’CREATE’ and ’DOES>’ can be difficult to port. The only way is to do the ’CREATE’ part manually and wrap the ’DOES>’ part into a ’:REDO’ definition. Another way to port this kind of code is to resort to the 4tH preprocessor.
• Definitions requiring the LOCAL and LOCAL EXT wordsets are difficult to port.
You’ll need to rewrite them extensively by using the locals.4th library file.
• Definitions using ANS-Forth enhanced flow control require some rewriting and conditional compilation.
• Programs that assume they may store cells and characters in the same dataspace require some rewriting. Use the ncoding.4th library file.
ಡೌನ್ಲೋಡ್ ಮಾಡಿ
ಜಾಹಿರಾತು