Skip to content

Commit

Permalink
feat(modules): reload modules in require
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy-33 committed Dec 28, 2024
1 parent 1ed299f commit 808bc0f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 37 deletions.
4 changes: 0 additions & 4 deletions compiler+runtime/include/cpp/jank/runtime/module/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ namespace jank::runtime::module

loader(context &rt_ctx, native_persistent_string_view const &ps);

native_bool is_loaded(native_persistent_string_view const &) const;
void set_loaded(native_persistent_string_view const &);

string_result<find_result> find(native_persistent_string_view const &module, origin const ori);
string_result<void> load(native_persistent_string_view const &module, origin const ori);

Expand All @@ -115,6 +112,5 @@ namespace jank::runtime::module
/* This maps module strings to entries. Module strings are like fully qualified Java
* class names. */
native_unordered_map<native_persistent_string, entry> entries;
native_set<native_persistent_string> loaded;
};
}
13 changes: 0 additions & 13 deletions compiler+runtime/src/cpp/clojure/core_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,6 @@ namespace clojure::core_native
return obj::nil::nil_const();
}

static object_ptr is_module_loaded(object_ptr const path)
{
return make_box(__rt_ctx->module_loader.is_loaded(runtime::to_string(path)));
}

static object_ptr set_module_loaded(object_ptr const path)
{
__rt_ctx->module_loader.set_loaded(runtime::to_string(path));
return obj::nil::nil_const();
}

static object_ptr compile(object_ptr const path)
{
__rt_ctx->compile_module(runtime::to_string(path)).expect_ok();
Expand Down Expand Up @@ -465,8 +454,6 @@ jank_object_ptr jank_load_clojure_core_native()
intern_fn("alias", &core_native::alias);
intern_fn("refer", &core_native::refer);
intern_fn("load-module", &core_native::load_module);
intern_fn("set-module-loaded", &core_native::set_module_loaded);
intern_fn("module-loaded?", &core_native::is_module_loaded);
intern_fn("compile", &core_native::compile);

/* TODO: jank.math? */
Expand Down
3 changes: 2 additions & 1 deletion compiler+runtime/src/cpp/jank/runtime/core/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ namespace jank::runtime
{
return typed_s->contains(key);
}
if constexpr(std::same_as<S, obj::persistent_hash_set>)
if constexpr(std::same_as<S, obj::persistent_hash_set>
|| std::same_as<S, obj::persistent_sorted_set>)
{
return typed_s->contains(key);
}
Expand Down
17 changes: 0 additions & 17 deletions compiler+runtime/src/cpp/jank/runtime/module/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,6 @@ namespace jank::runtime::module
return boost::filesystem::last_write_time(native_transient_string{ source_path });
}

native_bool loader::is_loaded(native_persistent_string_view const &module) const
{
return loaded.contains(module);
}

void loader::set_loaded(native_persistent_string_view const &module)
{
loaded.emplace(module);
}

string_result<loader::find_result>
loader::find(native_persistent_string_view const &module, origin const ori)
{
Expand Down Expand Up @@ -440,11 +430,6 @@ namespace jank::runtime::module

string_result<void> loader::load(native_persistent_string_view const &module, origin const ori)
{
if(loader::is_loaded(module))
{
return ok();
}

auto const &found_module{ loader::find(module, ori) };
if(found_module.is_err())
{
Expand Down Expand Up @@ -477,8 +462,6 @@ namespace jank::runtime::module
return res;
}

loader::set_loaded(module);

return ok();
}

Expand Down
4 changes: 2 additions & 2 deletions compiler+runtime/src/jank/clojure/core.jank
Original file line number Diff line number Diff line change
Expand Up @@ -3817,8 +3817,8 @@

(defn- load-all
"Loads a lib given its name and forces a load of any libs it directly or
indirectly loads. If need-ns, ensures that the associated namespace
exists after loading. If require, records the load so any duplicate loads
indirectly loads. If need-ns?, ensures that the associated namespace
exists after loading. If require?, records the load so any duplicate loads
can be skipped."
[lib need-ns? require?]
(swap! *loaded-libs* #(reduce conj %1 %2)
Expand Down

0 comments on commit 808bc0f

Please sign in to comment.