better arguments struct, arraylists as values, fixed docgen
This commit is contained in:
+55
-55
@@ -305,8 +305,8 @@ proc visualize_lisp_machine() -> void {
|
||||
draw_new_line();
|
||||
|
||||
int free_string_memory = (int)(Memory::next_free_spot_in_string_memory - Memory::string_memory);
|
||||
for (int i = 0; i < Memory::free_spots_in_string_memory->next_index; ++i) {
|
||||
free_string_memory += ((String*)(Memory::free_spots_in_string_memory->data[i]))->length;
|
||||
for (int i = 0; i < Memory::free_spots_in_string_memory.next_index; ++i) {
|
||||
free_string_memory += ((String*)(Memory::free_spots_in_string_memory.data[i]))->length;
|
||||
}
|
||||
int used_string_memory = Memory::string_memory_size - free_string_memory;
|
||||
|
||||
@@ -334,8 +334,8 @@ proc visualize_lisp_machine() -> void {
|
||||
// Object Memory
|
||||
// -------------------
|
||||
|
||||
int free_object_memory_cells = Memory::object_memory_size - (Memory::next_index_in_object_memory - Memory::free_spots_in_object_memory->next_index);
|
||||
int used_object_memory_cells = Memory::next_index_in_object_memory - Memory::free_spots_in_object_memory->next_index;
|
||||
int free_object_memory_cells = Memory::object_memory_size - (Memory::next_index_in_object_memory - Memory::free_spots_in_object_memory.next_index);
|
||||
int used_object_memory_cells = Memory::next_index_in_object_memory - Memory::free_spots_in_object_memory.next_index;
|
||||
|
||||
write_x += draw_text("Object Memory:").width;
|
||||
draw_margin();
|
||||
@@ -359,26 +359,26 @@ proc visualize_lisp_machine() -> void {
|
||||
draw_new_line(3);
|
||||
};
|
||||
proc draw_symbols_keywords_and_numbers = [&]() {
|
||||
Lisp_Object_Array_List* symbols = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List* keywords = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List* numbers = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List* strings = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List* pairs = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List* lists = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List symbols = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List keywords = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List numbers = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List strings = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List pairs = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List lists = create_Lisp_Object_array_list();
|
||||
|
||||
// loop over all used memory
|
||||
for (int i = 0; i < Memory::next_index_in_object_memory; ++i) {
|
||||
for (int j = 0; j < Memory::free_spots_in_object_memory->next_index; ++j) {
|
||||
if (i == Memory::free_spots_in_object_memory->data[j])
|
||||
for (int j = 0; j < Memory::free_spots_in_object_memory.next_index; ++j) {
|
||||
if (i == Memory::free_spots_in_object_memory.data[j])
|
||||
goto next;
|
||||
}
|
||||
|
||||
switch (Memory::get_type(Memory::object_memory+i)) {
|
||||
case Lisp_Object_Type::Symbol: append_to_array_list(symbols, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::String: append_to_array_list(strings, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Keyword: append_to_array_list(keywords, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Number : append_to_array_list(numbers, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Pair : append_to_array_list(pairs, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Symbol: append_to_array_list(&symbols, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::String: append_to_array_list(&strings, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Keyword: append_to_array_list(&keywords, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Number : append_to_array_list(&numbers, Memory::object_memory+i); break;
|
||||
case Lisp_Object_Type::Pair : append_to_array_list(&pairs, Memory::object_memory+i); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -386,36 +386,36 @@ proc visualize_lisp_machine() -> void {
|
||||
}
|
||||
|
||||
// create the lists-list by filtering the pairs-list.
|
||||
Lisp_Object_Array_List* pairs_to_filter = create_Lisp_Object_array_list();
|
||||
Lisp_Object_Array_List pairs_to_filter = create_Lisp_Object_array_list();
|
||||
|
||||
// helper lambda:
|
||||
proc remove_doubles_from_lisp_object_array_list = [&](Lisp_Object_Array_List* list) -> void {
|
||||
if (list->next_index == 0)
|
||||
proc remove_doubles_from_lisp_object_array_list = [&](Lisp_Object_Array_List list) -> void {
|
||||
if (list.next_index == 0)
|
||||
return;
|
||||
|
||||
sort_array_list(list);
|
||||
Int_Array_List* indices_to_filter = create_Int_array_list();
|
||||
sort_array_list(&list);
|
||||
Int_Array_List indices_to_filter = create_Int_array_list();
|
||||
|
||||
size_t last = (size_t)list->data[0];
|
||||
for (int i = 1; i < list->next_index; ++i) {
|
||||
if ((size_t)list->data[i] == last)
|
||||
append_to_array_list(indices_to_filter, i);
|
||||
size_t last = (size_t)list.data[0];
|
||||
for (int i = 1; i < list.next_index; ++i) {
|
||||
if ((size_t)list.data[i] == last)
|
||||
append_to_array_list(&indices_to_filter, i);
|
||||
else
|
||||
last = (size_t)list->data[i];
|
||||
last = (size_t)list.data[i];
|
||||
}
|
||||
|
||||
for (int i = indices_to_filter->next_index; i >= 0; --i) {
|
||||
remove_index_from_array_list(list, indices_to_filter->data[i]);
|
||||
for (int i = indices_to_filter.next_index; i >= 0; --i) {
|
||||
remove_index_from_array_list(&list, indices_to_filter.data[i]);
|
||||
}
|
||||
|
||||
// sort again as removing items destroys the order
|
||||
sort_array_list(list);
|
||||
sort_array_list(&list);
|
||||
};
|
||||
|
||||
// recursive lambda
|
||||
std::function<void(Lisp_Object*)> filter_pair_and_children;
|
||||
filter_pair_and_children = [&](Lisp_Object* pair) {
|
||||
append_to_array_list(pairs_to_filter, pair);
|
||||
append_to_array_list(&pairs_to_filter, pair);
|
||||
|
||||
if (Memory::get_type(pair->value.pair.first) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pair->value.pair.first);
|
||||
@@ -423,12 +423,12 @@ proc visualize_lisp_machine() -> void {
|
||||
if (Memory::get_type(pair->value.pair.rest) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pair->value.pair.rest);
|
||||
};
|
||||
for (int i = 0; i < pairs->next_index; ++i) {
|
||||
if (Memory::get_type(pairs->data[i]->value.pair.first) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pairs->data[i]->value.pair.first);
|
||||
for (int i = 0; i < pairs.next_index; ++i) {
|
||||
if (Memory::get_type(pairs.data[i]->value.pair.first) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pairs.data[i]->value.pair.first);
|
||||
|
||||
if (Memory::get_type(pairs->data[i]->value.pair.rest) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pairs->data[i]->value.pair.rest);
|
||||
if (Memory::get_type(pairs.data[i]->value.pair.rest) == Lisp_Object_Type::Pair)
|
||||
filter_pair_and_children(pairs.data[i]->value.pair.rest);
|
||||
|
||||
}
|
||||
|
||||
@@ -436,9 +436,9 @@ proc visualize_lisp_machine() -> void {
|
||||
// fprintf(stderr, "removing %d pairs\n", pairs_to_filter->next_index);
|
||||
// okay, so pairs_to_filter now only the pairs once each that
|
||||
// we want to filter from the pairs list
|
||||
for (int i = 0; i < pairs->next_index; ++i) {
|
||||
if (sorted_array_list_find(pairs_to_filter, pairs->data[i]) == -1) {
|
||||
append_to_array_list(lists, pairs->data[i]);
|
||||
for (int i = 0; i < pairs.next_index; ++i) {
|
||||
if (sorted_array_list_find(&pairs_to_filter, pairs.data[i]) == -1) {
|
||||
append_to_array_list(&lists, pairs.data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,15 +450,15 @@ proc visualize_lisp_machine() -> void {
|
||||
start_y = write_y;
|
||||
|
||||
write_x += draw_text("Symbols: ").width;
|
||||
draw_integer(symbols->next_index);
|
||||
draw_integer(symbols.next_index);
|
||||
draw_new_line();
|
||||
write_x = start_x;
|
||||
|
||||
for (int i = 0; i < symbols->next_index; ++i) {
|
||||
for (int i = 0; i < symbols.next_index; ++i) {
|
||||
draw_new_line();
|
||||
write_x = start_x;
|
||||
|
||||
draw_text(&symbols->data[i]->value.symbol.identifier->data);
|
||||
draw_text(&symbols.data[i]->value.symbol.identifier->data);
|
||||
}
|
||||
|
||||
|
||||
@@ -466,15 +466,15 @@ proc visualize_lisp_machine() -> void {
|
||||
write_y = start_y;
|
||||
|
||||
write_x += draw_text("Keywords: ").width;
|
||||
draw_integer(keywords->next_index);
|
||||
draw_integer(keywords.next_index);
|
||||
draw_new_line();
|
||||
write_x = start_x + 300;
|
||||
|
||||
for (int i = 0; i < keywords->next_index; ++i) {
|
||||
for (int i = 0; i < keywords.next_index; ++i) {
|
||||
draw_new_line();
|
||||
write_x = start_x + 300;
|
||||
|
||||
draw_lisp_object(keywords->data[i]);
|
||||
draw_lisp_object(keywords.data[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -483,30 +483,30 @@ proc visualize_lisp_machine() -> void {
|
||||
write_y = start_y;
|
||||
|
||||
write_x += draw_text("Numbers: ").width;
|
||||
draw_integer(numbers->next_index);
|
||||
draw_integer(numbers.next_index);
|
||||
draw_new_line();
|
||||
write_x = start_x + 600;
|
||||
|
||||
for (int i = 0; i < numbers->next_index; ++i) {
|
||||
for (int i = 0; i < numbers.next_index; ++i) {
|
||||
draw_new_line();
|
||||
write_x = start_x + 600;
|
||||
|
||||
draw_float((float)(numbers->data[i]->value.number));
|
||||
draw_float((float)(numbers.data[i]->value.number));
|
||||
}
|
||||
|
||||
write_x = start_x + 900;
|
||||
write_y = start_y;
|
||||
|
||||
write_x += draw_text("Strings: ").width;
|
||||
draw_integer(strings->next_index);
|
||||
draw_integer(strings.next_index);
|
||||
draw_new_line();
|
||||
write_x = start_x + 900;
|
||||
|
||||
for (int i = 0; i < strings->next_index; ++i) {
|
||||
for (int i = 0; i < strings.next_index; ++i) {
|
||||
draw_new_line();
|
||||
write_x = start_x + 900;
|
||||
|
||||
draw_text(&strings->data[i]->value.string->data, "#2aa198", true, 75);
|
||||
draw_text(&strings.data[i]->value.string->data, "#2aa198", true, 75);
|
||||
}
|
||||
|
||||
|
||||
@@ -514,17 +514,17 @@ proc visualize_lisp_machine() -> void {
|
||||
write_y = start_y;
|
||||
|
||||
write_x += draw_text("Lists, Pairs: ").width;
|
||||
write_x += draw_integer(lists->next_index).width;
|
||||
write_x += draw_integer(lists.next_index).width;
|
||||
draw_margin();
|
||||
draw_integer(pairs->next_index);
|
||||
draw_integer(pairs.next_index);
|
||||
draw_new_line();
|
||||
write_x = start_x + 2000;
|
||||
|
||||
for (int i = 0; i < lists->next_index; ++i) {
|
||||
for (int i = 0; i < lists.next_index; ++i) {
|
||||
draw_new_line(3);
|
||||
write_x = start_x + 2000;
|
||||
|
||||
write_y += draw_pair(lists->data[i]).height;
|
||||
write_y += draw_pair(lists.data[i]).height;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user