From 967960d9bc1b6545a9a19382632b455337f497b8 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Sun, 29 Sep 2024 01:38:07 +0200 Subject: [PATCH] 32bit operations for session storage + rethinking ownership of char* names for symbol table storage (now it is up to the symbol table and we let it be invalidated) --- engine/slc.h | 13 +++++++++++-- main.c | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/slc.h b/engine/slc.h index 564e752..3f66314 100644 --- a/engine/slc.h +++ b/engine/slc.h @@ -144,6 +144,8 @@ enum SLC_SESSION_OP { SLC_SESSION_PUSH, SLC_SESSION_GET, SLC_SESSION_SET, + SLC_SESSION_GET32, + SLC_SESSION_SET32, SLC_SESSION_PROCESS }; typedef enum SLC_SESSION_OP SLC_SESSION_OP; @@ -166,6 +168,11 @@ union symptr { }; typedef union symptr symptr; +struct slc_tmp_charptr { + char *ptr; +}; +typedef struct slc_tmp_charptr slc_tmp_charptr; + /** * Function-abstraction for a "symbol-table". * @@ -178,11 +185,11 @@ typedef union symptr symptr; * 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 key The key (both for SET and GET) + * @param key The key (both for SET and GET). This pointer can get easily invalidated so you might need a copy on SET. * @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. */ -typedef symptr (*sym)(SLC_SYM_OP op, char *key, symptr ptr); +typedef symptr (*sym)(SLC_SYM_OP op, slc_tmp_charptr key, symptr ptr); /** * Function-abstraction for an integer "stack". @@ -210,6 +217,8 @@ typedef uint32_t (*stack)(SLC_STACK_OP op, uint32_t param); * SLC_SESSION_PUSH adds the given byte (value in i) to the end of the session storage (by growing it) - j unused * SLC_SESSION_GET gets byte at the ith accessor index - j unused * SLC_SESSION_SET gets byte at the ith accessor index to be of (byte)j + * SLC_SESSION_GET32 gets uint32_t at the ith accessor index - j unused. XXX: Beware, architectures unaligned access crash! + * SLC_SESSION_SET32 gets uint32_t at the ith accessor index to be of j. XXX: Beware, architectures unaligned access crash! * SLC_SESSION_PROCESS gets the last j bytes and moves them overriding bytes at index i, then "shrinks" the storage by j. * * @param op Defines which operation the caller wants. diff --git a/main.c b/main.c index db4edd3..0b0b047 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #define SLC_DEBUG #include "engine/slc.h" -symptr nopsym(SLC_SYM_OP op, char *key, symptr ptr) { +symptr nopsym(SLC_SYM_OP op, slc_tmp_charptr key, symptr ptr) { symptr ret; ret.worp = NULL; return ret;