From ee36eb420e4515959946aef0b43701744ba499ee Mon Sep 17 00:00:00 2001 From: Rex <631752+reginaldford@users.noreply.github.com> Date: Thu, 7 Mar 2024 00:09:03 -0500 Subject: [PATCH] fastmaps done. tests passing. merging now. release after cleanup. sms is FAST now --- Makefile | 22 +++++++++----------- build/submodules/bounce/src/.gitkeep | 1 - scripts/replace-all.sh | 2 +- sms_key | Bin 256 -> 0 bytes src/main/object/sm_cx.c | 2 +- src/main/object/sm_node.c | 11 +++++----- src/main/object/sm_symbol.c | 29 +++++++++------------------ src/main/sm_global.c | 5 ----- src/main/sm_init.c | 15 +------------- src/main/sm_main.c | 2 +- 10 files changed, 28 insertions(+), 61 deletions(-) delete mode 100644 build/submodules/bounce/src/.gitkeep delete mode 100644 sms_key diff --git a/Makefile b/Makefile index ad21e7dc..68f6fbe7 100755 --- a/Makefile +++ b/Makefile @@ -20,11 +20,9 @@ SRC_MEM := src/main/memory SRC_TERMINAL := src/main/terminal SRC_TEST := src/test SRC_KERN_TEST := src/kernel_test -SRC_BOUNCE := submodules/bounce/src SRCS_MAIN := $(filter-out $(SRC_MAIN)/sm_main.c, $(shell find $(SRC_MAIN) -name '*.c')) SRCS_TEST := $(shell find $(SRC_TEST) -name '*.c') SRCS_KT := $(shell find $(SRC_KERN_TEST) -name '*.c') -SRCS_BOUNCE := $(filter-out submodules/bounce/src/main.c, $(shell find $(SRC_BOUNCE) -name '*.c')) OBJS_PARSER := $(BUILD_DIR)/$(SRC_BISON_FLEX)/y.tab.c.o $(BUILD_DIR)/$(SRC_BISON_FLEX)/lex.yy.c.o OBJS_PARSER_DBG := $(BUILD_DIR)/$(SRC_BISON_FLEX)/y.tab.c.dbg.o $(BUILD_DIR)/$(SRC_BISON_FLEX)/lex.yy.c.dbg.o OBJS_PARSER_PROF:= $(BUILD_DIR)/$(SRC_BISON_FLEX)/y.tab.c.prof.o $(BUILD_DIR)/$(SRC_BISON_FLEX)/lex.yy.c.prof.o @@ -33,7 +31,6 @@ OBJS_BASE_DBG := $(SRCS_MAIN:%=$(BUILD_DIR)/%.dbg.o) # dbg version of base f OBJS_BASE_PROF := $(SRCS_MAIN:%=$(BUILD_DIR)/%.prof.o) # prof version of base files OBJS_TEST := $(SRCS_TEST:%=$(BUILD_DIR)/%.dbg.o) # sms tests OBJS_KT := $(SRCS_KT:%=$(BUILD_DIR)/%.dbg.o) # sms kernel tests -OBJS_BOUNCE := $(SRCS_BOUNCE:%=$(BUILD_DIR)/%.o) # bounce encryption functions BIN_NAME := sms BIN_NAME_UNIFIED:= sms_unified @@ -50,8 +47,8 @@ main: $(MAKE) $(SRC_BISON_FLEX)/lex.yy.c $(MAKE) -j$(THREADS) bin/$(BIN_NAME) -bin/$(BIN_NAME): $(OBJS_BOUNCE) $(OBJS_PARSER) $(OBJS_BASE) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.o - $(CC) $(CFLAGS) -lm $(OBJS_BOUNCE) $(OBJS_BASE) $(OBJS_PARSER) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.o -o $@ +bin/$(BIN_NAME): $(OBJS_PARSER) $(OBJS_BASE) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.o + $(CC) $(CFLAGS) -lm $(OBJS_BASE) $(OBJS_PARSER) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.o -o $@ # Not files @@ -65,16 +62,16 @@ all: $(MAKE) -j$(THREADS) bin/$(BIN_NAME_DBG) # sms_dbg executable -bin/$(BIN_NAME_DBG): $(OBJS_BOUNCE) $(OBJS_PARSER_DBG) $(OBJS_BASE_DBG) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.dbg.o - $(CC_DEBUG) -lm $(OBJS_BOUNCE) $(CFLAGS_DEBUG) $(OBJS_BASE_DBG) $(OBJS_PARSER_DBG) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.dbg.o -o $@ +bin/$(BIN_NAME_DBG): $(OBJS_PARSER_DBG) $(OBJS_BASE_DBG) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.dbg.o + $(CC_DEBUG) -lm $(CFLAGS_DEBUG) $(OBJS_BASE_DBG) $(OBJS_PARSER_DBG) $(BUILD_DIR)/$(SRC_MAIN)/sm_main.c.dbg.o -o $@ # sms_test executable -bin/$(BIN_NAME_TEST): $(OBJS_BOUNCE) $(OBJS_PARSER_DBG) $(OBJS_BASE_DBG) $(OBJS_TEST) - $(CC_DEBUG) $(CFLAGS_DEBUG) -lm $(OBJS_BOUNCE) $(OBJS_BASE_DBG) $(OBJS_PARSER_DBG) $(OBJS_TEST) -o $@ +bin/$(BIN_NAME_TEST): $(OBJS_PARSER_DBG) $(OBJS_BASE_DBG) $(OBJS_TEST) + $(CC_DEBUG) $(CFLAGS_DEBUG) -lm $(OBJS_BASE_DBG) $(OBJS_PARSER_DBG) $(OBJS_TEST) -o $@ # sms_kernel_test executable -bin/$(BIN_NAME_KT): $(OBJS_BOUNCE) $(OBJS_PARSER) $(OBJS_BASE_DBG) $(OBJS_KT) - $(CC_DEBUG) $(CFLAGS_DEBUG) -lm $(OBJS_BOUNCE) $(OBJS_BASE_DBG) $(OBJS_PARSER) $(OBJS_KT) -o $@ +bin/$(BIN_NAME_KT): $(OBJS_PARSER) $(OBJS_BASE_DBG) $(OBJS_KT) + $(CC_DEBUG) $(CFLAGS_DEBUG) -lm $(OBJS_BASE_DBG) $(OBJS_PARSER) $(OBJS_KT) -o $@ # Bison generates the parser $(SRC_BISON_FLEX)/y.tab.c: $(SRC_MAIN)/parser/sms.y @@ -112,7 +109,6 @@ clean: $(BUILD_DIR)/$(SRC_ENGINE)/*.o\ $(BUILD_DIR)/$(SRC_MEM)/*.o\ $(BUILD_DIR)/$(SRC_TERMINAL)/*.o\ - $(OBJS_BOUNCE)\ bin/sms*\ docs/html @@ -150,7 +146,7 @@ docs: unified: $(MAKE) $(SRC_BISON_FLEX)/y.tab.c $(MAKE) $(SRC_BISON_FLEX)/lex.yy.c - $(CC_UNIFIED) -lm $(SRCS_BOUNCE) $(CFLAGS) $(SRC_BISON_FLEX)/y.tab.c $(SRC_BISON_FLEX)/lex.yy.c $(SRCS_MAIN) $(SRC_MAIN)/sm_main.c -o bin/$(BIN_NAME_UNIFIED) + $(CC_UNIFIED) -lm $(CFLAGS) $(SRC_BISON_FLEX)/y.tab.c $(SRC_BISON_FLEX)/lex.yy.c $(SRCS_MAIN) $(SRC_MAIN)/sm_main.c -o bin/$(BIN_NAME_UNIFIED) # install the unified version install_unified: unified diff --git a/build/submodules/bounce/src/.gitkeep b/build/submodules/bounce/src/.gitkeep deleted file mode 100644 index 6342678f..00000000 --- a/build/submodules/bounce/src/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Where bounce object files go diff --git a/scripts/replace-all.sh b/scripts/replace-all.sh index faa2ebde..b78ff789 100755 --- a/scripts/replace-all.sh +++ b/scripts/replace-all.sh @@ -1,5 +1,5 @@ #backup your code before you do this -str='s/cryptid/crypt_id/g'; +str='s/extern\\ struct\\ sm_heap\\ \\*sms_heap//g'; find ../src/ -name *.c -exec sed -i $str {} + find ../src/ -name *.h -exec sed -i $str {} + find ../src/ -name *.y -exec sed -i $str {} + diff --git a/sms_key b/sms_key deleted file mode 100644 index 8e99beff1abd68339d31133266da486bdfe9a23a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 256 zcmV+b0ssD@hv6R0!mdoc`msV~3>9SJg?wzMSpQO@zqRg^!@@!K7@Y;^@uO()J zaZ_6i;Y6rOfU2B4sM1Qka^b3fsl&@Sy=h)xXg`})i9=N)d8G8-Dgf@aHKPFFo>uu0 za*F&a!^58zU3M;#7RQ?#Pu=;P6rNS`=gs#em6sIrAlKv?CIl>L#DUO+aIo`%}`4+Q~`3XbKK96y7?a6xidF$Q*tRsN^*?px4O=1*<=2)9=>B#St GSZegANr>|R diff --git a/src/main/object/sm_cx.c b/src/main/object/sm_cx.c index 3cc3dee7..734ff7ff 100644 --- a/src/main/object/sm_cx.c +++ b/src/main/object/sm_cx.c @@ -1,7 +1,7 @@ // Read https://raw.githubusercontent.com/reginaldford/sms/main/LICENSE.txt for license information #include "../sms.h" -#include "../../../submodules/bounce/src/bounce.h" + extern sm_heap *sms_symbol_heap; extern uint8_t *sms_key; extern uint32_t sms_ks1; diff --git a/src/main/object/sm_node.c b/src/main/object/sm_node.c index 65159893..602cdbfb 100644 --- a/src/main/object/sm_node.c +++ b/src/main/object/sm_node.c @@ -1,7 +1,7 @@ // Read https://raw.githubusercontent.com/reginaldford/sms/main/LICENSE.txt for license information #include "../sms.h" -#include "../../../submodules/bounce/src/bounce.h" + extern sm_heap *sms_symbol_heap; extern uint32_t sms_num_symbols; extern uint8_t *sms_key; @@ -22,11 +22,12 @@ sm_node *sm_new_node(sm_object *value, struct sm_node *next, long long map, } // Return the sm_node child index correlating to this character +// The index is the ASCII value, the value is a number from 0 to 63. // Input ASCII Group_Size output -// ' is 39 1 0 +// _ is 95 1 0 // 0-9 is 48-57 10 1-10 // A-Z is 65-90 26 11-36 -// _ is 95 1 37 +// ' is 39 1 37 // a-z is 98-122 26 38-63 // Total: 64 int sm_node_map_index(char c) { @@ -48,9 +49,9 @@ int sm_node_map_index(char c) { // Inverse of sm_map_index // Expects 0-63, else, returns NULL char sm_node_bit_unindex(int i) { - static const int output[] = {39, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, + static const int output[] = {95, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 39, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}; if (i < 64) diff --git a/src/main/object/sm_symbol.c b/src/main/object/sm_symbol.c index 0bea3e6a..91dbd225 100644 --- a/src/main/object/sm_symbol.c +++ b/src/main/object/sm_symbol.c @@ -1,35 +1,24 @@ // Read https://raw.githubusercontent.com/reginaldford/sms/main/LICENSE.txt for license information #include "../sms.h" -#include "../../../submodules/bounce/src/bounce.h" extern struct sm_heap *sms_heap; extern struct sm_heap *sms_symbol_heap; extern struct sm_heap *sms_symbol_name_heap; extern uint32_t sms_num_symbols; -extern uint8_t *sms_key; -extern uint32_t sms_ks1; -extern uint32_t sms_ks2; -extern uint8_t sms_sub_table[256]; // Encrypt the id of the symbol // id is the array index of the symbol in the symbol heap sm_string *sm_symbol_encrypt_id(sm_symbol *sym) { - int sym_id = sym - (sm_symbol *)sms_symbol_heap->storage; - uint8_t enc_buffer[] = {0, 0, 0, 0, 0}; - fflush(stdout); - bounce_encrypt((uint8_t *)&sym_id, 4, sms_key, sms_ks1, sms_ks2, sms_sub_table, enc_buffer); - int null_streak; - for (null_streak = 0; null_streak < 4; null_streak++) - if (enc_buffer[3 - null_streak] != 0) - break; - int enc_buffer_used = 4 - null_streak; - char output_str[12]; - uint32_t chunk = *enc_buffer; - uint8_t out_str_len = ceil(enc_buffer_used * 3.0 / 4.0) - 1; - for (uint8_t i = 0; i < out_str_len; i++) { - char zeroTo63 = ((char)(chunk >> i * 6)) & 63; - output_str[i] = sm_node_bit_unindex(zeroTo63); + int32_t sym_id = sym - (sm_symbol *)sms_symbol_heap->storage; + // turn sym_id into hex + char output_str[7]; + uint8_t out_str_len = 0; + while (sym_id) { + char zeroTo63 = (char)((sym_id)&63); + output_str[out_str_len] = sm_node_bit_unindex(zeroTo63); + sym_id = sym_id >> 6; + out_str_len++; } output_str[out_str_len] = '\0'; return sm_new_string_at(sms_symbol_name_heap, out_str_len, output_str); diff --git a/src/main/sm_global.c b/src/main/sm_global.c index f073d9b6..028f8c37 100644 --- a/src/main/sm_global.c +++ b/src/main/sm_global.c @@ -12,11 +12,6 @@ sm_heap *sms_symbol_heap; // Symbol names are in alpabetical order, correlating with the symbol sm_heap *sms_symbol_name_heap; uint32_t sms_num_symbols; -// Bounce prereqs -uint8_t *sms_key; -uint32_t sms_ks1; -uint32_t sms_ks2; -uint8_t sms_sub_table[256]; /* GLOBALS as functions The following globals use functions f(x): diff --git a/src/main/sm_init.c b/src/main/sm_init.c index 416d2c94..1c92587d 100644 --- a/src/main/sm_init.c +++ b/src/main/sm_init.c @@ -1,7 +1,6 @@ // Read https://raw.githubusercontent.com/reginaldford/sms/main/LICENSE.txt for license information #include "sms.h" -#include "../../submodules/bounce/src/bounce.h" extern struct sm_heap *sms_heap; extern struct sm_heap *sms_symbol_heap; @@ -33,22 +32,10 @@ void sm_init(sm_env *env, int num_args, char **argv) { sms_symbol_heap = sm_new_heap(1024 * 512); sms_symbol_name_heap = sm_new_heap(1024 * 1024); sms_num_symbols = 0; + // Initialize the current memory heap // During first gc, a second heap of the same size will be allocated. sms_heap = sm_new_heap(mem_bytes / 2); - // Store bounce encryption prereqs - // Globals: sms_key, sms_ks1, sms_ks2, and sms_sub_table - bounceReadFileResult brfr = bounceReadFile("sms_key"); - if (!brfr.fileExists) { - printf("SMS key file not found!\n"); - exit(1); - } - sms_key = brfr.fileContent; - // Calculate and store the keySum - sms_ks1 = bounceProcKeySum(sms_key); - sms_ks2 = bounceProcKeySum(sms_key + 128); - // Invertable Swap table generated from key - bounceTableInit(sms_key, sms_sub_table); // Initialize the lexical stack sm_global_lex_stack(sm_new_stack(128)); diff --git a/src/main/sm_main.c b/src/main/sm_main.c index a0ca6564..c15e8203 100644 --- a/src/main/sm_main.c +++ b/src/main/sm_main.c @@ -10,7 +10,7 @@ extern int yylineno; void print_intro() { printf("%s%sSymbolic Math System\n", sm_terminal_bg_color(SM_TERM_BLACK), sm_terminal_fg_color(SM_TERM_B_BLUE)); - printf("%sVersion 0.206%s\n", sm_terminal_fg_color(SM_TERM_B_WHITE), sm_terminal_reset()); + printf("%sVersion 0.207%s\n", sm_terminal_fg_color(SM_TERM_B_WHITE), sm_terminal_reset()); } // Initialize the heap, etc, if necessary