further ideas
This commit is contained in:
parent
ef7a2bf333
commit
b1fa9cd9c9
48
engine/slc.h
48
engine/slc.h
@ -97,11 +97,6 @@ enum SLC_IO_OP {
|
||||
SLC_IO_CMD,
|
||||
};
|
||||
typedef enum SLC_IO_OP SLC_IO_OP;
|
||||
enum SLC_CODE_OP {
|
||||
SLC_CODE_COUNT,
|
||||
SLC_CODE_READ,
|
||||
};
|
||||
typedef enum SLC_CODE_OP SLC_CODE_OP;
|
||||
|
||||
/**
|
||||
* Function-abstraction for a "symbol-table".
|
||||
@ -143,12 +138,14 @@ typedef uint32_t (*stack)(SLC_STACK_OP op, uint32_t param);
|
||||
* SLC_SESSION_ALLOC allocates parameter amount of memory and returns an accessor index.
|
||||
* SLC_SESSION_ERASE erase the session storage (all of it)
|
||||
* SLC_SESSION_GET gets byte at the ith accessor index
|
||||
* SLC_SESSION_SET sets byte to have the value of b at the ith accessor index
|
||||
*
|
||||
* @param op Defines which operation the caller wants.
|
||||
* @param i Used on SESSION_GET and is the accessor index
|
||||
* @param b Used on SESSION_SET and is the byte to write
|
||||
* @returns The accessor index in case of ALLOC (0xFFFFFFFF == -1 means error), on get it returns the store BYTE as uint32_t
|
||||
*/
|
||||
typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i);
|
||||
typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i, uint8_t b);
|
||||
|
||||
/**
|
||||
* Function-abstraction for io connectors.
|
||||
@ -172,31 +169,34 @@ typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i);
|
||||
typedef const char* (*ioconn)(SLC_IO_OP op, const char *param);
|
||||
|
||||
/**
|
||||
* Function-abstraction for reading the source code.
|
||||
*
|
||||
* Operations:
|
||||
*
|
||||
* SLC_CODE_COUNT To get how much bytes are readable (i is unused). Returns size as uint32_t (full used)
|
||||
* SLC_CODE_READ To read bytes of the source code at location i. Returns the byte char as uint32_t (low byte)
|
||||
*
|
||||
* @param op Defines which operation the caller wants.
|
||||
* @param i In case of READ, the index of the data.
|
||||
* Function-abstraction for reading the source code byte-by-byte.
|
||||
*/
|
||||
typedef uint32_t (*coderead)(SLC_CODE_OP op, uint32_t i);
|
||||
typedef uint8_t (*coderead)();
|
||||
|
||||
/**
|
||||
* This function runs the main slc engine over a snippet of code.
|
||||
*
|
||||
* @param code_src The input source code to interpret / run.
|
||||
* @param symbol_table The symbol table to use
|
||||
* @param code_stack The code stack (return addresses) to use
|
||||
* @param data_stack The data stack (forth-like stack) to use
|
||||
* @param insert_stack Used for temporarily expanding the input stream (one word level above) with words
|
||||
* The code_src is what we start interpreting, but you can do buffered reads
|
||||
* because we will use session_storage to store the source code data into memory while processing...
|
||||
* This also helps with the "include" directives using io_connector.
|
||||
* TODO: Investigate "what if" we start with session_storage prefilled with the initial read code?
|
||||
*
|
||||
* The symbol_table not only store "words", but direct access offsets for:
|
||||
*
|
||||
* - words themselves
|
||||
* - variables of the words
|
||||
* - "word ", "word(", "word[", "word{" keys show where "blocks" of that word is. TODO: what to do with multiple blocks? Use flagz?
|
||||
*
|
||||
* @param code_src The input source code to interpret / run. Code ends either with \0 or EOF.
|
||||
* @param symbol_table The symbol table to use while processing.
|
||||
* @param code_stack The code stack (return addresses) to use.
|
||||
* @param data_stack The data stack (forth-like stack) to use.
|
||||
* @param insert_stack Used for temporarily expanding the input stream (one word level above current) with further words.
|
||||
* @param session_storage Can allocate and use arbitrary memory with this.
|
||||
* @param io_connector The engine uses this to open/close pipes/files and write/read them.
|
||||
* @param prefix The prefix added to the lookup of built-ins.
|
||||
* @param ender The character string that ends a word definition.
|
||||
* @param varprefix The character string that prefixes variable declarations.
|
||||
* @param prefix The prefix added to the lookup of built-ins. Useful when you write a compiler with SLC. Defaults to "" (empty).
|
||||
* @param ender The character string that ends a word definition. Defaults to ";".
|
||||
* @param varprefix The character string that prefixes variable declarations. Defaults to "@".
|
||||
*/
|
||||
static inline void slc(
|
||||
coderead code_src,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user