Silly problem

31 views
Skip to first unread message

Antoni Gual Via

unread,
Jan 31, 2024, 5:35:55 AMJan 31
to 4tH-compiler
Hello
I have installed 4th in Win10 and tried to compile and run (cx) some of the examples that came with it. It looks very promising!

The problem comes when I try to run some code well tested in gforth. I get errors like 
Word 0: Null String   when the program starts with a \ comment , the same as many examples that come with 4th.
The error puzzles me.    Does the 0 indicate a position? 
Is there any way to get more explicit error messages?

Cheers
Antonio



The Beez

unread,
Jan 31, 2024, 5:53:10 AMJan 31
to 4tH-compiler
First, 4tH is NOT Forth. So if you think you can take a random gForth program and pull it through 4tH, it will most probably not work. There are plenty of libraries that can make 4tH more ANS compatible, but I would not suggest that unless you have a proper knowledge of 4tH and Forth. 

The error you get is because 4tH's parser expects a string after "\" - and if it doesn't get it, it will refuse to continue. The "Word: xxx" indicates at which opcode compilation failed - and here it comes: since it fails at the parsing stage NOTHING HAS BEEN COMPILED YET. So it reports, "Word 0" - what else can the poor thing do? You can issue "cd" to see what I mean ;-)

There is an easy way to get more information, e.g. on errors. Just consult the 650+ pages of the manual. You can also find an entire chapter dedicated to converting 4tH to Forth (or vice versa) called "The porting guide". Additionally you can consult the "ANS Forth statement" chapter to get more information on how to make 4tH more ANS compatible.

As far as the errors go, there is an "Errors guide", which I copied in its entirety blow. Hope this helps!

Hans Bezemer

Errors guide
1.1 How to use this manual
This manual contains all the error messages 4tH can possibly issue. It is organized like this:
  1. Message: This features the message from errs_4th.c, the error-code returned in ErrNo and the C-mnemonic.
  2. Words: Words that can trigger this error.
  3. Example: This features a 4tH one-liner that will trigger the error.
  4. Cause: This lists all possible causes of the error.
  5. Hints: This will give you some directions on how to fix the error.
