better type name for do_not_save_ptr; todo about simplest "fast-enough" symbol table

This commit is contained in:
Richard Thier 2024-09-29 02:00:43 +02:00
parent 967960d9bc
commit 560ac9e29e
2 changed files with 12 additions and 4 deletions

View File

@ -168,10 +168,10 @@ union symptr {
}; };
typedef union symptr symptr; typedef union symptr symptr;
struct slc_tmp_charptr { struct do_not_save_charptr {
char *ptr; char *ptr;
}; };
typedef struct slc_tmp_charptr slc_tmp_charptr; typedef struct do_not_save_charptr do_not_save_charptr;
/** /**
* Function-abstraction for a "symbol-table". * Function-abstraction for a "symbol-table".
@ -185,11 +185,11 @@ typedef struct slc_tmp_charptr slc_tmp_charptr;
* Rem.: On GET we return a word* in case the key is to a word and a regular uint32_t* if its a variable name! * Rem.: On GET we return a word* in case the key is to a word and a regular uint32_t* if its a variable name!
* *
* @param op Defines which operation the caller wants. * @param op Defines which operation the caller wants.
* @param key The key (both for SET and GET). This pointer can get easily invalidated so you might need a copy on SET. * @param key The key (both for SET and GET). This pointer can get easily invalidated so you might need a copy or you do Trie, etc.
* @param ptr When adding a found word/variable to the symbol table, the key will point to this word* or uint32_t* * @param ptr When adding a found word/variable to the symbol table, the key will point to this word* or uint32_t*
* @returns The word/var definition stored for the key, or NULL when it is not stored yet or op is SET and there was an error. * @returns The word/var definition stored for the key, or NULL when it is not stored yet or op is SET and there was an error.
*/ */
typedef symptr (*sym)(SLC_SYM_OP op, slc_tmp_charptr key, symptr ptr); typedef symptr (*sym)(SLC_SYM_OP op, do_not_save_charptr key, symptr ptr);
/** /**
* Function-abstraction for an integer "stack". * Function-abstraction for an integer "stack".

8
main.c
View File

@ -10,6 +10,14 @@ symptr nopsym(SLC_SYM_OP op, slc_tmp_charptr key, symptr ptr) {
symptr ret; symptr ret;
ret.worp = NULL; ret.worp = NULL;
return ret; return ret;
// TODO: Create a "peasantly" symbol table where we have:
// - length
// - previndex
// - nextindex
// - char* name inline stored
//
// Then I can do a lookup basically via strstr
// and check validity by jumping back&forth a bit.
} }
uint32_t nopstack(SLC_STACK_OP op, uint32_t param) { uint32_t nopstack(SLC_STACK_OP op, uint32_t param) {