coly_lisp_object now dows not create new nil and t values anymore

Fixed an error where a nil value could not be used as the default
value as a keyword argument since coly_lisp_object would be invoked
before assigning nil as the default argument, producing a separate nil
value, which then fails the nil tests becase it lives in a different
location as Memory::nil.
This commit is contained in:
Felix Brendel
2019-05-17 02:11:20 +02:00
parent 03a2c81aa5
commit 912ec19373
6 changed files with 63 additions and 15 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, S
delete_error();
debug_break();
visualize_lisp_machine();
// visualize_lisp_machine();
using Globals::error;
error = new(Error);
+8 -4
View File
@@ -24,11 +24,11 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) ->
if (arguments == Memory::nil)
goto checks;
// keyword arguments: use all given ones and keep track of the
// added ones (array list), if end of parameters in encountered or
// something that is not a keyword is encountered or a keyword
// that is not recognized is encoutered, jump out of the loop.
while (Memory::get_type(arguments->value.pair.first) == Lisp_Object_Type::Keyword) {
// check if this one is even an accepted keyword
bool accepted = false;
@@ -80,8 +80,9 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) ->
}
// if not set it and then add it to the array list
try sym = Memory::get_or_create_lisp_object_symbol(arguments->value.pair.first->value.symbol.identifier),
define_symbol(sym, arguments->value.pair.rest->value.pair.first, new_env);
try sym = Memory::get_or_create_lisp_object_symbol(arguments->value.pair.first->value.symbol.identifier);
// NOTE(Felix): It seems we do not need to evaluate the argument here...
try define_symbol(sym, arguments->value.pair.rest->value.pair.first, new_env);
append_to_array_list(read_in_keywords, arguments->value.pair.first->value.symbol.identifier);
@@ -257,9 +258,11 @@ proc parse_argument_list(Lisp_Object* arguments, Function* function) -> void {
// would be an error
next = next->value.pair.rest;
if (Memory::get_type(next) == Lisp_Object_Type::Pair) {
Lisp_Object* ret;
try_void ret = eval_expr(next->value.pair.first, function->parent_environment);
append_to_keyword_argument_list(function->keyword_arguments,
arguments->value.pair.first->value.symbol.identifier,
next->value.pair.first);
ret);
arguments = next->value.pair.rest;
} else {
create_parsing_error("Expecting a value after 'defaults-to'");
@@ -426,6 +429,7 @@ proc eval_expr(Lisp_Object* node, Environment* env) -> Lisp_Object* {
proc is_truthy(Lisp_Object* expression, Environment* env) -> bool {
Lisp_Object* result;
try result = eval_expr(expression, env);
return result != Memory::nil;
}
+3
View File
@@ -283,6 +283,9 @@ namespace Memory {
}
proc copy_lisp_object(Lisp_Object* n) -> Lisp_Object* {
if (n == nil || n == t)
return n;
Lisp_Object* target;
try target = create_lisp_object();
*target = *n;
+1
View File
@@ -635,6 +635,7 @@ proc run_all_tests() -> bool {
printf("\n-- Test Files --\n");
invoke_test_script("evaluation_of_default_args");
invoke_test_script("lexical_scope");
invoke_test_script("class_macro");
invoke_test_script("sicp");