1.2 Interpreter (exec_4th)
When exiting this function ErrLine will contain the address of the word in the Code Segment where the error occured.
  1. Message: No errors (#0 M4NOERRS)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: A program was succesfully executed.
  5. Hints: Make an error ;)
  1. Message: Out of memory (#1 M4NOMEM)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: There was not enough free memory to allocate the Character Segment or the Integer Segment.
  5. Hints:
  1. Reduce the amount of memory your program allocates and recompile.
  2. Add more physical memory or increase swap space.
  3. Recompile 4tH under another operating system (flat memory space) or another memory model.
  1. Message: Bad object (#2 M4BADOBJ)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: An unknown token was encountered in the H-code.
  5. Hints: Contact us, this should never happen.
  1. Message: Stack overflow (#3 M4SOVFLW)
  2. Words: Any word that pushes items on the Data Stack.
  3. Example: STACK 1+ 0 DO I LOOP
  4. Cause: The Data Stack collided with the Return Stack.
  5. Hints:
  1. Don't push too many elements on the Data Stack.
  2. Merge colon-definitions. Reduce the number of nested DO..LOOPs.
  3. If you are using recursion, try if you can achieve the same result with a loop.
  4. Make sure that your stacks are still balanced when returning from a colon-definition. Don't leave any unused data on the Data Stack. Flow-control words can have unexpected stack effects!
  1. Message: Stack empty (#4 M4SEMPTY)
  2. Words: Any word that pops items from the Data Stack.
  3. Example: 0 SWAP
  4. Cause: The Data Stack did not contain the required number of items to complete the operation.
  5. Hints:
  1. Make sure that your stack is still balanced when returning from a colon-definition.
  2. Make sure that the required number of items are on the stack when performing the operation.
  3. If the problem occurs within an interpreter driven application, make sure that you check the number of elements are on the stack before allowing the operation.
  1. Message: Return stack overflow (#5 M4ROVFLW)
  2. Words: Any word that pushes items on the Return Stack; calling a user defined word
  3. Example: : DUMMY DUMMY ; DUMMY
  4. Cause: The Return Stack collided with the Data Stack.
  5. Hints:
  1. Don't push too many elements on the Data Stack.
  2. Merge colon-definitions. Reduce the number of nested DO..LOOPs.
  3. If you are using recursion, try if you can achieve the same result with a loop.
  4. Make sure that your stacks are still balanced when returning from a colon-definition. Don't leave any unused data on the Data Stack. Flow-control words can have unexpected stack effects!
  1. Message: Return stack empty (#6 M4REMPTY)
  2. Words: Any word that pops items from the Return Stack; returning from a user defined word
  3. Example: R>
  4. Cause: The Return Stack did not contain the required number of items to complete the operation.
  5. Hints:
  1. Balance R> and >R inside your colon-definition. Flow-control words can have unexpected stack effects!
  2. Be careful when using R> and >R inside a DO..LOOP.
  1. Message: Bad string (#7 M4BADSTR)
  2. Words: ARGS OFFSET
  3. Example: -1 ARGS
  4. Cause: There was either no argument on the command line or no binary string constant with this index.
  5. Hints:
  1. Use a valid index for ARGS.
  2. Use a valid index for the offset.
  1. Message: Bad variable (#8 M4BADVAR)
  2. Words: ! @ +! ? SMOVE
  3. Example: 6 ARRAY NAME NAME -5 TH @
  4. Cause: You tried to access a variable or array element, but its address in the Integer Segment is invalid.
  5. Hints:
  1. Be sure that all stack-items are in the right order when address calculations, fetches or stores are made.
  2. Use a valid array index or address.
  3. Don't transfer any cells to or from a invalid array index or address.
  4. Don't try to overwrite read-only system variables.
  1. Message: Bad address (#9 M4BADADR)
  2. Words: All string handling words
  3. Example: 10 STRING BUFFER TIB CHAR- BUFFER /TIB CMOVE
  4. Cause: You tried to access a character, but its address in the Character Segment is invalid.
  5. Hints:
  1. Be sure that all stack-items are in the right order when address calculations, fetches or stores are made.
  2. Make sure that the number of elements is correct when you use words like CMOVE, COUNT, FILL.
  3. Terminate strings.
  4. You exceeded the maximum length of PAD when you defined a string constant using S".
  5. You exceeded the maximum length of PAD when you fetched a commandline argument using ARGS.
  1. Message: Divide by zero (#10 M4DIVBY0)
  2. Words: / MOD /MOD */ */MOD
  3. Example: 1 0 / . CR
  4. Cause: You tried to divide by zero.
  5. Hints: Check the divisor before you use it.
  1. Message: Bad token (#11 M4BADTOK)
  2. Words: @C EXECUTE EXIT CATCH
  3. Example: : DUMMY ; ' DUMMY 5 - DUP @C SWAP EXECUTE
  4. Cause: You tried to jump to a token or access the argument of a token, but its address in the Code Segment is invalid.
  5. Hints:
  1. Be sure that all stack-items are in the right order when address calculations, fetches or jumps are made.
  2. Make sure the address you're using is within the Code Segment.
  3. Be sure that the name after ' is that of a colon-definition.
  1. Message: I/O error (#14 M4IOERR)
  2. Words: All words performing I/O
  3. Example: OUTPUT FILE 5 . CR
  4. Cause:
  1. You tried to read from or write to an unopened file.
  2. You tried to USE, SEEK or TELL an unused stream.
  3. There was an I/O error when you tried to read from or write to a file.
  4. There was an error when you tried to close an open file with CLOSE.
  5. There was an error when 4tH tried to close a file after the program terminated.
  1. Hints:
  1. Open a file before you try to read or write to it. Check the value OPEN returns.
  2. Make sure the values on the stack are correct when you perform I/O.
  3. Make sure the values on the stack are correct when addressing streams.
  4. Make sure that there is enough space left on the device you try to write to. Make sure it functions correctly.
  1. Message: Assertion failed (#15 M4ASSERT)
  2. Words: )
  3. Example: [ASSERT] ASSERT( FALSE )
  4. Cause: The top of the stack was FALSE when ) executed.
  5. Hints: Correct the condition ) acted upon.
  1. Message: Unhandled exception (#16 M4THROW)
  2. Words: THROW
  3. Example: 1 THROW
  4. Cause: A THROW was encountered without a previous call from CATCH. The top of stack contained an error number outside the range of system errors.
  5. Hints: Make sure that a THROW can only be reached from a previous CATCH.
  1. Message: Bad radix (#17 M4BADRDX)
  2. Words: .R . # NUMBER
  3. Example: 1 BASE ! 5 . CR
  4. Cause: The 4tH variable BASE contained a value outside the 2 to 36 range during a conversion.
  5. Hints: Take care that BASE stays within the 2 to 36 range.
  1. Message: Bad stream (#18 M4BADDEV)
  2. Words: USE SEEK TELL CLOSE
  3. Example: -1 CLOSE
  4. Cause:
  1. The filehandle you tried to use was out of range.
  2. You may not SEEK, TELL or CLOSE the streams STDIN and STDOUT.
  3. You may not SEEK or TELL a pipe.
  1. Hints:
  1. Make sure you use a proper stream when using USE, SEEK, TELL or CLOSE.
  2. Check stack manipulations or use a variable or value.
  1. Message: Bad pointer (#20 M4BADPTR)
  2. Words: CATCH THROW PAUSE
  3. Example: : ME R> R> R> DROP -5 >R >R >R 1 THROW ; ' ME CATCH
  4. Cause: The stack pointer THROW or PAUSE tried to use was invalid.
  5. Hints:
  1. Be careful when you manipulate the Return Stack.
  2. Contact us, this should never happen.
1.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.
  1. Message: No errors (#0 M4NOERRS)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: A source was succesfully compiled.
  5. Hints: Make an error ;)
  1. Message: Out of memory (#1 M4NOMEM)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: There was not enough free memory to allocate the H-code header, the Code Segment, the symbol-table or the control-stack.
  5. Hints:
  1. Compact your source by removing all comment and whitespace or use the preprocessor
  2. Add more physical memory or increase swap space.
  3. Recompile 4tH under another compiler (flat memory space) or another memory model.
  1. Message: Bad object (#2 M4BADOBJ)
  2. Words: All defining words
  3. Example: CR CR 20 STRING
  4. Cause:
  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.
  1. Hints:
  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.
  1. Message: Bad string (#7 M4BADSTR)
  2. Words: SCONSTANT
  3. Example: 6 SCONSTANT BAD
  4. Cause: The expression, which was compiled right before the word which caused the error, was not a string constant created by S" or S|.
  5. Hints: Use a string constant created by S" or S|.
  1. Message: Bad variable (#8 M4BADVAR)
  2. Words: EQUATES
  3. Example: 6 EQUATES BAD
  4. Cause: The expression, which was compiled right before the word which caused the error, did not compile to a variable.
  5. Hints: Use a expression, which compiles to a variable.
  1. Message: Divide by zero (#10 M4DIVBY0)
  2. Words: / /CONSTANT
  3. Example: 0 /CONSTANT WRONG 1 WRONG
  4. Cause:
  1. You tried to divide by zero in a literal expression.
  2. You tried to apply a zero /CONSTANT.
  1. Hints:
  1. Check the divisor before you use it.
  2. Don't define a zero /CONSTANT.
  1. Message: Wrong type (#12 M4NOTYPE)
  2. Words: TO IS ALIAS DEFER FILE VALUE :REDO DOES> TAG
  3. Example: 0 CONSTANT WRONG 5 TO WRONG
  4. Cause:
  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.
  1. Hints:
  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.
  1. Message: Undefined name (#13 M4NONAME)
  2. Words: <name> ' ['] RECURSE AKA HIDE
  3. Example: ' HELLO ( "hello" is not defined)
  4. Cause:
  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.
  5. RECURSE is used outside a colon definition.
  6. The name you used is longer than WIDTH characters.
  1. Hints:
  1. Note that most of the words above only work with names defined inside the program and not with built-in names
    2
    AKA does offer limited capability in this field.
    .
  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.
  1. Message: I/O error (#14 M4IOERR)
  2. Words: [NEEDS INCLUDE
  3. Example: [NEEDS nosuchfile.4th]
  4. Cause:
  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.
  1. Hints:
  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.
  1. Message: Bad literal (#19 M4BADLIT)
  2. Words: All words requiring a literal expression
  3. Example: 10 DUP ARRAY NAME
  4. Cause: The expression, which was compiled right before the word which caused the error, did not compile to a literal.
  5. Hints: Use a literal expression.
  1. Message: Nesting too deep (#21 M4NONEST)
  2. Words: All flow control words and colon definitions
  3. Example: 10 0 DO 10 0 DO <more flow-control structures> LOOP LOOP
  4. Cause: The control-stack, that holds all references to addresses of flow-control structures in the Code Segment, overflowed.
  5. Hints: Make separate colon-definitions of the flow-control structures that caused the error.
  1. Message: No program (#22 M4NOPROG)
  2. Words: All words that do not compile any tokens
  3. Example: 10 ARRAY NAME ( Won't compile)
  4. Cause:
  1. The source didn't contain any compilable words.
  2. The source was corrupt.
  3. A runaway comment, invalid declaration or misconstructed conditional compilation clause.
  4. Using reserved words as names.
  1. Hints:
  1. Make a program that actually does something.
  2. Make sure that the source actually contains 4tH source-code.
  3. Terminate your comments, declarations and conditional compilations properly.
  4. Don't use any reserved words as names.
  1. Message: Incomplete declaration (#23 M4NODECL)
  2. Words: All defining words and compiler directives
  3. Example: 10 CONSTANT CONSTANT NAME
  4. Cause:
  1. Syntax errors; usually a missing name or a literal expression.
  2. Incomplete compiler directives or expressions, like a leading comma.
  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].
  1. Hints:
  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.
  1. Message: Unmatched conditional (#24 M4NOJUMP)
  2. Words: All flow control words and colon definitions
  3. Example: : WRONG IF DROP BEGIN FALSE LOOP ;
  4. Cause: The flow-control word that caused the error didn't match with the previous flow-control word (BEGIN after IF) or was missing.
  5. Hints: Use the appropriate flow-control word to terminate a flow-control structure.
  1. Message: Unterminated string (#25 M4NOSTR)
  2. Words: ." \ ( .( ," S" S| ,| ABORT" THROW" @GOTO [NEEDS INCLUDE [CHAR] CHAR [DEFINED] [UNDEFINED]
  3. Example: ." Hello world
  4. Cause:
  1. A required delimiter is missing at the end of a string.
  2. An error occured at the very end of the source.
  1. Hints:
  1. Add the required delimiter at the end of the string.
  2. Complete the source properly. Contact us if this isn't the cause.
  1. Message: Null string (#26 M4NULSTR)
  2. Words: See error #25, except [CHAR] CHAR [DEFINED] [UNDEFINED]
  3. Example: ." "
  4. Cause:
  1. The string between the word and its delimiter did not contain any characters.
  2. There was more than one whitespace character between INCLUDE and the string following it.
  1. Hints:
  1. Use a string that contains at least one single character.
  2. Delete all superfluous whitespace characters between INCLUDE and the string following it. If the error persists, try using [NEEDS instead.
  1. Message: Duplicate name (#27 M4DUPNAM)
  2. Words: All defining words
  3. Example: : TH CELLS + ;
  4. Cause: The name you used for a definition is already in use by either 4tH, the libraries you included or your own program.
  5. Hints: Use a different name.
  1. Message: Name too long (#28 M4BADNAM)
  2. Words: All defining words
  3. Example: VARIABLE JUSTTOOLONGANAMEFORCOMFORT
  4. Cause: The name you used for a definition is too long.
  5. Hints: Use a shorter name.
  1. Message: Compilation aborted (#29 M4CABORT)
  2. Words: [ABORT]
  3. Example: [ABORT]
  4. Cause: An [ABORT] directive was encountered during compilation.
  5. Hints: The original programmer must have had a reason to abort compilation in this particular circumstance. See the program in question for additional information.
1.4 Loader (load_4th)
Since the loader works with complete segments, the words don't have to do much with fixing an error. Therefore, it reports that nothing has been loaded (word 0) or everything has been loaded (the last word).
  1. Message: No errors (#0 M4NOERRS)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: A program was succesfully loaded.
  5. Hints: Keep up the good work. ;)
  1. Message: Out of memory (#1 M4NOMEM)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: There was not enough free memory to allocate the header, the Code Segment or the String Segment.
  5. Hints:
  1. Reduce the amount of memory your program allocates and recompile.
  2. Add more physical memory or increase swap space.
  3. Recompile 4tH under another compiler (flat memory space) or another memory model.
  1. Message: Bad object (#2 M4BADOBJ)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause:
  1. You tried to load a file, that was not an HX-file.
  2. You tried to load an HX-file from a previous version of 4tH.
  3. You tried to load an HX-file for a different application.
  4. You tried to load an HX-file for a different architecture.
  5. You tried to load an inconsistent HX-file.
  1. Hints:
  1. Use a proper HX-file.
  2. Recompile the source, using the current 4tH compiler.
  3. If the source is compatible, you might recompile the source, using your own 4tH compiler.
  4. If the source is compatible, you might recompile the source, using your own 4tH compiler.
  5. Recompile the source, using your own 4tH compiler.
  1. Message: I/O error (#14 M4IOERR)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause:
  1. The file could not be opened.
  2. There was an I/O error while the file was read.
  3. The file could not be closed.
  1. Hints:
  1. Use a valid filename.
  2. Make sure the device functions correctly.
  3. Make sure the device functions correctly.
1.5 Saver (save_4th)
Since the saver works with complete segments, the words don't have to do much with fixing an error. Therefore, it reports that nothing has been saved (word 0) or everything has been saved (the last word).
  1. Message: No errors (#0 M4NOERRS)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause: A program was succesfully saved.
  5. Hints: Keep up the good work. ;)
  1. Message: I/O error (#14 M4IOERR)
  2. Words: Not applicable
  3. Example: Not applicable
  4. Cause:
  1. The file could not be opened.
  2. There was an I/O error while the file was written.
  3. The file could not be closed.
  1. Hints:
  1. Make sure you got enough inodes or directory-entries left on the device you want to write to. Use a valid filename.
  2. Make sure that there is enough space left on the device you try to write to. Make sure it functions correctly.
  3. Make sure the device functions correctly.
 

Reply all
Reply to author
Forward
0 new messages