Skip to content

Commit

Permalink
fastmaps done. tests passing. merging now. release after cleanup. sms…
Browse files Browse the repository at this point in the history
… is FAST now
  • Loading branch information
reginaldford committed Mar 7, 2024
1 parent bea1835 commit ee36eb4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 61 deletions.
22 changes: 9 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion build/submodules/bounce/src/.gitkeep

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/replace-all.sh
Original file line number Diff line number Diff line change
@@ -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 {} +
Expand Down
Binary file removed sms_key
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/object/sm_cx.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/main/object/sm_node.c
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
29 changes: 9 additions & 20 deletions src/main/object/sm_symbol.c
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/main/sm_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 1 addition & 14 deletions src/main/sm_init.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/main/sm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee36eb4

Please sign in to comment.