fixed into for cFunction args
This commit is contained in:
+49
-45
@@ -106,7 +106,8 @@ proc load_built_ins_into_environment() -> void {
|
||||
|
||||
#define fetch1(var) \
|
||||
static Lisp_Object* var##_symbol = Memory::get_or_create_lisp_object_symbol(#var); \
|
||||
Lisp_Object* var = lookup_symbol(var##_symbol, get_current_environment())
|
||||
Lisp_Object* var = lookup_symbol(var##_symbol, get_current_environment()); \
|
||||
if (Globals::error) printf("in %s:%d\n", __FILE__, __LINE__)
|
||||
|
||||
#define fetch2(var1, var2) fetch1(var1); fetch1(var2)
|
||||
#define fetch3(var1, var2, var3) fetch2(var1, var2); fetch1(var3)
|
||||
@@ -320,19 +321,19 @@ proc load_built_ins_into_environment() -> void {
|
||||
return nullptr;
|
||||
};
|
||||
define_special((define-syntax form (:doc "") . body), "TODO") {
|
||||
// fetch(form, doc, body);
|
||||
fetch(form, doc, body);
|
||||
|
||||
static Lisp_Object *form_symbol = Memory::get_or_create_lisp_object_symbol("form");
|
||||
static Lisp_Object *doc_symbol = Memory::get_or_create_lisp_object_symbol("doc");
|
||||
static Lisp_Object *body_symbol = Memory::get_or_create_lisp_object_symbol("body");
|
||||
// static Lisp_Object *form_symbol = Memory::get_or_create_lisp_object_symbol("form");
|
||||
// static Lisp_Object *doc_symbol = Memory::get_or_create_lisp_object_symbol("doc");
|
||||
// static Lisp_Object *body_symbol = Memory::get_or_create_lisp_object_symbol("body");
|
||||
|
||||
printf("\n\nin define-syntax:: envi stack depth: %d\n",
|
||||
Globals::Current_Execution::envi_stack.next_index);
|
||||
print_environment(get_current_environment());
|
||||
// printf("\n\nin define-syntax:: envi stack depth: %d\n",
|
||||
// Globals::Current_Execution::envi_stack.next_index);
|
||||
// print_environment(get_current_environment());
|
||||
|
||||
Lisp_Object *form = lookup_symbol(form_symbol, get_current_environment());
|
||||
Lisp_Object *doc = lookup_symbol(doc_symbol, get_current_environment());
|
||||
Lisp_Object *body = lookup_symbol(body_symbol, get_current_environment());
|
||||
// Lisp_Object *form = lookup_symbol(form_symbol, get_current_environment());
|
||||
// Lisp_Object *doc = lookup_symbol(doc_symbol, get_current_environment());
|
||||
// Lisp_Object *body = lookup_symbol(body_symbol, get_current_environment());
|
||||
|
||||
assert_type(doc, Lisp_Object_Type::String);
|
||||
// if no doc string, we dont have to store it
|
||||
@@ -823,17 +824,15 @@ proc load_built_ins_into_environment() -> void {
|
||||
print(n);
|
||||
|
||||
Lisp_Object* type;
|
||||
in_caller_env {
|
||||
try type = eval_expr(Memory::create_list(Memory::get_or_create_lisp_object_symbol("type"), n));
|
||||
}
|
||||
|
||||
if (type) {
|
||||
Lisp_Object* val;
|
||||
in_caller_env {
|
||||
try Lisp_Object* val = eval_expr(n);
|
||||
try type = eval_expr(Memory::create_list(Memory::get_or_create_lisp_object_symbol("type"), n));
|
||||
try val = eval_expr(n);
|
||||
}
|
||||
|
||||
printf(" is of type ");
|
||||
print(type);
|
||||
printf(" (internal: %s)", Lisp_Object_Type_to_string(Memory::get_type(val)));
|
||||
printf("\nand is printed as: ");
|
||||
print(val);
|
||||
printf("\n\ndocs: \n %s\n",
|
||||
@@ -841,61 +840,66 @@ proc load_built_ins_into_environment() -> void {
|
||||
? Memory::get_c_str(val->docstring)
|
||||
: "No docs avaliable");
|
||||
|
||||
// TODO(Felix): Maybe don't compare strings here?? Wtf
|
||||
if (Memory::get_type(type) == Lisp_Object_Type::Keyword &&
|
||||
(string_equal(type->value.symbol.identifier, "lambda") ||
|
||||
string_equal(type->value.symbol.identifier, "special-lambda") ||
|
||||
string_equal(type->value.symbol.identifier, "macro")))
|
||||
if (Memory::get_type(val) == Lisp_Object_Type::Function ||
|
||||
Memory::get_type(val) == Lisp_Object_Type::CFunction)
|
||||
{
|
||||
Lisp_Object* fun = eval_expr(n);
|
||||
|
||||
if (fun->docstring)
|
||||
printf("Docstring:\n==========\n%s\n\n", Memory::get_c_str(fun->docstring));
|
||||
Arguments* args;
|
||||
if (Memory::get_type(val) == Lisp_Object_Type::Function)
|
||||
args = &val->value.function.args;
|
||||
else
|
||||
printf("No docstring avaliable\n");
|
||||
args = &val->value.cFunction->args;
|
||||
|
||||
printf("Arguments:\n==========\n");
|
||||
printf("Postitional: {");
|
||||
if (fun->value.function.args.positional.symbols.next_index != 0) {
|
||||
if (args->positional.symbols.next_index != 0) {
|
||||
printf("%s",
|
||||
Memory::get_c_str(fun->value.function.args.positional.symbols.data[0]->value.symbol.identifier));
|
||||
for (int i = 1; i < fun->value.function.args.positional.symbols.next_index; ++i) {
|
||||
Memory::get_c_str(args->positional.symbols.data[0]->value.symbol.identifier));
|
||||
for (int i = 1; i < args->positional.symbols.next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(fun->value.function.args.positional.symbols.data[i]->value.symbol.identifier));
|
||||
Memory::get_c_str(args->positional.symbols.data[i]->value.symbol.identifier));
|
||||
}
|
||||
}
|
||||
printf("}\n");
|
||||
printf("Keyword: {");
|
||||
if (fun->value.function.args.keyword.values.next_index != 0) {
|
||||
if (args->keyword.values.next_index != 0) {
|
||||
printf("%s",
|
||||
Memory::get_c_str(fun->value.function.args.keyword.keywords.data[0]->value.symbol.identifier));
|
||||
if (fun->value.function.args.keyword.values.data[0]) {
|
||||
Memory::get_c_str(args->keyword.keywords.data[0]->value.symbol.identifier));
|
||||
if (args->keyword.values.data[0]) {
|
||||
printf(" (");
|
||||
print(fun->value.function.args.keyword.values.data[0]);
|
||||
print(args->keyword.values.data[0], true);
|
||||
printf(")");
|
||||
}
|
||||
for (int i = 1; i < fun->value.function.args.keyword.values.next_index; ++i) {
|
||||
for (int i = 1; i < args->keyword.values.next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(fun->value.function.args.keyword.keywords.data[i]->value.symbol.identifier));
|
||||
if (fun->value.function.args.keyword.values.data[i]) {
|
||||
Memory::get_c_str(args->keyword.keywords.data[i]->value.symbol.identifier));
|
||||
if (args->keyword.values.data[i]) {
|
||||
printf(" (");
|
||||
print(fun->value.function.args.keyword.values.data[i]);
|
||||
print(args->keyword.values.data[i], true);
|
||||
printf(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("}\n");
|
||||
printf("Rest: {");
|
||||
if (fun->value.function.args.rest)
|
||||
if (args->rest)
|
||||
printf("%s",
|
||||
Memory::get_c_str(fun->value.function.args.rest));
|
||||
Memory::get_c_str(args->rest->value.symbol.identifier));
|
||||
printf("}\n");
|
||||
|
||||
}
|
||||
} else {
|
||||
printf(" is not defined\n");
|
||||
delete_error();
|
||||
}
|
||||
// }
|
||||
// // TODO(Felix): Maybe don't compare strings here?? Wtf
|
||||
// if (Memory::get_type(type) == Lisp_Object_Type::Keyword &&
|
||||
// (string_equal(type->value.symbol.identifier, "lambda") ||
|
||||
// string_equal(type->value.symbol.identifier, "special-lambda") ||
|
||||
// string_equal(type->value.symbol.identifier, "macro")))
|
||||
// {
|
||||
// Lisp_Object* fun = eval_expr(n);
|
||||
|
||||
// if (fun->docstring)
|
||||
// printf("Docstring:\n==========\n%s\n\n", Memory::get_c_str(fun->docstring));
|
||||
// else
|
||||
// printf("No docstring avaliable\n");
|
||||
|
||||
return Memory::nil;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "slime.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc > 1) {
|
||||
if (Slime::string_equal(argv[1], "--run-tests")) {
|
||||
int res = Slime::run_all_tests();
|
||||
|
||||
Reference in New Issue
Block a user