Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jank-lang/jank
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Dec 12, 2024
2 parents bf617e9 + eee125b commit d4c9d3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler+runtime/include/cpp/jank/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C"

jank_object_ptr jank_var_intern(jank_object_ptr ns, jank_object_ptr name);
jank_object_ptr jank_var_bind_root(jank_object_ptr var, jank_object_ptr val);
jank_object_ptr jank_var_set_dynamic(jank_object_ptr var, jank_object_ptr dynamic);

jank_object_ptr jank_keyword_intern(jank_object_ptr ns, jank_object_ptr name);

Expand Down
7 changes: 7 additions & 0 deletions compiler+runtime/src/cpp/jank/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ extern "C"
return erase(var_obj->bind_root(val_obj));
}

jank_object_ptr jank_var_set_dynamic(jank_object_ptr const var, jank_object_ptr const dynamic)
{
auto const var_obj(try_object<runtime::var>(reinterpret_cast<object *>(var)));
auto const dynamic_obj(reinterpret_cast<object *>(dynamic));
return erase(var_obj->set_dynamic(truthy(dynamic_obj)));
}

jank_object_ptr jank_keyword_intern(jank_object_ptr const ns, jank_object_ptr const name)
{
auto const ns_obj(reinterpret_cast<object *>(ns));
Expand Down
15 changes: 15 additions & 0 deletions compiler+runtime/src/cpp/jank/codegen/llvm_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ namespace jank::codegen
ctx->builder->CreateCall(set_meta_fn, { ref, meta });
}

auto const set_dynamic_fn_type(
llvm::FunctionType::get(ctx->builder->getPtrTy(),
{ ctx->builder->getPtrTy(), ctx->builder->getPtrTy() },
false));

auto const set_dynamic_fn(
ctx->module->getOrInsertFunction("jank_var_set_dynamic", set_dynamic_fn_type));

auto const dynamic{ truthy(get(expr.name->meta.unwrap_or(obj::nil::nil_const()),
__rt_ctx->intern_keyword("dynamic").expect_ok())) };

auto const dynamic_global{ gen_global(make_box(dynamic)) };

ctx->builder->CreateCall(set_dynamic_fn, { ref, dynamic_global });

if(expr.position == expression_position::tail)
{
return ctx->builder->CreateRet(ref);
Expand Down

0 comments on commit d4c9d3d

Please sign in to comment.