Skip to content

Commit

Permalink
Catch tests up to the new singleton rt ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed May 5, 2024
1 parent b4e8950 commit 245ed43
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 299 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ if(jank_tests)
test/cpp/jank/read/parse.cpp
test/cpp/jank/analyze/box.cpp
test/cpp/jank/runtime/detail/list_type.cpp
test/cpp/jank/runtime/context.cpp
test/cpp/jank/jit/processor.cpp
)
add_executable(jank::test_exe ALIAS jank_test_exe)
Expand Down
5 changes: 1 addition & 4 deletions include/cpp/jank/read/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ namespace jank::read::parse
processor &p;
};

processor(runtime::context &rt_ctx,
lex::processor::iterator const &b,
lex::processor::iterator const &e);
processor(lex::processor::iterator const &b, lex::processor::iterator const &e);

object_result next();
object_result parse_list();
Expand Down Expand Up @@ -88,7 +86,6 @@ namespace jank::read::parse
static native_bool syntax_quote_is_unquote(runtime::object_ptr form, native_bool splice);

public:
runtime::context &rt_ctx;
lex::processor::iterator token_current, token_end;
option<lex::token_kind> expected_closer;
/* Splicing, in reader conditionals, is not allowed at the top level. When we're parsing
Expand Down
6 changes: 6 additions & 0 deletions include/cpp/jank/runtime/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace jank::jit

namespace jank::runtime
{
/* This is a singleton, as much as I fought it for actual years. Trying to have multiple
* contexts is limited firstly by there being a single, global JIT compilation context
* and process in which global memory exists. Secondly, by the fact that interned keywords
* from one context will not play nicely with others. Thirdly that we want the context
* anywhere and everywhere, without passing it around, so we can do things like intern
* keywords. So this guy is always initialized in main and you can always use it. */
struct context
{
context();
Expand Down
2 changes: 1 addition & 1 deletion include/cpp/jank/runtime/obj/persistent_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace jank::runtime

/* behavior::objectable */
native_bool equal(object const &) const;
native_persistent_string to_string() const;
native_persistent_string const &to_string() const;
void to_string(fmt::memory_buffer &buff) const;
native_hash to_hash() const;

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/analyze/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ namespace jank::analyze
{code_str->data.data() + next_interp + interp_start.size(),
code_str->data.data() + code_str->data.size()}
};
read::parse::processor p_prc{ rt_ctx, l_prc.begin(), l_prc.end() };
read::parse::processor p_prc{ l_prc.begin(), l_prc.end() };
auto parsed_obj(p_prc.next());
if(parsed_obj.is_err())
{
Expand Down
57 changes: 28 additions & 29 deletions src/cpp/jank/read/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace jank::read::parse
{
using runtime::__rt_ctx;

native_bool
processor::object_source_info::operator==(processor::object_source_info const &rhs) const
{
Expand Down Expand Up @@ -60,14 +62,11 @@ namespace jank::read::parse
return *this;
}

processor::processor(runtime::context &rt_ctx,
lex::processor::iterator const &b,
lex::processor::iterator const &e)
: rt_ctx{ rt_ctx }
, token_current{ b }
processor::processor(lex::processor::iterator const &b, lex::processor::iterator const &e)
: token_current{ b }
, token_end{ e }
, splicing_allowed_var{ make_box<runtime::var>(
rt_ctx.intern_ns(make_box<runtime::obj::symbol>("clojure.core")),
__rt_ctx->intern_ns(make_box<runtime::obj::symbol>("clojure.core")),
make_box<runtime::obj::symbol>("*splicing-allowed?*"),
runtime::obj::boolean::false_const())
->set_dynamic(true) }
Expand Down Expand Up @@ -207,11 +206,11 @@ namespace jank::read::parse
auto const prev_expected_closer(expected_closer);
expected_closer = some(lex::token_kind::close_paren);

rt_ctx
.push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
__rt_ctx
->push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
std::make_pair(splicing_allowed_var, runtime::obj::boolean::true_const())))
.expect_ok();
util::scope_exit const finally{ [&]() { rt_ctx.pop_thread_bindings().expect_ok(); } };
util::scope_exit const finally{ [&]() { __rt_ctx->pop_thread_bindings().expect_ok(); } };

