Przeglądaj źródła

started on svg visualization

master
Felix Brendel 7 lat temu
rodzic
commit
a3f74cdaec
10 zmienionych plików z 97 dodań i 8 usunięć
  1. +1
    -0
      bin/tests/import.slime
  2. +3
    -0
      bin/tests/import_and_load.slime
  3. +14
    -0
      bin/visualization.svg
  4. +1
    -0
      build.sh
  5. +2
    -2
      src/defines.cpp
  6. +1
    -1
      src/error.cpp
  7. +2
    -0
      src/forward_decls.cpp
  8. +1
    -0
      src/slime.h
  9. +7
    -5
      src/testing.cpp
  10. +65
    -0
      src/visualization.cpp

+ 1
- 0
bin/tests/import.slime Wyświetl plik

@@ -0,0 +1 @@
(define variable "Hello World!")

+ 3
- 0
bin/tests/import_and_load.slime Wyświetl plik

@@ -0,0 +1,3 @@
(import "tests/import.slime")

(print variable)

+ 14
- 0
bin/visualization.svg Wyświetl plik

@@ -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>

+ 1
- 0
build.sh Wyświetl plik

@@ -2,6 +2,7 @@ TIMEFORMAT=%3lR
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
pushd $SCRIPTPATH > /dev/null

# _DEBUG
time clang++ src/main.cpp -g -o ./bin/slime --std=c++17 || exit 1

echo ""


+ 2
- 2
src/defines.cpp Wyświetl plik

@@ -28,7 +28,7 @@ constexpr bool is_debug_build = false;
else \
while (1) \
if (1) { \
if(Globals::error) { \
if (Globals::error) { \
if (Globals::log_level == Log_Level::Debug) { \
printf("in %s:%d\n", __FILE__, __LINE__); \
} \
@@ -44,7 +44,7 @@ constexpr bool is_debug_build = false;
else \
while (1) \
if (1) { \
if(Globals::error) { \
if (Globals::error) { \
if (Globals::log_level == Log_Level::Debug) { \
printf("in %s:%d\n", __FILE__, __LINE__); \
} \


+ 1
- 1
src/error.cpp Wyświetl plik

@@ -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 {
visualize_lisp_machine();
printf("Error created in:\n%s:%d\n", c_file_name, c_file_line);

delete_error();


+ 2
- 0
src/forward_decls.cpp Wyświetl plik

@@ -14,6 +14,8 @@ proc print_environment(Environment*) -> void;

proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char*;

proc visualize_lisp_machine() -> void;

namespace Memory {
proc create_built_ins_environment() -> Environment*;
proc get_or_create_lisp_object_keyword(const char* identifier) -> Lisp_Object*;


+ 1
- 0
src/slime.h Wyświetl plik

@@ -23,6 +23,7 @@ namespace Slime {
# include "./env.cpp"
# include "./parse.cpp"
# include "./eval.cpp"
# include "./visualization.cpp"
# include "./built_ins.cpp"
# include "./testing.cpp"
# include "./undefines.cpp"


+ 7
- 5
src/testing.cpp Wyświetl plik

@@ -485,16 +485,17 @@ proc test_file(const char* file) -> testresult {
Memory::reset();
assert_no_error();

Environment* env = Memory::create_built_ins_environment();
Environment* root_env = Memory::create_built_ins_environment();
assert_no_error();

Parser::environment_for_macros = env;
Environment* user_env = Memory::create_child_environment(root_env);
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();

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();

return pass;
@@ -532,6 +533,7 @@ proc run_all_tests() -> bool {
invoke_test_script("lexical_scope");
invoke_test_script("class_macro");
invoke_test_script("sicp");
invoke_test_script("import_and_load");

return result;
}


+ 65
- 0
src/visualization.cpp Wyświetl plik

@@ -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);

}

Ładowanie…
Anuluj
Zapisz