From 5f90f2877f7f21562946653e9f785863e42c4378 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Thu, 19 Sep 2019 13:47:34 +0200 Subject: [PATCH] fixed into for cFunction args --- build.sh | 0 src/built_ins.cpp | 148 ++++++++++++++++++++++++---------------------- src/main.cpp | 1 - 3 files changed, 76 insertions(+), 73 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/src/built_ins.cpp b/src/built_ins.cpp index 1a49e49..a1d8964 100644 --- a/src/built_ins.cpp +++ b/src/built_ins.cpp @@ -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,79 +824,82 @@ proc load_built_ins_into_environment() -> void { print(n); Lisp_Object* type; + Lisp_Object* val; in_caller_env { try type = eval_expr(Memory::create_list(Memory::get_or_create_lisp_object_symbol("type"), n)); + try val = eval_expr(n); } - if (type) { - Lisp_Object* val; - in_caller_env { - try Lisp_Object* 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", + (val->docstring) + ? Memory::get_c_str(val->docstring) + : "No docs avaliable"); + + if (Memory::get_type(val) == Lisp_Object_Type::Function || + Memory::get_type(val) == Lisp_Object_Type::CFunction) + { + Arguments* args; + if (Memory::get_type(val) == Lisp_Object_Type::Function) + args = &val->value.function.args; + else + args = &val->value.cFunction->args; + + printf("Arguments:\n==========\n"); + printf("Postitional: {"); + if (args->positional.symbols.next_index != 0) { + printf("%s", + 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(args->positional.symbols.data[i]->value.symbol.identifier)); + } } - printf(" is of type "); - print(type); - printf("\nand is printed as: "); - print(val); - printf("\n\ndocs: \n %s\n", - (val->docstring) - ? 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"))) - { - 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"); - - printf("Arguments:\n==========\n"); - printf("Postitional: {"); - if (fun->value.function.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) { - printf(", %s", - Memory::get_c_str(fun->value.function.args.positional.symbols.data[i]->value.symbol.identifier)); - } + printf("}\n"); + printf("Keyword: {"); + if (args->keyword.values.next_index != 0) { + printf("%s", + Memory::get_c_str(args->keyword.keywords.data[0]->value.symbol.identifier)); + if (args->keyword.values.data[0]) { + printf(" ("); + print(args->keyword.values.data[0], true); + printf(")"); } - printf("}\n"); - printf("Keyword: {"); - if (fun->value.function.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]) { + for (int i = 1; i < args->keyword.values.next_index; ++i) { + printf(", %s", + 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[0]); + print(args->keyword.values.data[i], true); printf(")"); } - for (int i = 1; i < fun->value.function.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]) { - printf(" ("); - print(fun->value.function.args.keyword.values.data[i]); - printf(")"); - } - } } - printf("}\n"); - printf("Rest: {"); - if (fun->value.function.args.rest) - printf("%s", - Memory::get_c_str(fun->value.function.args.rest)); - printf("}\n"); - } - } else { - printf(" is not defined\n"); - delete_error(); + printf("}\n"); + printf("Rest: {"); + if (args->rest) + printf("%s", + Memory::get_c_str(args->rest->value.symbol.identifier)); + printf("}\n"); + } + // } + // // 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; }; diff --git a/src/main.cpp b/src/main.cpp index 51cc2b6..7de470a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();