added engine debugging and some cleanup

This commit is contained in:
Richard Thier 2024-09-26 12:32:34 +02:00
parent ceabdee697
commit d35b55194f

View File

@ -213,7 +213,7 @@ typedef uint32_t (*stack)(SLC_STACK_OP op, uint32_t param);
typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i, uint32_t j); typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i, uint32_t j);
union iores { union iores {
/** Either the terminal cmd result or the handle pointer */ /** Either the terminal cmd result or the handle pointer. NULL means some kind of error */
const char *ptr; const char *ptr;
/** The read character */ /** The read character */
char c; char c;
@ -229,8 +229,8 @@ typedef union iores iores;
* SLC_IO_CLOSE Closes a PERSISTENT file with the given handle. * SLC_IO_CLOSE Closes a PERSISTENT file with the given handle.
* SLC_IO_OPEN_TMP Opens a TEMPORARY file with the given name. Returns the handle pointer. * SLC_IO_OPEN_TMP Opens a TEMPORARY file with the given name. Returns the handle pointer.
* SLC_IO_CLOSE_TMP Removes the TEMPORARY file with the given handle. * SLC_IO_CLOSE_TMP Removes the TEMPORARY file with the given handle.
* SLC_IO_READ Reads a character from the given file handle. Returns pointer to the character that got read. * SLC_IO_READ Reads a character from the given file handle. Returns '\0' on EOF and being out of data!
* SLC_IO_WRITE Writes a character from the given file handle. The 'param' points to the character to write (1 byte) * SLC_IO_WRITE Writes a character to the given file handle. The 'param' points to the character to write (1 byte)
* SLC_IO_LOCK Locks the given file handle for exclusive reads and writes (others need to use lock/unlock too) * SLC_IO_LOCK Locks the given file handle for exclusive reads and writes (others need to use lock/unlock too)
* SLC_IO_UNLOCK Locks the given file handle for exclusive reads and writes (others need to use lock/unlock too) * SLC_IO_UNLOCK Locks the given file handle for exclusive reads and writes (others need to use lock/unlock too)
* SLC_IO_CMD Runs the given command on the operating system. The 'param' is the command (+args) and returned is std output. * SLC_IO_CMD Runs the given command on the operating system. The 'param' is the command (+args) and returned is std output.
@ -248,21 +248,21 @@ typedef char (*coderead)();
enum slc_state : uint32_t { enum slc_state : uint32_t {
/** Before things */ /** Before things */
SLC_START, SLC_START = 0,
/** In a comment */ /** In a comment */
SLC_COMMENT, SLC_COMMENT = 1,
/** In multi-line comment */ /** In multi-line comment */
SLC_MULTILINE_COMMENT, SLC_MULTILINE_COMMENT = 2,
/** Name part of word-definition (after ':') - whitespace ends it */ /** Name part of word-definition (after ':') - whitespace ends it */
SLC_DEF_NAME, SLC_DEF_NAME = 3,
/** Variable-listing part of word-definition - endline, '(', '[' or '{' ends it */ /** Variable-listing part of word-definition - endline, '(', '[' or '{' ends it */
SLC_DEF_VAR, SLC_DEF_VAR = 4,
/** Raw body part of the word definition - these can contain local variable accesses + words, depth counted by vars */ /** Raw body part of the word definition - these can contain local variable accesses + words, depth counted by vars */
SLC_DEF_BODY, SLC_DEF_BODY = 5,
/** Name part of a word "call" (non-definition). Ends by whitespace, '@' (in case of variable) or various parentheses */ /** Name part of a word "call" (non-definition). Ends by whitespace, '@' (in case of variable) or various parentheses */
SLC_WORD_NAME, SLC_WORD_NAME = 6,
/** Variable call (MYWORD@MYVAR) - we get to be here from SLC_WORD_NAME or from START */ /** Variable call (MYWORD@MYVAR) - we get to be here from SLC_WORD_NAME or from START */
SLC_WORD_VAR, SLC_WORD_VAR = 7,
}; };
typedef enum slc_state slc_state; typedef enum slc_state slc_state;
@ -386,6 +386,9 @@ static inline void slc(
char c = 0; char c = 0;
while(((c = code_src()) != 0)) { while(((c = code_src()) != 0)) {
process_char: process_char:
#ifdef SLC_DEBUG
printf("%c @ %d\n", c, state);
#endif
switch(state) { switch(state) {
case SLC_START: case SLC_START:
/* state -> comment | multiline_comment */ /* state -> comment | multiline_comment */