diff --git a/bin/visualization.svg b/bin/visualization.svg index 225656e..87bb694 100644 --- a/bin/visualization.svg +++ b/bin/visualization.svg @@ -1,13 +1,13 @@ + viewBox='-00000000040 -00000000040 000000003424 000000019754'> Date: - 07.05.2019 + 12.05.2019 | @@ -16,7 +16,7 @@ Time: - 21:51:56 + 11:40:20 | @@ -34,25 +34,25 @@ [free] - 3026 + 4924 [used] - 62510 + 60612 [%free] - 00004.617310 + 00007.513428 [%used] - 00095.382690 + 00092.486572 | @@ -70,27 +70,27 @@ [#free] - 8191179 + 8190327 [#used] - 821 + 1673 - + [%free] - - 00099.989975 + + 00099.979576 - + [%used] - - 00000.010022 + + 00000.020422 - + | @@ -100,7 +100,7 @@ Symbols: - 302 + 778 = @@ -250,2766 +250,2819 @@ concat-strings - define-syntax + sym - when + + - condition + fun - body + + - if + define - condition + fun - unquote + lambda - pair + x - prog + + - body + * - unquote + x - nil + x - quasiquote + eval - prog + + - define-syntax + eval - unless + = - condition + > - body + >= - if + < - condition + <= - unquote + + - nil + - - pair + * - prog + / - body + ** - unquote + % - quasiquote + assert - prog + define - define-syntax + mutate - cond + if - clauses + quote - define + quasiquote - rec + and - clauses + or - if + not - = + while - nil + let - clauses + lambda - nil + special-lambda - if + eval - = + prog - first + list - first + pair - clauses + first - else + rest - quote + set-type - prog + delete-type - if + type - not + info - = + show - rest + print - clauses + read - error + exit - pair + break - prog + memstat - quote + try - rest + load - first + import - clauses + copy - list + error - if + symbol->keyword - quote + string->symbol - first + symbol->string - first + concat-strings - clauses + + - pair + = - prog + > - quote + >= - rest + < - first + <= - clauses + + - rec + - - rest + * - clauses + / - rec + ** - clauses + % - prog + assert define - nil? + mutate - x + if - = + quote - x + quasiquote - nil + and - define + or - number? + not - x + while - = + let - type + lambda - x + special-lambda - define + eval - symbol? + prog - x + list - = + pair - type + first - x + rest - define + set-type - keyword? + delete-type - x + type - = + info - type + show - x + print - define + read - pair? + exit - x + break - = + memstat - type + try - x + load - define + import - string? + copy - x + error - = + symbol->keyword - type + string->symbol - x + symbol->string - define + concat-strings - lambda? + - - x + = - = + > - type + >= - x + < - define + <= - special-lambda? + + - x + - - = + * - type + / - x + ** - define + % - built-n-function? + assert - x + define - = + mutate - type + if - x + quote - define + quasiquote - apply + and - fun + or - seq + not - eval + while - pair + let - fun + lambda - seq + special-lambda - define + eval - end + prog - seq + list - if + pair - or + first - nil? + rest - seq + set-type - not + delete-type - pair? + type - rest + info - seq + show - seq + print - end + read - rest + exit - seq + break - define + memstat - last + try - seq + load - first + import - end + copy - seq + error - define + symbol->keyword - extend + string->symbol - seq + symbol->string - elem + concat-strings - if + * - pair? + = - seq + > - prog + >= - define + < - e + <= - end + + - seq + - - mutate + * - e + / - pair + ** - first + % - e + assert - elem + define - seq + mutate - elem + if - define + quote - append + quasiquote - seq + and - elem + or - extend + not - seq + while - pair + let - elem + lambda - nil + special-lambda - define-syntax + eval - extend! + prog - seq + list - elem + pair - mutate + first - seq + rest - unquote + set-type - extend + delete-type - seq + type - unquote + info - elem + show - unquote + print - quasiquote + read - prog + exit - define-syntax + break - append! + memstat - seq + try - elem + load - mutate + import - seq + copy - unquote + error - append + symbol->keyword - seq + string->symbol - unquote + symbol->string - elem + concat-strings - unquote + / - quasiquote + = - prog + > - define + >= - length + < - seq + <= - if + + - nil? + - - seq + * - + + / - length + ** - rest + % - seq + assert define - increment + mutate - val + if - + + quote - val + quasiquote - define + and - decrement + or - val + not - - + while - val + let - define + lambda - range + special-lambda - from + eval - to + prog - when + list - < + pair - from + first - to + rest - pair + set-type - from + delete-type - range + type - + + info - from + show - to + print - condition + read - body + exit - - Keywords: + + break - - 16 + + memstat - - : + + try - - rest + + load - - : + + import - - rest + + copy - - : + + error - - rest + + symbol->keyword - - : + + string->symbol - - number + + symbol->string - - : + + concat-strings - - symbol + + if - - : + + = - - keyword + + > - - : + + >= - - pair + + < - - : + + <= - - string + + + - - : + + - - - dynamic-function + + * - - : + + / - - dynamic-macro + + ** - - : + + % - - built-in-function + + assert - - : + + define - - keys + + mutate - - : + + if - - defaults-to + + quote - - : + + quasiquote - - from + + and - - : + + or - - to + + not - - : + + while - - symbol-undefined + + let - - Numbers: + + lambda - - 6 + + special-lambda - - 00000.000000 + + eval - - 00001.000000 + + prog - - 00001.000000 + + list - - 00001.000000 + + pair - - 00000.000000 + + first - - 00001.000000 + + rest - - Strings: + + set-type - - 21 + + delete-type - - "Doc String for 'when'" + + type - - "There are additional clauses after the else clause!" + + info - - "Checks if the argument is nil." + + show - - "Checks if the argument is a number." + + print - - "Checks if the argument is a symbol." + + read - - "Checks if the argument is a keyword." + + exit - - "Checks if the argument is a pair." + + break - - "Checks if the argument is a string." + + memstat - - "Checks if the argument is a function." + + try - - "Checks if the argument is a macro." + + load - - "Checks if the argument is a built-in function." + + import - - "Applies the funciton to the sequence, as in calls the function with\nithe se" + + copy - - "Returns the last pair in the sqeuence." + + error - - "Returns the (first) of the last (pair) of the given sequence." + + symbol->keyword - - "Extends a list with the given element, by putting it in\nthe (rest) of the l" + + string->symbol - - "Appends an element to a sequence, by extendeing the list\nwith (pair elem ni" + + symbol->string - - "test" + + concat-strings - - "Returns the length of the given sequence." + + if - - "Adds one to the argument." + + = - - "Subtracts one from the argument." + + > - - "Returns a sequence of numbers starting with the number defined\nby the key '" + + >= - - Lists, Pairs: + + < - - 30 + + <= - - 420 + + + - - define-syntax + + - - - when + + * - - condition + + / - - : + + ** - - rest + + % - - body + + assert - - - - - - "Doc String for 'when" + + define - - quasiquote + + mutate - + if - - unquote + + quote - - condition + + quasiquote - - - - unquote + + and - - pair + + or - - prog + + not - - body + + while - - - - - - - nil + + let - - - - - - - - - - - - when + + lambda - - condition + + special-lambda - - : + + eval - - rest + + prog - - body + + list - - - - - - "Doc String for 'when" + + pair - - quasiquote + + first - - if + + rest - - unquote + + set-type - - condition + + delete-type - - - - unquote + + type - - pair + + info - - prog + + show - - body + + print - - - - - - - nil + + read - - - - - - - - - - - prog + + exit - - quasiquote + + break - - if + + memstat - - unquote + + try - - condition + + load - - - - unquote + + import - - pair + + copy - - prog + + error - - body + + symbol->keyword - - - - - - - nil + + string->symbol - - - - - - - - - - define-syntax + + symbol->string - - unless + + concat-strings - - condition + + and - - : + + = - - rest + + > - - body + + >= - - - - - - quasiquote + + < - - if + + <= - - unquote + + + - - condition + + - - - - - nil + + * - - unquote + + / - - pair + + ** - - prog + + % - - body + + assert - - - - - - - - - - - - - - - - prog + + define - - quasiquote + + mutate - + if - - unquote + + quote - - condition + + quasiquote - - - - nil + + and - - unquote + + or - - pair + + not - - prog + + while - - body + + let - - - - - - - - - - - - - - - define-syntax + + lambda - - cond + + special-lambda - - : + + eval - - rest + + prog + + + list - - clauses + + pair - - - - - define + + first - - rec + + rest - - clauses + + set-type - - - - if + + delete-type - - = + + type - - nil + + info - - clauses + + show - - - - - nil + + print - - if + + read - - = + + exit - - first + + break - - first + + memstat - - clauses + + try - - - - - - quote + + load - - else + + import - - - - - - - prog + + copy - - if + + error - - not + + symbol->keyword - - = + + string->symbol - - () + + symbol->string - - rest + + concat-strings - - clauses + + and - - - - - - - - - error + + = - - "There are additional" + + > - - - - pair + + >= - - quote + + < - - prog + + <= - - - - rest + + + - - first + + - - - clauses + + * - - - - - - - - - - - - - - - list + + / - - quote + + ** - - if + + % - - - - first + + assert - - first + + define - - clauses + + mutate - - - - - - pair + + if - + quote - - prog + + quasiquote - - - - rest + + and - - first + + or - - clauses + + not - - - - - - - - - rec + + while - - rest + + let - - clauses + + lambda - - - - - - - - - - - - - - - - - - - - - - rec + + special-lambda - - clauses + + eval - - - - - - - + prog - - define + + list - - rec + + pair - - clauses + + first - - - - if + + rest - - = + + set-type - - nil + + delete-type - - clauses + + type - - - - - nil + + info - - if + + show + + + print - + + read + + + exit + + + break + + + memstat + + + try + + + load + + + import + + + copy + + + error + + + symbol->keyword + + + string->symbol + + + symbol->string + + + concat-strings + + + or + + + nil + + = - - first + + > - - first + + >= - - clauses + + < - - - - - + + <= + + + + + + + - + + + * + + + / + + + ** + + + % + + + assert + + + define + + + mutate + + + if + + quote - - else + + quasiquote - - - - - - + + and + + + or + + + not + + + while + + + let + + + lambda + + + special-lambda + + + eval + + prog - + + list + + + pair + + + first + + + rest + + + set-type + + + delete-type + + + type + + + info + + + show + + + print + + + read + + + exit + + + break + + + memstat + + + try + + + load + + + import + + + copy + + + error + + + symbol->keyword + + + string->symbol + + + symbol->string + + + concat-strings + + + or + + + = + + + > + + + >= + + + < + + + <= + + + + + + + - + + + * + + + / + + + ** + + + % + + + assert + + + define + + + mutate + + if - + + quote + + + quasiquote + + + and + + + or + + not - - = + + while - - () + + let + + + lambda + + + special-lambda + + + eval + + + prog - + + list + + + pair + + + first + + rest - - clauses + + set-type - - - - - - - - + + delete-type + + + type + + + info + + + show + + + print + + + read + + + exit + + + break + + + memstat + + + try + + + load + + + import + + + copy + + error - - "There are additional" + + symbol->keyword - - - - pair + + string->symbol + + + symbol->string + + + concat-strings + + + not + + + = + + + > + + + >= + + + < + + + <= + + + + + + + - + + + * + + + / + + + ** - + + % + + + assert + + + define + + + mutate + + + if + + quote - + + quasiquote + + + and + + + or + + + not + + + while + + + let + + + lambda + + + special-lambda + + + eval + + prog - - - - rest + + list + + + pair - + first - - clauses + + rest - - - - - - - - - - - - - - - list + + set-type - - quote + + delete-type + + + type + + + info + + + show + + + print + + + read + + + exit + + + break + + + memstat + + + try + + + load + + + import + + + copy + + + error + + + symbol->keyword + + + string->symbol + + + symbol->string + + + concat-strings - + + not + + + = + + + > + + + >= + + + < + + + <= + + + + + + + - + + + * + + + / + + + ** + + + % + + + assert + + + define + + + mutate + + if - - - - first + + quote - - first + + quasiquote + + + and + + + or + + + not + + + while + + + let + + + lambda + + + special-lambda + + + eval + + + prog - - clauses + + list - - - - - + pair - - quote - - - prog + + first - - - + rest - - first + + set-type - - clauses + + delete-type - - - - - - - - - rec + + type - - rest + + info - - clauses + + show - - - - - - - - - - - - - - - - - - - - - - rec + + print - - clauses + + read - - - - - - - define + + exit - - nil? + + break - - x + + memstat - - - - "Checks if the argume" + + try - - = + + load - - x + + import - - nil + + copy - - - - - - - - - define + + error - - number? + + symbol->keyword - - x + + string->symbol - - - - "Checks if the argume" + + symbol->string + + + concat-strings - + = - - type + + > - - x + + >= - - - - : + + < - - number + + <= - - - - - - - - - define + + + - - symbol? + + - - - x + + * - - - - "Checks if the argume" + + / - - = + + ** - - type + + % - - x + + assert - - - - : + + define - - symbol + + mutate - - - - - - - - - define + + if - - keyword? + + quote - - x + + quasiquote - - - - "Checks if the argume" + + and - - = + + or - - type + + not - - x + + while - - - - : + + let - - keyword + + lambda - - - - - - - - - define + + special-lambda - - pair? + + eval - - x + + prog - - - - "Checks if the argume" + + list - - = + + pair - - type + + first - - x + + rest - - - - : + + set-type - - pair + + delete-type - - - - - - - - - define + + type - - string? + + info - - x + + show - - - - "Checks if the argume" + + print - - = + + read - - type + + exit - - x + + break - - - - : + + memstat - - string + + try - - - - - - - - - define + + load - - lambda? + + import - - x + + copy - - - - "Checks if the argume" + + error - - = + + symbol->keyword - - type + + string->symbol - - x + + symbol->string - - - - : + + concat-strings - - dynamic-function + + prog - - - - - - - - + define - - special-lambda? + + a - - x + + type - - - - "Checks if the argume" + + a - - = + + prog + + + set-type + + + a - + type - - x + + a - - - - : + + prog - - dynamic-macro + + set-type - - - - - - - - - define + + a - - built-n-function? + + type - - x + + a - - - - "Checks if the argume" + + Keywords: - - = + + 6 - - type + + : - - x + + key1 - - - + : - - built-in-function + + key:2 - - - - - - - - - define + + : - - apply + + haha - - fun + + : - - seq + + number - - - - - "Applies the funciton" + + : - - eval + + my-type - - pair + + : - - fun + + type-missmatch + + + Numbers: + + + 29 + + + 00123.000000 - - seq + + -0000.012300 - - - - - - - - - - - define + + 00012.000000 - - end + + 00005.000000 - - seq + + 00001.000000 - - - - "Returns the last pai" + + 00001.000000 - - if + + 00002.000000 - - or + + 00003.000000 - - nil? + + 00010.000000 - - seq + + 00004.000000 - - - - not + + 00014.000000 - - pair? + + 00010.000000 - - rest + + 00004.000000 - - seq + + 00006.000000 - - - - - - - - - - - seq + + 00010.000000 - - end + + 00004.000000 - - rest + + 00040.000000 - - seq + + 00020.000000 - - - - - - - - - - - - - - define + + 00004.000000 - - last + + 00005.000000 - - seq + + 00001.000000 - - - - "Returns the (first) " + + 00004.000000 - - first + + 00005.000000 - - end + + 00004.000000 - - seq + + 00005.000000 - - - - - - - - - - define + + 00001.000000 - - extend + + 00004.000000 - - seq + + 00004.000000 - - elem + + 00010.000000 - - - - - "Extends a list with " + + Strings: - - if + + 7 - - pair? + + "asd" - - seq + + "okay" - - - - prog + + "asd" - - define + + "asd" - - e + + "asd" - - end + + "asd xD" - - seq + + "wrong tpye" - - - - - - - mutate + + Lists, Pairs: - - e + + 34 - - pair + + 116 - - first + + fun - - e + + + - - - - elem + + 00012.000000 - + - - - - - seq + + + - - - - - - elem + + 00012.000000 - - - + - - - - - + define - - append - - - seq + + fun - - elem + + lambda - - - - - "Appends an element t" + + x - - extend + + + + - - seq + + 00005.000000 - - pair + + * - - elem + + x - - nil + + x - - + - + - + - - define-syntax - - - extend! - - - seq - - - elem - - + - - "test" + + eval - - quasiquote + + 00001.000000 - - mutate + + + + + - - unquote + + 00001.000000 - - seq + + 00002.000000 - + - - extend - - - unquote + + + "okay" - - seq + + eval - - - - unquote + + : - - elem + + haha - - - - - - - + - + - - - - prog + + 00001.000000 - - quasiquote + + 00003.000000 - - mutate + + "okay" - - unquote + + : - - seq + + haha - + + + - - extend + + 00001.000000 - - unquote + + + 00001.000000 - - seq + + 00002.000000 - + - - unquote - - - elem + + : - - - - - - - - - - - - - - define-syntax + + haha - - append! + + + + - - seq + + 00010.000000 - - elem + + 00004.000000 - + - - quasiquote - - - mutate - - - unquote + + 00010.000000 - - seq + + 00004.000000 - + - - append + + - - - unquote + + 00010.000000 - - seq + + 00004.000000 - + + - - unquote + + 00010.000000 - - elem + + 00004.000000 - - - - - - - - - - - + - - - prog + + * - - quasiquote + + 00010.000000 - - mutate + + 00004.000000 - - unquote + + + + + 00010.000000 - - seq + + 00004.000000 - + - - append + + / - - unquote + + 00020.000000 - - seq + + 00004.000000 - + - - unquote + + + 00020.000000 - - elem + + 00004.000000 - - - - - - + - - - - - - - define + + if + + + 00001.000000 - - length + + 00004.000000 - - seq + + 00005.000000 - + - - "Returns the length o" - - + + + if - - nil? + + () - - seq + + 00004.000000 - - - - 00000.000000 + + 00005.000000 - - + + + + + + + and - + 00001.000000 - - length - - - rest + + "asd" - - seq + + 00004.000000 - - - + - - - - - - + + and + + + () + + + "asd" + + + 00004.000000 + + - - define + + or - - increment + + "asd" - - val + + nil - + - - "Adds one to the argu" - - - + + + + or - - val + + () - - 00001.000000 + + () - - + - - - - - define + + not - - decrement + + () + + + + + not - - val + + "asd xD" - + - - "Subtracts one from t" + + prog - - - + + define - - val + + a - - 00001.000000 + + 00010.000000 - + - + + type + + + a + + + - - define + + 00010.000000 - - range - - + : - - keys + + number - - from + + + + 00010.000000 - - : + + + prog - - defaults-to + + set-type - - 00000.000000 + + a - - to + + : - - - - + + my-type + + - - "Returns a sequence o" + + type - - () + + a - + + - - when + + : - - < + + my-type - - from + + : - - to + + my-type - + - - - pair + + 00010.000000 - - from + + : - - range + + my-type - - : + + + + 00010.000000 - - from + + + prog - - + + + set-type - - 00001.000000 + + a - - from + + "wrong tpye" - + - - : - - - to + + type - - to + + a - + + - - - - - - + + () + + + + 00010.000000 + + + "wrong tpye" + + diff --git a/src/env.cpp b/src/env.cpp index fbcc9a6..e927f1c 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -55,6 +55,7 @@ proc lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* { String* identifier = node->value.identifier; create_symbol_undefined_error("The symbol '%s' is not defined.", &identifier->data); + print_environment(env); return nullptr; } diff --git a/src/eval.cpp b/src/eval.cpp index 70b4554..2e52ec9 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -432,23 +432,18 @@ proc interprete_file (char* file_name) -> Lisp_Object* { Environment* user_env = Memory::create_child_environment(root_env); Parser::environment_for_macros = user_env; - char* file_content; - try file_content = read_entire_file(file_name); + // char* file_content; + // try file_content = read_entire_file(file_name); - built_in_load(Memory::create_string("pre.slime"), root_env); - - Lisp_Object_Array_List* program; - program = Parser::parse_program(Memory::create_string(file_name), file_content); + built_in_import(Memory::create_string("pre.slime"), user_env); - Lisp_Object* result = Memory::nil; - for (int i = 0; i < program->next_index; ++i) { - result = eval_expr(program->data[i], user_env); + Lisp_Object* result; + result = built_in_load(Memory::create_string(file_name), user_env); - if (Globals::error) { - log_error(); - delete_error(); - return nullptr; - } + if (Globals::error) { + log_error(); + delete_error(); + return nullptr; } return result; diff --git a/src/memory.cpp b/src/memory.cpp index 8353c64..ae0d2c9 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -1,13 +1,21 @@ namespace Memory { // ------------------ - // lisp_object + // lisp_objects // ------------------ int object_memory_size; Int_Array_List* free_spots_in_object_memory; Lisp_Object* object_memory; int next_index_in_object_memory = 0; + // ------------------ + // environments + // ------------------ + int environment_memory_size; + Int_Array_List* free_spots_in_environment_memory; + Lisp_Object* environment_memory; + int next_index_in_environment_memory = 0; + // ------------------ // strings // ------------------ @@ -19,7 +27,6 @@ namespace Memory { String* string_memory; String* next_free_spot_in_string_memory; - // ------------------ // immutables // ------------------ @@ -168,8 +175,7 @@ namespace Memory { next_index_in_object_memory = 2; // because t and nil are always there next_free_spot_in_string_memory = string_memory; - Globals::root_environment->next_index = 0; - Globals::root_environment->parents->next_index = 0; + Globals::root_environment = create_built_ins_environment(); } proc create_lisp_object_number(double number) -> Lisp_Object* { diff --git a/src/testing.cpp b/src/testing.cpp index effa66e..5532d59 100644 --- a/src/testing.cpp +++ b/src/testing.cpp @@ -570,7 +570,7 @@ proc test_file(const char* file) -> testresult { Environment* user_env = Memory::create_child_environment(root_env); assert_no_error(); - Parser::environment_for_macros = root_env; + Parser::environment_for_macros = user_env; built_in_import(Memory::create_string("pre.slime"), user_env); assert_no_error(); diff --git a/src/visualization.cpp b/src/visualization.cpp index 01ac339..ec57b31 100644 --- a/src/visualization.cpp +++ b/src/visualization.cpp @@ -414,7 +414,7 @@ proc visualize_lisp_machine() -> void { } remove_doubles_from_lisp_object_array_list(pairs_to_filter); - fprintf(stderr, "removing %d pairs\n", pairs_to_filter->next_index); + // 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) {