updated to use type-extensible hashmaps

This commit is contained in:
FelixBrendel
2019-10-03 16:52:33 +02:00
parent b19af904d0
commit 2cc076fa43
5 changed files with 34 additions and 4 deletions
+1
View File
@@ -426,6 +426,7 @@ proc load_built_ins_into_environment() -> void {
define_special((define definee (:doc "") . body), "TODO") {
fetch(definee, doc, body);
// print_hm(get_current_environment()->hm);
try assert_type(doc, Lisp_Object_Type::String);
// if no doc string, we dont have to store it
+1 -1
View File
@@ -16,7 +16,7 @@ proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, S
delete_error();
if (Globals::breaking_on_errors) {
// debug_break();
debug_break();
}
// visualize_lisp_machine();
+1 -1
Submodule src/ftb updated: 854593273f...2f6954b520
+1 -1
View File
@@ -387,7 +387,7 @@ namespace Memory {
if (parent)
append_to_array_list(&env->parents, parent);
env->hm = create_hashmap();
env->hm = create_String_hashmap();
return env;
}
+30 -1
View File
@@ -2,12 +2,41 @@ struct Lisp_Object;
struct String;
struct Environment;
// ARRAY LISTS
define_array_list(Lisp_Object*, Lisp_Object);
define_array_list(Environment*, Environment);
define_array_list(String*, String);
define_array_list(int, Int);
define_array_list(void*, Void_Ptr);
// HASH MAPS
inline bool hm_objects_match(char* a, char* b) {
return strcmp(a, b) == 0;
}
inline bool hm_objects_match(void* a, void* b) {
return a == b;
}
u32 hm_hash(void* ptr) {
return ((unsigned long long)ptr * 2654435761) % 4294967296;
}
u32 hm_hash(char* str) {
u32 value = str[0] << 7;
int i = 0;
while (str[i]) {
value = (10000003 * value) ^ str[i++];
}
return value ^ i;
}
define_hash_map(char*, String);
define_hash_map(void*, Void_Ptr);
#define for_str_hash_map(hm) __for_hm_generator(char*, hm)
#define for_ptr_hash_map(hm) __for_hm_generator(void*, hm)
// STRUCTS
enum struct Thread_Type {
Main,
GarbageCollection
@@ -111,7 +140,7 @@ struct Arguments {
struct Environment {
Environment_Array_List parents;
StringHashMap* hm;
String_Hash_Map* hm;
// int capacity;
// int next_index;