From c0b900cdd82e1bdfec5ef163d6d95c8eb5bfd262 Mon Sep 17 00:00:00 2001 From: hrzlgnm Date: Sun, 15 Dec 2024 23:59:31 +0100 Subject: [PATCH] feat: builtins using builtin_object for run_file (#113) --- examples/fibonacci-recursive.mk | 13 +++++++++++++ source/main.cpp | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/fibonacci-recursive.mk diff --git a/examples/fibonacci-recursive.mk b/examples/fibonacci-recursive.mk new file mode 100644 index 0000000..02c9ead --- /dev/null +++ b/examples/fibonacci-recursive.mk @@ -0,0 +1,13 @@ +let fibonacci = fn(x) { + if (x == 0) { + 0 + } else { + if (x == 1) { + return 1; + } else { + fibonacci(x - 1) + fibonacci(x - 2); + } + } +}; + +puts(fibonacci(30)); diff --git a/source/main.cpp b/source/main.cpp index 0eb0eb0..a63b553 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -182,7 +182,7 @@ auto run_file(const command_line_args& opts) -> int } else { auto* global_env = make(); for (const auto& builtin : builtin_function_expression::builtins) { - global_env->set(builtin->name, make(builtin, nullptr)); + global_env->set(builtin->name, make(builtin)); } const auto* result = prgrm->eval(global_env); if (!result->is(object::object_type::null)) {