| @@ -0,0 +1 @@ | |||||
| (define variable "Hello World!") | |||||
| @@ -0,0 +1,3 @@ | |||||
| (import "tests/import.slime") | |||||
| (print variable) | |||||
| @@ -0,0 +1,14 @@ | |||||
| <?xml version='1.0' encoding='UTF-8'?> | |||||
| <svg xmlns='http://www.w3.org/2000/svg' | |||||
| version='1.1' baseProfile='full' | |||||
| viewBox='-00030 -00030 000288 000090'> | |||||
| <text x='0' y='12' font-size='20' font-family='monospace'> | |||||
| doeun | |||||
| </text> | |||||
| <text x='0' y='30' font-size='20' font-family='monospace'> | |||||
| ASDNew texhgfdgdhft | |||||
| </text> | |||||
| </svg> | |||||
| @@ -2,6 +2,7 @@ TIMEFORMAT=%3lR | |||||
| SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" | ||||
| pushd $SCRIPTPATH > /dev/null | pushd $SCRIPTPATH > /dev/null | ||||
| # _DEBUG | |||||
| time clang++ src/main.cpp -g -o ./bin/slime --std=c++17 || exit 1 | time clang++ src/main.cpp -g -o ./bin/slime --std=c++17 || exit 1 | ||||
| echo "" | echo "" | ||||
| @@ -28,7 +28,7 @@ constexpr bool is_debug_build = false; | |||||
| else \ | else \ | ||||
| while (1) \ | while (1) \ | ||||
| if (1) { \ | if (1) { \ | ||||
| if(Globals::error) { \ | |||||
| if (Globals::error) { \ | |||||
| if (Globals::log_level == Log_Level::Debug) { \ | if (Globals::log_level == Log_Level::Debug) { \ | ||||
| printf("in %s:%d\n", __FILE__, __LINE__); \ | printf("in %s:%d\n", __FILE__, __LINE__); \ | ||||
| } \ | } \ | ||||
| @@ -44,7 +44,7 @@ constexpr bool is_debug_build = false; | |||||
| else \ | else \ | ||||
| while (1) \ | while (1) \ | ||||
| if (1) { \ | if (1) { \ | ||||
| if(Globals::error) { \ | |||||
| if (Globals::error) { \ | |||||
| if (Globals::log_level == Log_Level::Debug) { \ | if (Globals::log_level == Log_Level::Debug) { \ | ||||
| printf("in %s:%d\n", __FILE__, __LINE__); \ | printf("in %s:%d\n", __FILE__, __LINE__); \ | ||||
| } \ | } \ | ||||
| @@ -8,7 +8,7 @@ proc delete_error() -> void { | |||||
| } | } | ||||
| proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, String* message) -> void { | proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, String* message) -> void { | ||||
| visualize_lisp_machine(); | |||||
| printf("Error created in:\n%s:%d\n", c_file_name, c_file_line); | printf("Error created in:\n%s:%d\n", c_file_name, c_file_line); | ||||
| delete_error(); | delete_error(); | ||||
| @@ -14,6 +14,8 @@ proc print_environment(Environment*) -> void; | |||||
| proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char*; | proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char*; | ||||
| proc visualize_lisp_machine() -> void; | |||||
| namespace Memory { | namespace Memory { | ||||
| proc create_built_ins_environment() -> Environment*; | proc create_built_ins_environment() -> Environment*; | ||||
| proc get_or_create_lisp_object_keyword(const char* identifier) -> Lisp_Object*; | proc get_or_create_lisp_object_keyword(const char* identifier) -> Lisp_Object*; | ||||
| @@ -23,6 +23,7 @@ namespace Slime { | |||||
| # include "./env.cpp" | # include "./env.cpp" | ||||
| # include "./parse.cpp" | # include "./parse.cpp" | ||||
| # include "./eval.cpp" | # include "./eval.cpp" | ||||
| # include "./visualization.cpp" | |||||
| # include "./built_ins.cpp" | # include "./built_ins.cpp" | ||||
| # include "./testing.cpp" | # include "./testing.cpp" | ||||
| # include "./undefines.cpp" | # include "./undefines.cpp" | ||||
| @@ -485,16 +485,17 @@ proc test_file(const char* file) -> testresult { | |||||
| Memory::reset(); | Memory::reset(); | ||||
| assert_no_error(); | assert_no_error(); | ||||
| Environment* env = Memory::create_built_ins_environment(); | |||||
| Environment* root_env = Memory::create_built_ins_environment(); | |||||
| assert_no_error(); | assert_no_error(); | ||||
| Parser::environment_for_macros = env; | |||||
| Environment* user_env = Memory::create_child_environment(root_env); | |||||
| assert_no_error(); | assert_no_error(); | ||||
| built_in_load(Memory::create_string("pre.slime"), env); | |||||
| Parser::environment_for_macros = root_env; | |||||
| built_in_import(Memory::create_string("pre.slime"), user_env); | |||||
| assert_no_error(); | assert_no_error(); | ||||
| Lisp_Object* result = built_in_load(Memory::create_string(file), env); | |||||
| Lisp_Object* result = built_in_load(Memory::create_string(file), user_env); | |||||
| assert_no_error(); | assert_no_error(); | ||||
| return pass; | return pass; | ||||
| @@ -532,6 +533,7 @@ proc run_all_tests() -> bool { | |||||
| invoke_test_script("lexical_scope"); | invoke_test_script("lexical_scope"); | ||||
| invoke_test_script("class_macro"); | invoke_test_script("class_macro"); | ||||
| invoke_test_script("sicp"); | invoke_test_script("sicp"); | ||||
| invoke_test_script("import_and_load"); | |||||
| return result; | return result; | ||||
| } | } | ||||
| @@ -0,0 +1,65 @@ | |||||
| proc visualize_lisp_machine() -> void { | |||||
| const int padding = 30; | |||||
| const int margin = 20; | |||||
| FILE *f = fopen("visualization.svg", "w"); | |||||
| defer { | |||||
| fclose(f); | |||||
| }; | |||||
| if (f == NULL) { | |||||
| create_generic_error("The file for writing the visualization" | |||||
| "could not be opened for writing"); | |||||
| return; | |||||
| } | |||||
| int max_x = 0, | |||||
| max_y = 0, | |||||
| write_x = 0, | |||||
| write_y = 0; | |||||
| proc draw_text = [&](const char* text) { | |||||
| int text_width = 12 * strlen(text); | |||||
| int text_height = 12; | |||||
| if (write_x + text_width > max_x) max_x = write_x + text_width; | |||||
| if (write_y > max_y) max_y = write_y; | |||||
| fprintf(f, | |||||
| " <text x='%d' y='%d' font-size='20' " | |||||
| "font-family='monospace'>\n" | |||||
| " %s" | |||||
| "\n </text>\n", write_x, write_y, text); | |||||
| write_x += text_width; | |||||
| }; | |||||
| proc draw_header = [&](){ | |||||
| write_y = 12; | |||||
| // draw_text("ASD"); | |||||
| // write_x += margin; | |||||
| draw_text("doeun"); | |||||
| }; | |||||
| fprintf(f, | |||||
| "<?xml version='1.0' encoding='UTF-8'?>\n" | |||||
| "<svg xmlns='http://www.w3.org/2000/svg'\n" | |||||
| " version='1.1' baseProfile='full'\n" | |||||
| " viewBox='%06d %06d %06d %06d'" | |||||
| ">\n\n", -padding, -padding, 0, 0); | |||||
| draw_header(); | |||||
| fprintf(f, "\n\n</svg>"); | |||||
| // fill in the correct viewBox | |||||
| rewind(f); | |||||
| fprintf(f, | |||||
| "<?xml version='1.0' encoding='UTF-8'?>\n" | |||||
| "<svg xmlns='http://www.w3.org/2000/svg'\n" | |||||
| " version='1.1' baseProfile='full'\n" | |||||
| " viewBox='%06d %06d %06d %06d'", -padding, -padding, max_x + 2*padding, max_y + 2*padding); | |||||
| } | |||||