made it possible to specify the needed memory in Memory::init()
This commit is contained in:
+2
-2
@@ -429,7 +429,7 @@ proc is_truthy (Lisp_Object* expression, Environment* env) -> bool {
|
||||
}
|
||||
|
||||
proc interprete_file (char* file_name) -> Lisp_Object* {
|
||||
Memory::init();
|
||||
Memory::init(4096 * 256, 4096 * 256);
|
||||
Environment* env = Memory::create_empty_environment();
|
||||
Parser::init(env);
|
||||
|
||||
@@ -461,7 +461,7 @@ proc interprete_file (char* file_name) -> Lisp_Object* {
|
||||
}
|
||||
|
||||
proc interprete_stdin() -> void {
|
||||
Memory::init();
|
||||
Memory::init(4096 * 256, 4096 * 256);
|
||||
Environment* env = Memory::create_built_ins_environment();
|
||||
Parser::init(env);
|
||||
|
||||
|
||||
+14
-4
@@ -3,7 +3,7 @@ namespace Memory {
|
||||
// ------------------
|
||||
// lisp_object
|
||||
// ------------------
|
||||
constexpr int object_memory_size = 4096 * 1024; // == 98304kb == 96mb
|
||||
int object_memory_size;
|
||||
Int_Array_List* free_spots_in_object_memory;
|
||||
Lisp_Object* object_memory;
|
||||
int next_index_in_object_memory = 0;
|
||||
@@ -11,7 +11,7 @@ namespace Memory {
|
||||
// ------------------
|
||||
// strings
|
||||
// ------------------
|
||||
constexpr int string_memory_size = 4096 * 1024; // == 98304kb == 96mb
|
||||
int string_memory_size; // = 4096 * 1024; // == 98304kb == 96mb
|
||||
// free_spots_in_string_memory is an arraylist of pointers into
|
||||
// the string_memory, where dead String objects live (which give
|
||||
// information about their size)
|
||||
@@ -102,12 +102,15 @@ namespace Memory {
|
||||
return object;
|
||||
}
|
||||
|
||||
proc init() {
|
||||
proc init(int oms, int sms) {
|
||||
object_memory_size = oms;
|
||||
string_memory_size = sms;
|
||||
|
||||
free_spots_in_object_memory = create_Int_array_list();
|
||||
free_spots_in_string_memory = create_Void_Ptr_array_list();
|
||||
|
||||
object_memory = (Lisp_Object*)malloc(object_memory_size * sizeof(Lisp_Object));
|
||||
string_memory = (String*)malloc(object_memory_size * sizeof(Lisp_Object));
|
||||
string_memory = (String*)malloc(string_memory_size * sizeof(char));
|
||||
|
||||
next_free_spot_in_string_memory = string_memory;
|
||||
|
||||
@@ -120,6 +123,13 @@ namespace Memory {
|
||||
t->type = Lisp_Object_Type::T;
|
||||
}
|
||||
|
||||
proc reset() {
|
||||
free_spots_in_object_memory->next_index = 0;
|
||||
free_spots_in_string_memory->next_index = 0;
|
||||
next_index_in_object_memory = 2; // because t and nil are always there
|
||||
next_free_spot_in_string_memory = string_memory;
|
||||
}
|
||||
|
||||
proc create_lisp_object_number(double number) -> Lisp_Object* {
|
||||
Lisp_Object* node = create_lisp_object();
|
||||
node->type = Lisp_Object_Type::Number;
|
||||
|
||||
+4
-3
@@ -461,7 +461,7 @@ proc test_singular_t_and_nil() -> testresult {
|
||||
}
|
||||
|
||||
proc test_class_macro() -> testresult {
|
||||
Memory::init();
|
||||
Memory::reset();
|
||||
Environment* env = Memory::create_built_ins_environment();
|
||||
Parser::init(env);
|
||||
|
||||
@@ -474,7 +474,7 @@ proc test_class_macro() -> testresult {
|
||||
}
|
||||
|
||||
proc test_lexical_scope() -> testresult {
|
||||
Memory::init();
|
||||
Memory::reset();
|
||||
Environment* env = Memory::create_built_ins_environment();
|
||||
Parser::init(env);
|
||||
|
||||
@@ -492,7 +492,7 @@ proc run_all_tests() -> bool {
|
||||
log_level = log_level_before;
|
||||
};
|
||||
|
||||
Memory::init();
|
||||
Memory::init(4096 * 2, 4096 * 16);
|
||||
Parser::init(Memory::create_built_ins_environment());
|
||||
|
||||
bool result = true;
|
||||
@@ -544,3 +544,4 @@ proc run_all_tests() -> bool {
|
||||
#undef assert_null
|
||||
#undef assert_not_null
|
||||
#undef invoke_test
|
||||
#undef invoke_test_script
|
||||
|
||||
Reference in New Issue
Block a user