runtime::detail::native_transient_vector ret;
for(auto it(begin()); it != end(); ++it)
Expand Down Expand Up @@ -242,11 +241,11 @@ namespace jank::read::parse
auto const prev_expected_closer(expected_closer);
expected_closer = some(lex::token_kind::close_square_bracket);

rt_ctx
.push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
__rt_ctx
->push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
std::make_pair(splicing_allowed_var, runtime::obj::boolean::true_const())))
.expect_ok();
util::scope_exit const finally{ [&]() { rt_ctx.pop_thread_bindings().expect_ok(); } };
util::scope_exit const finally{ [&]() { __rt_ctx->pop_thread_bindings().expect_ok(); } };

runtime::detail::native_transient_vector ret;
for(auto it(begin()); it != end(); ++it)
Expand Down Expand Up @@ -276,11 +275,11 @@ namespace jank::read::parse
auto const prev_expected_closer(expected_closer);
expected_closer = some(lex::token_kind::close_curly_bracket);

rt_ctx
.push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
__rt_ctx
->push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
std::make_pair(splicing_allowed_var, runtime::obj::boolean::true_const())))
.expect_ok();
util::scope_exit const finally{ [&]() { rt_ctx.pop_thread_bindings().expect_ok(); } };
util::scope_exit const finally{ [&]() { __rt_ctx->pop_thread_bindings().expect_ok(); } };

runtime::detail::native_persistent_array_map ret;
for(auto it(begin()); it != end(); ++it)
Expand Down Expand Up @@ -463,11 +462,11 @@ namespace jank::read::parse
auto const prev_expected_closer(expected_closer);
expected_closer = some(lex::token_kind::close_curly_bracket);

rt_ctx
.push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
__rt_ctx
->push_thread_bindings(runtime::obj::persistent_hash_map::create_unique(
std::make_pair(splicing_allowed_var, runtime::obj::boolean::true_const())))
.expect_ok();
util::scope_exit const finally{ [&]() { rt_ctx.pop_thread_bindings().expect_ok(); } };
util::scope_exit const finally{ [&]() { __rt_ctx->pop_thread_bindings().expect_ok(); } };

runtime::detail::native_transient_set ret;
for(auto it(begin()); it != end(); ++it)
Expand Down Expand Up @@ -630,8 +629,8 @@ namespace jank::read::parse
error{ start_token.pos, native_persistent_string{ "#? expects an even number of forms" } });
}

auto const jank_keyword(rt_ctx.intern_keyword("", "jank").expect_ok());
auto const default_keyword(rt_ctx.intern_keyword("", "default").expect_ok());
auto const jank_keyword(__rt_ctx->intern_keyword("", "jank").expect_ok());
auto const default_keyword(__rt_ctx->intern_keyword("", "default").expect_ok());

