Compare commits

..

No commits in common. "ef7a2bf3337d19d83dbd02b0205da1290ed48e5c" and "8370ff3c92981cab77f854ffabceb77bbffbcdf4" have entirely different histories.

3 changed files with 12 additions and 118 deletions

View File

@ -1,90 +1,20 @@
#ifndef SLC_H #ifndef SLC_H
#define SLC_H #define SLC_H
/** Possible word types */ /** A word starts right after this - a word is usually after this memory area */
enum SLC_WORDTYP {
/** Still in plain text */
SLC_WORDTYP_TEXT = 0,
/** Native code, use get_word_storage_offset to get what to run (relative pointer or array of pointers) */
SLC_WORDTYP_NATIVE = 1,
/** "Threaded code" (utf16-like word offsets) and encoded parentheses IN-PLACE inlined where text was before */
SLC_WORDTYP_THREADED_INLINE = 2,
/** "Threaded code" that did not fit in-place and is thus stored in session storage, word offset tells where */
SLC_WORDTYP_THREADED_SESSION = 2
};
typedef enum SLC_WORDTYP SLC_WORDTYP;
/** Gets the wordtyp from a flags field - see wordstart */
static inline SLC_WORDTYP get_word_type(uint8_t flags) {
return (SLC_WORDTYP)(flags >> 6);
}
/** Gets the 6-bit variable count (at most 64 vars possible per word) */
static inline uint8_t get_word_var_count(uint8_t flags) {
return (flags && 0x3F); /* 0011 1111 */
}
/** Gets the 24bit storage offset of the word: Natives contain pointers in an offseted array */
static inline uint32_t get_word_storage_offset(uint8_t high_offset, uint16_t low_offset) {
return ((uint32_t)high_offset << 16) + low_offset;
}
/**
* A word definition starts right after this. After processing it, we inline overwrite random parts of it in memory...
*
* Examples:
*
* #: just_code
* #dup
* #inc
* #swap
* #
*
* : with_vars @a; @b; @c;
* @a
* inc
* @a(.)
* ;
*
* #builtin: to_prefix
* #swap
* #dup
*
* TODO: How to do this builtin to be properly changed inline? If it can be inline threaded-coded, then its fine, but is spec-case
* ^^The above always needs starting '#builtin' at the definition and inside. That is exchanged to real prefix...
* This is used for implementation implementing built-ins with FORTH-like code instead of native (saves native interpret. space)
*
* #: structural (
* #parse_num
* #dup
* #inc
* #swap
* #print
* #print
* ) [ #parse_num #print ] { #parse_num #print }
* #
*/
struct wordstart { struct wordstart {
/** The ':' char - after processing it stores the flags */ /* : */
char colon;
/* whitespace after ':', usually used to store the flags */
uint8_t flags; uint8_t flags;
/** whitespace after ':' and first char of name - after processing contains the high-offset */ /* char name[]; // The name of the word being defined. */
uint16_t high_offset; /* char vars[]; // The local variables of the word. */
/** Either remaining parts of the name - or the leading tab/space for starting variables (or newline if there's none) */ /* char data[]; // The "body" of the word - either text source or after processing the threaded code of it (see flags) */
uint8_t low_offset;
/* char ..name[]; // The REMAINS of name of the word being defined. Can be empty! */
/* char vars[]; // The local (at least 1-letter) variables of the word. Can be empty - min 4x8bit per a var, like: " @a;" */
/* char newline; // there is always a newline at this point! XXX: "@a; ", "@b;\n" is how we store vars (*/
/* char data[]; // The "body" of the word - either text source or inline threaded code (at least 1 character) */
/* char ender[]; // The ender-string that ends the word - always at least 1 character! */
}; };
typedef struct wordstart wordstart;
enum SLC_SYM_OP { SLC_SYM_SET, SLC_SYM_GET, SLC_SYM_ERASE }; enum SLC_SYM_OP { SLC_SYM_SET, SLC_SYM_GET, SLC_SYM_ERASE };
typedef enum SLC_SYM_OP SLC_SYM_OP;
enum SLC_STACK_OP { SLC_STACK_PUSH, SLC_STACK_POP, SLC_STACK_AT, SLC_STACK_COUNT, SLC_STACK_ERASE }; enum SLC_STACK_OP { SLC_STACK_PUSH, SLC_STACK_POP, SLC_STACK_AT, SLC_STACK_COUNT, SLC_STACK_ERASE };
typedef enum SLC_STACK_OP SLC_STACK_OP;
enum SLC_SESSION_OP { SLC_SESSION_ALLOC, SLC_SESSION_ERASE, SLC_SESSION_GET }; enum SLC_SESSION_OP { SLC_SESSION_ALLOC, SLC_SESSION_ERASE, SLC_SESSION_GET };
typedef enum SLC_SESSION_OP SLC_SESSION_OP;
enum SLC_IO_OP { enum SLC_IO_OP {
SLC_IO_OPEN, SLC_IO_OPEN,
SLC_IO_OPEN_TMP, SLC_IO_OPEN_TMP,
@ -96,12 +26,6 @@ enum SLC_IO_OP {
SLC_IO_UNLOCK, SLC_IO_UNLOCK,
SLC_IO_CMD, 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". * Function-abstraction for a "symbol-table".
@ -171,35 +95,19 @@ typedef uint32_t (*session)(SLC_SESSION_OP op, uint32_t i);
*/ */
typedef const char* (*ioconn)(SLC_IO_OP op, const char *param); 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.
*/
typedef uint32_t (*coderead)(SLC_CODE_OP op, uint32_t i);
/** /**
* This function runs the main slc engine over a snippet of code. * This function runs the main slc engine over a snippet of code.
* *
* @param code_src The input source code to interpret / run. * @param code The input source code to interpret / run.
* @param symbol_table The symbol table to use * @param symbol_table The symbol table to use
* @param code_stack The code stack (return addresses) to use * @param code_stack The code stack (return addresses) to use
* @param data_stack The data stack (forth-like stack) 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 * @param insert_stack Used for temporarily expanding the input stream (one word level above) with words
* @param session_storage Can allocate and use arbitrary memory with this. * @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 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.
*/ */
static inline void slc( void slc(
coderead code_src, const char *code,
sym symbol_table, sym symbol_table,
stack code_stack, stack code_stack,
stack data_stack, stack data_stack,
@ -208,9 +116,9 @@ static inline void slc(
ioconn io_connector, ioconn io_connector,
const char *prefix, const char *prefix,
const char *ender, const char *ender,
const char *varprefix const char *varprefix,
) { ) {
// TODO // TODO
} }
#endif /* SLC_H */ #ENDIF /* SLC_H */

10
main.c
View File

@ -1,10 +0,0 @@
#include <stdio.h>
#include "hamt.h"
#include "turbolist/turbolist.h"
#include "engine/slc.h"
int main(int argc, const char **argv) {
// TODO: Implement CLI frontend...
puts("TODO: Implement CLI frontend...");
return 0;
}

View File

@ -1,4 +0,0 @@
debug:
gcc -g hamt.c main.c -o main
release:
gcc -O2 hamt.c main.c -o main