22.3 Compiler (comp_4th). 4tH 4tH Forth compiler
Oglas
Oglas
CHAPTER 22. ERRORS GUIDE 401
W
ORDS
:
CATCH THROW PAUSE
E
XAMPLE
:
: ME R> R> R> DROP -5 >R >R >R 1 THROW ; ’ ME CATCH
C
AUSE
H
INTS
:
: The stack pointer THROW or PAUSE tried to use was invalid.
1. Be careful when you manipulate the Return Stack.
2. Contact us, this should never happen.
22.3
Compiler (comp_4th)
When exiting this function ErrLine will contain the address in the Code Segment where the next word would have been compiled if the error hadn’t occured. This is logical, since
4tH always reports where the error occured. And all previous words have been succesfully compiled.
M
ESSAGE
:
W
ORDS
:
No errors
(#0 M4NOERRS)
Not applicable
E
XAMPLE
: Not applicable
C
AUSE
:
H
INTS
:
A source was succesfully compiled.
Make an error ;)
M
ESSAGE
:
W
ORDS
:
Out of memory
Not applicable
(#1 M4NOMEM)
E
XAMPLE
: Not applicable
C
AUSE
: There was not enough free memory to allocate the H-code header, the Code
Segment, the symbol-table or the control-stack.
H
INTS
:
1. Compact your source by removing all comment and whitespace or use the preprocessor
1
.
2. Add more physical memory or increase swap space.
3. Recompile 4tH under another compiler (flat memory space) or another memory model.
M
ESSAGE
:
1
See chapter 18.
Bad object
(#2 M4BADOBJ)
CHAPTER 22. ERRORS GUIDE 402
W
ORDS
: All defining words
E
XAMPLE
:
CR CR 20 STRING
C
AUSE
:
1. A word could not be compiled due to lack of space in the Code Segment.
2. A definition could not be compiled due to lack of space in the symbol-table.
H
INTS
:
1. Trying to make words private by using conditional compilation may trigger this error.
Remove the offending HIDE.
2. In certain circumstances, incomplete data declarations may trigger this error. Complete the declaration.
3. Contact us, this should never happen with normal source-code.
M
ESSAGE
:
W
ORDS
:
Bad string
SCONSTANT
(#7 M4BADSTR)
E
XAMPLE
:
6 SCONSTANT BAD
C
AUSE
: The expression, which was compiled right before the word which caused the error, was not a string constant created by S" or S|.
H
INTS
: Use a string constant created by S" or S|.
M
ESSAGE
:
W
ORDS
:
Bad variable
EQUATES
(#8 M4BADVAR)
E
XAMPLE
:
6 EQUATES BAD
C
AUSE
: The expression, which was compiled right before the word which caused the error, did not compile to a variable.
H
INTS
: Use a expression, which compiles to a variable.
M
ESSAGE
:
W
ORDS
:
Divide by zero
/ /CONSTANT
(#10 M4DIVBY0)
E
XAMPLE
:
0 /CONSTANT WRONG 1 WRONG
C
AUSE
:
1. You tried to divide by zero in a literal expression.
2. You tried to apply a zero /CONSTANT.
CHAPTER 22. ERRORS GUIDE
H
INTS
:
1. Check the divisor before you use it.
2. Don’t define a zero /CONSTANT.
M
ESSAGE
:
Wrong type
(#12 M4NOTYPE)
W
ORDS
: TO IS ALIAS DEFER FILE VALUE :REDO DOES> TAG
E
XAMPLE
:
0 CONSTANT WRONG 5 TO WRONG
C
AUSE
:
1. The name after TO isn’t a VALUE.
2. The name after IS isn’t a DEFER.
3. The name after DEFER or ALIAS is already defined and not a DEFER.
4. The name after VALUE or FILE is already defined and not a VALUE.
5. You tried to create a :REDO or DOES> definition for an unsupported datatype.
6. The name after TAG isn’t an OFFSET.
H
INTS
:
1. Use TO only in combination with a VALUE.
2. Use IS only in combination with a DEFER.
3. Use a different name.
4. Use a different name.
5. Use a proper datatype when creating a :REDO or DOES> definition.
6. Use TAG only in combination with an OFFSET.
M
ESSAGE
:
W
ORDS
:
Undefined name
(#13 M4NONAME)
<name> ’ [’] RECURSE AKA HIDE
E
XAMPLE
: ’ HELLO ( "hello" is not defined)
C
AUSE
:
1. The name which caused the error is not present in the symbol-table.
2. The name is not defined at all.
3. It is not a valid number in the current radix.
4. Underflow or overflow occured during number conversion.
403
CHAPTER 22. ERRORS GUIDE
5. RECURSE is used outside a colon definition.
6. The name you used is longer than WIDTH characters.
H
INTS
:
404
1. Note that most of the words above only work with names defined inside the program and not with built-in names
2
.
2. Usually a typo; correct spelling.
3. Set the appropriate radix by using [BINARY], [OCTAL], [DECIMAL] or [HEX].
4. Don’t use numbers less or equal to (ERROR) or greater than MAX-N.
5. Remove the offending RECURSE.
6. Use a shorter name.
M
ESSAGE
:
W
ORDS
:
I/O error
(#14 M4IOERR)
[NEEDS INCLUDE
E
XAMPLE
:
[NEEDS nosuchfile.4th]
C
AUSE
:
1. The source file you tried to read doesn’t exist.
2. There was an error reading the source file.
3. There was an error when 4tH tried to close the source file.
H
INTS
:
1. Make sure the file you try to open exists and is in the path. Change your working directory if necessary. Check the DIR4TH environment variable.
2. Make sure the device functions correctly.
M
ESSAGE
:
W
ORDS
:
Bad literal
(#19 M4BADLIT)
All words requiring a literal expression
E
XAMPLE
: 10 DUP ARRAY NAME
C
AUSE
: The expression, which was compiled right before the word which caused the error, did not compile to a literal.
H
INTS
: Use a literal expression.
2
AKA does offer limited capability in this field.
CHAPTER 22. ERRORS GUIDE 405
M
ESSAGE
:
W
ORDS
:
Nesting too deep
(#21 M4NONEST)
All flow control words and colon definitions
E
XAMPLE
:
10 0 DO 10 0 DO
<more flow-control structures> LOOP LOOP
C
AUSE
:
H
INTS
:
The control-stack, that holds all references to addresses of flow-control structures in the Code Segment, overflowed.
Make separate colon-definitions of the flow-control structures that caused the error.
M
ESSAGE
:
W
ORDS
:
No program
(#22 M4NOPROG)
All words that do not compile any tokens
E
XAMPLE
:
10 ARRAY NAME ( Won’t compile)
C
AUSE
:
1. The source didn’t contain any compilable words.
2. The source was corrupt.
3. A runaway comment or conditional compilation clause.
4. In rare cases use of reserved words as names.
H
INTS
:
1. Make a program that does something.
2. Make sure that the source actually contains 4tH source- code.
3. Terminate your comments and conditional compilations properly.
4. Don’t use any reserved words as names.
M
ESSAGE
:
W
ORDS
:
Incomplete declaration
(#23 M4NODECL)
All defining words and compiler directives
E
XAMPLE
:
10 CONSTANT CONSTANT NAME
C
AUSE
:
1. Syntax errors; usually a missing name or a literal expression.
2. Incomplete compiler directives or expressions, like a leading comma or a trailing
CHAR.
3. An assertion, beginning with ASSERT(, is missing a right parenthesis. Assertions are not enabled at that point.
4. An [IF] is not balanced by a [THEN].
CHAPTER 22. ERRORS GUIDE
H
INTS
:
1. Use an appropriate expression or name.
2. Complete compiler directives and expressions.
3. Add a right parenthesis at the end of the expression.
4. Add a [THEN] for each [IF] statement.
406
M
ESSAGE
:
W
ORDS
:
Unmatched conditional
(#24 M4NOJUMP)
All flow control words and colon definitions
E
XAMPLE
: : WRONG IF DROP BEGIN FALSE LOOP ;
C
AUSE
: The flow-control word that caused the error didn’t match with the previous flow-control word (BEGIN after IF) or was missing.
H
INTS
: Use the appropriate flow-control word to terminate a flow-control structure.
M
ESSAGE
:
W
ORDS
:
Unterminated string
(#25 M4NOSTR)
." \ ( .( ," S" ABORT" S| ,| [CHAR] CHAR @GOTO [NEEDS
INCLUDE [DEFINED] [UNDEFINED]
E
XAMPLE
:
." Hello world
C
AUSE
:
1. A required delimiter is missing at the end of a string.
2. An internal error occured at the very end of the source.
H
INTS
:
1. Add the required delimiter at the end of the string.
2. Contact us, this should never happen.
M
ESSAGE
:
Null string
(#26 M4NULSTR)
W
ORDS
: See error #25
E
XAMPLE
: ." "
C
AUSE
:
1. The string between the word and its delimiter did not contain any characters.
2. There was more than one whitespace character between a [DEFINED], [UNDE-
FINED], [CHAR], CHAR or INCLUDE and the string following it.
Preuzimanje
Oglas