for(auto it(list->fresh_seq()); it != nullptr;)
{
Expand Down Expand Up @@ -788,7 +787,7 @@ namespace jank::read::parse
string_result<runtime::object_ptr> processor::syntax_quote(runtime::object_ptr const form)
{
/* Specials, such as fn*, let*, try, etc. just get left alone. We can't qualify them more. */
if(rt_ctx.an_prc.is_special(form))
if(__rt_ctx->an_prc.is_special(form))
{
return make_box<runtime::obj::persistent_list>(std::in_place,
make_box<runtime::obj::symbol>("quote"),
Expand All @@ -802,7 +801,7 @@ namespace jank::read::parse
auto sym(runtime::expect_object<runtime::obj::symbol>(form));
if(sym->ns.empty() && sym->name.ends_with('#'))
{
auto const env(rt_ctx.gensym_env_var->deref());
auto const env(__rt_ctx->gensym_env_var->deref());
if(env->type == runtime::object_type::nil)
{
return err("gensym literal is not within a syntax quote");
Expand All @@ -812,16 +811,16 @@ namespace jank::read::parse
if(gensym->type == runtime::object_type::nil)
{
gensym = make_box<runtime::obj::symbol>(runtime::context::unique_symbol(sym->name));
rt_ctx.gensym_env_var->set(runtime::assoc(env, sym, gensym)).expect_ok();
__rt_ctx->gensym_env_var->set(runtime::assoc(env, sym, gensym)).expect_ok();
}
sym = runtime::expect_object<runtime::obj::symbol>(gensym);
}
else if(sym->ns.empty() && sym->name != "&")
{
auto var(rt_ctx.find_var(sym));
auto var(__rt_ctx->find_var(sym));
if(var.is_none())
{
sym = make_box<runtime::obj::symbol>(rt_ctx.current_ns()->name->name, sym->name);
sym = make_box<runtime::obj::symbol>(__rt_ctx->current_ns()->name->name, sym->name);
}
else
{
Expand Down Expand Up @@ -953,9 +952,9 @@ namespace jank::read::parse
++token_current;

runtime::context::binding_scope const scope{
rt_ctx,
*__rt_ctx,
runtime::obj::persistent_hash_map::create_unique(
std::make_pair(rt_ctx.gensym_env_var, runtime::obj::persistent_hash_map::empty()))
std::make_pair(__rt_ctx->gensym_env_var, runtime::obj::persistent_hash_map::empty()))
};

auto const old_quoted(quoted);
Expand Down Expand Up @@ -1053,7 +1052,7 @@ namespace jank::read::parse
/* Normal symbols will have the ns resolved immediately. */
else
{
auto const resolved_ns(rt_ctx.resolve_ns(make_box<runtime::obj::symbol>(ns_portion)));
auto const resolved_ns(__rt_ctx->resolve_ns(make_box<runtime::obj::symbol>(ns_portion)));
if(resolved_ns.is_none())
{
return err(error{ token.pos, fmt::format("unknown namespace: {}", ns_portion) });
Expand Down Expand Up @@ -1144,7 +1143,7 @@ namespace jank::read::parse
name = sv.substr(resolved ? 0 : 1);
}

auto const intern_res(rt_ctx.intern_keyword(ns, name, resolved));
auto const intern_res(__rt_ctx->intern_keyword(ns, name, resolved));
if(intern_res.is_err())
{
return err(intern_res.expect_err());
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/jank/runtime/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace jank::runtime
{
profile::timer timer{ "rt eval_string" };
read::lex::processor l_prc{ code };
read::parse::processor p_prc{ *this, l_prc.begin(), l_prc.end() };
read::parse::processor p_prc{ l_prc.begin(), l_prc.end() };

object_ptr ret{ obj::nil::nil_const() };
native_vector<analyze::expression_ptr> exprs{};
Expand Down Expand Up @@ -225,7 +225,7 @@ namespace jank::runtime
{
profile::timer timer{ "rt analyze_string" };
read::lex::processor l_prc{ code };
read::parse::processor p_prc{ *this, l_prc.begin(), l_prc.end() };
read::parse::processor p_prc{ l_prc.begin(), l_prc.end() };

native_vector<analyze::expression_ptr> ret{};
for(auto const &form : p_prc)
Expand Down
8 changes: 3 additions & 5 deletions src/cpp/jank/runtime/obj/persistent_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ namespace jank::runtime
return data == s->data;
}

native_persistent_string obj::persistent_string::to_string() const
native_persistent_string const &obj::persistent_string::to_string() const
{
fmt::memory_buffer buff;
to_string(buff);
return native_persistent_string{ buff.data(), buff.size() };
return data;
}

void obj::persistent_string::to_string(fmt::memory_buffer &buff) const
{
format_to(std::back_inserter(buff), FMT_COMPILE("{}"), util::escaped_quoted_view(data));
format_to(std::back_inserter(buff), FMT_COMPILE("{}"), data);
}

native_hash obj::persistent_string::to_hash() const
Expand Down
Loading

0 comments on commit 245ed43

Please sign in to comment.