removed special-lambdas to make evaluatino of arfgs more regular
This commit is contained in:
+16
-20
@@ -779,31 +779,27 @@ proc load_built_ins_into_environment() -> void {
|
||||
fun->value.function.body = maybe_wrap_body_in_begin(body);
|
||||
return fun;
|
||||
};
|
||||
define_special((special-lambda args . body), "TODO") {
|
||||
fetch(args, body);
|
||||
// define_special((special-lambda args . body), "TODO") {
|
||||
// fetch(args, body);
|
||||
|
||||
Lisp_Object* fun;
|
||||
try fun = Memory::create_lisp_object();
|
||||
Memory::set_type(fun, Lisp_Object_Type::Function);
|
||||
fun->value.function.type = Function_Type::Special_Lambda;
|
||||
// Lisp_Object* fun;
|
||||
// try fun = Memory::create_lisp_object();
|
||||
// Memory::set_type(fun, Lisp_Object_Type::Function);
|
||||
// fun->value.function.type = Function_Type::Special_Lambda;
|
||||
|
||||
in_caller_env {
|
||||
fun->value.function.parent_environment = get_current_environment();
|
||||
}
|
||||
// in_caller_env {
|
||||
// fun->value.function.parent_environment = get_current_environment();
|
||||
// }
|
||||
|
||||
try create_arguments_from_lambda_list_and_inject(args, fun);
|
||||
fun->value.function.body = maybe_wrap_body_in_begin(body);
|
||||
return fun;
|
||||
};
|
||||
// try create_arguments_from_lambda_list_and_inject(args, fun);
|
||||
// fun->value.function.body = maybe_wrap_body_in_begin(body);
|
||||
// return fun;
|
||||
// };
|
||||
define((apply fun args), "TODO") {
|
||||
fetch(fun, args);
|
||||
Lisp_Object* result;
|
||||
|
||||
// try assert_type(args, Lisp_Object_Type::Pair);
|
||||
// HACK(Felix): this is probably a really nasty hack:
|
||||
fluid_let (fun->value.function.type, Function_Type::Special_Lambda) {
|
||||
try result = apply_arguments_to_function(args, fun);
|
||||
}
|
||||
try result = apply_arguments_to_function(args, fun, /*eval_args=*/false);
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -907,8 +903,8 @@ proc load_built_ins_into_environment() -> void {
|
||||
Function* fun = &n->value.function;
|
||||
if (fun->type == Function_Type::Lambda)
|
||||
return Memory::get_or_create_lisp_object_keyword("lambda");
|
||||
else if (fun->type == Function_Type::Special_Lambda)
|
||||
return Memory::get_or_create_lisp_object_keyword("special-lambda");
|
||||
// else if (fun->type == Function_Type::Special_Lambda)
|
||||
// return Memory::get_or_create_lisp_object_keyword("special-lambda");
|
||||
else if (fun->type == Function_Type::Macro)
|
||||
return Memory::get_or_create_lisp_object_keyword("macro");
|
||||
else return Memory::get_or_create_lisp_object_keyword("unknown");
|
||||
|
||||
+15
-13
@@ -1,6 +1,7 @@
|
||||
proc create_extended_environment_for_function_application(
|
||||
Lisp_Object* unevaluated_arguments,
|
||||
Lisp_Object* function) -> Environment*
|
||||
Lisp_Object* function,
|
||||
bool should_evaluate) -> Environment*
|
||||
{
|
||||
profile_this;
|
||||
bool is_c_function = Memory::get_type(function) == Lisp_Object_Type::CFunction;
|
||||
@@ -15,17 +16,12 @@ proc create_extended_environment_for_function_application(
|
||||
if (is_c_function) {
|
||||
new_env = Memory::create_child_environment(get_root_environment());
|
||||
arg_spec = &function->value.cFunction->args;
|
||||
// if it is not a special form, evaluate the arguments
|
||||
if (!function->value.cFunction->is_special_form) {
|
||||
try arguments = eval_arguments(arguments);
|
||||
}
|
||||
} else {
|
||||
new_env = Memory::create_child_environment(function->value.function.parent_environment);
|
||||
arg_spec = &function->value.function.args;
|
||||
// if it is a lambda
|
||||
if (function->value.function.type == Function_Type::Lambda) {
|
||||
try arguments = eval_arguments(arguments);
|
||||
}
|
||||
}
|
||||
if (should_evaluate) {
|
||||
try arguments = eval_arguments(arguments);
|
||||
}
|
||||
|
||||
// NOTE(Felix): Even though we will return the environment at the
|
||||
@@ -230,12 +226,12 @@ proc create_extended_environment_for_function_application(
|
||||
return new_env;
|
||||
}
|
||||
|
||||
proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function) -> Lisp_Object* {
|
||||
proc apply_arguments_to_function(Lisp_Object* arguments, Lisp_Object* function, bool should_evaluate_args) -> Lisp_Object* {
|
||||
profile_this;
|
||||
Environment* new_env;
|
||||
Lisp_Object* result;
|
||||
|
||||
try new_env = create_extended_environment_for_function_application(arguments, function);
|
||||
try new_env = create_extended_environment_for_function_application(arguments, function, should_evaluate_args);
|
||||
push_environment(new_env);
|
||||
defer {
|
||||
pop_environment();
|
||||
@@ -435,7 +431,10 @@ proc eval_expr(Lisp_Object* node) -> Lisp_Object* {
|
||||
// check for c function
|
||||
if (Memory::get_type(lispOperator) == Lisp_Object_Type::CFunction) {
|
||||
Lisp_Object* result;
|
||||
try result = apply_arguments_to_function(arguments, lispOperator);
|
||||
try result = apply_arguments_to_function(
|
||||
arguments,
|
||||
lispOperator,
|
||||
!lispOperator->value.cFunction->is_special_form);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -446,7 +445,10 @@ proc eval_expr(Lisp_Object* node) -> Lisp_Object* {
|
||||
// we do not need.
|
||||
|
||||
Lisp_Object* result;
|
||||
try result = apply_arguments_to_function(arguments, lispOperator);
|
||||
try result = apply_arguments_to_function(
|
||||
arguments,
|
||||
lispOperator,
|
||||
lispOperator->value.function.type == Function_Type::Lambda);
|
||||
|
||||
// NOTE(Felix): The parser does not understnad (import ..)
|
||||
// so it cannot expand imported macros at read time
|
||||
|
||||
+2
-2
@@ -313,8 +313,8 @@ proc print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout) -> v
|
||||
}
|
||||
if (node->value.function.type == Function_Type::Lambda)
|
||||
fputs("[lambda]", file);
|
||||
else if (node->value.function.type == Function_Type::Special_Lambda)
|
||||
fputs("[special-lambda]", file);
|
||||
// else if (node->value.function.type == Function_Type::Special_Lambda)
|
||||
// fputs("[special-lambda]", file);
|
||||
else if (node->value.function.type == Function_Type::Macro)
|
||||
fputs("[macro]", file);
|
||||
else
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ enum class Lisp_Object_Flags : u64
|
||||
|
||||
enum struct Function_Type {
|
||||
Lambda,
|
||||
Special_Lambda,
|
||||
// Special_Lambda,
|
||||
Macro
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user