Skip to content

Commit

Permalink
Merge pull request #50 from jank-lang/string
Browse files Browse the repository at this point in the history
Add new persistent string
  • Loading branch information
jeaye authored Dec 30, 2023
2 parents 6119929 + 78d40af commit 72f3e38
Show file tree
Hide file tree
Showing 81 changed files with 1,565 additions and 375 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ if(jank_tests)
add_executable(
jank_test_exe
test/cpp/main.cpp
test/cpp/jank/native_persistent_string.cpp
test/cpp/jank/read/lex.cpp
test/cpp/jank/read/parse.cpp
test/cpp/jank/analyze/box.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/cpp/jank/analyze/expr/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace jank::analyze::expr
template <typename E>
struct function : expression_base
{
native_string name;
native_persistent_string name;
native_vector<function_arity<E>> arities;

runtime::object_ptr to_runtime_data() const
Expand Down
4 changes: 2 additions & 2 deletions include/cpp/jank/analyze/expr/native_raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace jank::analyze::expr
template <typename E>
struct native_raw : expression_base
{
using chunk_t = boost::variant<native_string, native_box<E>>;
using chunk_t = boost::variant<native_persistent_string, native_box<E>>;

native_vector<chunk_t> chunks;

Expand All @@ -34,7 +34,7 @@ namespace jank::analyze::expr
{
using T = std::decay_t<decltype(d)>;

if constexpr(std::same_as<T, native_string>)
if constexpr(std::same_as<T, native_persistent_string>)
{ return make_box(d); }
else
{ return d->to_runtime_data(); }
Expand Down
8 changes: 4 additions & 4 deletions include/cpp/jank/codegen/escape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* https://github.com/fmtlib/fmt/issues/825#issuecomment-1227501168 */
namespace jank::codegen
{
template <typename S = native_string_view>
template <typename S = native_persistent_string_view>
struct escape_view
{
template <typename It>
Expand All @@ -32,9 +32,9 @@ namespace jank::codegen
typename S::value_type esc{ '\\' };
};

constexpr escape_view<native_string_view> escaped
(native_string_view const &sv, char const q = '"', char const e = '\\')
{ return escape_view<native_string_view>{ sv, q, e }; }
constexpr escape_view<native_persistent_string_view> escaped
(native_persistent_string_view const &sv, char const q = '"', char const e = '\\')
{ return escape_view<native_persistent_string_view>{ sv, q, e }; }
}

template <typename S>
Expand Down
38 changes: 19 additions & 19 deletions include/cpp/jank/codegen/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ namespace jank::codegen
handle() = default;
handle(handle const &) = default;
handle(handle &&) = default;
handle(native_string const &name, bool boxed);
handle(native_string const &boxed_name);
handle(native_string const &boxed_name, native_string const &unboxed_name);
handle(native_persistent_string const &name, bool boxed);
handle(native_persistent_string const &boxed_name);
handle(native_persistent_string const &boxed_name, native_persistent_string const &unboxed_name);
handle(analyze::local_binding const &binding);

handle& operator =(handle const &) = default;
handle& operator =(handle &&) = default;

native_string str(bool needs_box) const;
native_persistent_string str(bool needs_box) const;

native_string boxed_name;
native_string unboxed_name;
native_persistent_string boxed_name;
native_persistent_string unboxed_name;
};

enum class compilation_target
Expand All @@ -60,14 +60,14 @@ namespace jank::codegen
(
runtime::context &rt_ctx,
analyze::expression_ptr const &expr,
native_string_view const &module,
native_persistent_string_view const &module,
compilation_target target
);
processor
(
runtime::context &rt_ctx,
analyze::expr::function<analyze::expression> const &expr,
native_string_view const &module,
native_persistent_string_view const &module,
compilation_target target
);
processor(processor const &) = delete;
Expand Down Expand Up @@ -164,36 +164,36 @@ namespace jank::codegen
bool box_needed
);

native_string declaration_str();
native_persistent_string declaration_str();
void build_header();
void build_body();
void build_footer();
native_string expression_str(bool box_needed);
native_persistent_string expression_str(bool box_needed);

native_string module_init_str(native_string_view const &module);
native_persistent_string module_init_str(native_persistent_string_view const &module);

void format_elided_var
(
native_string_view const &start,
native_string_view const &end,
native_string_view const &ret_tmp,
native_persistent_string_view const &start,
native_persistent_string_view const &end,
native_persistent_string_view const &ret_tmp,
native_vector<native_box<analyze::expression>> const &arg_exprs,
analyze::expr::function_arity<analyze::expression> const &fn_arity,
bool arg_box_needed,
bool ret_box_needed
);
void format_direct_call
(
native_string const &source_tmp,
native_string_view const &ret_tmp,
native_persistent_string const &source_tmp,
native_persistent_string_view const &ret_tmp,
native_vector<native_box<analyze::expression>> const &arg_exprs,
analyze::expr::function_arity<analyze::expression> const &fn_arity,
bool arg_box_needed
);
void format_dynamic_call
(
native_string const &source_tmp,
native_string_view const &ret_tmp,
native_persistent_string const &source_tmp,
native_persistent_string_view const &ret_tmp,
native_vector<native_box<analyze::expression>> const &arg_exprs,
analyze::expr::function_arity<analyze::expression> const &fn_arity,
bool arg_box_needed
Expand All @@ -203,7 +203,7 @@ namespace jank::codegen
/* This is stored just to keep the expression alive. */
analyze::expression_ptr root_expr{};
analyze::expr::function<analyze::expression> const &root_fn;
native_string module;
native_persistent_string module;

compilation_target target{};
runtime::obj::symbol struct_name;
Expand Down
2 changes: 1 addition & 1 deletion include/cpp/jank/detail/to_runtime_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace jank::detail
runtime::object_ptr to_runtime_data(native_box<T> const &d)
{ return make_box(fmt::format("box({})", reinterpret_cast<void const*>(d.data))); }

inline runtime::object_ptr to_runtime_data(native_string const &d)
inline runtime::object_ptr to_runtime_data(native_persistent_string const &d)
{ return make_box(d); }
inline runtime::object_ptr to_runtime_data(runtime::obj::symbol const &d)
{ return make_box<runtime::obj::symbol>(d); }
Expand Down
6 changes: 3 additions & 3 deletions include/cpp/jank/jit/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace jank::jit
{
processor(runtime::context &rt_ctx, native_integer optimization_level);

result<option<runtime::object_ptr>, native_string> eval(codegen::processor &cg_prc) const;
void eval_string(native_string const &s) const;
void load_object(native_string_view const &path) const;
result<option<runtime::object_ptr>, native_persistent_string> eval(codegen::processor &cg_prc) const;
void eval_string(native_persistent_string const &s) const;
void load_object(native_persistent_string_view const &path) const;

std::unique_ptr<cling::Interpreter> interpreter;
native_integer optimization_level{};
Expand Down
2 changes: 1 addition & 1 deletion include/cpp/jank/native_box_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ namespace jank
native_box<runtime::obj::integer> make_box(native_integer const i);
native_box<runtime::obj::integer> make_box(size_t const i);
native_box<runtime::obj::real> make_box(native_real const r);
native_box<runtime::obj::string> make_box(native_string_view const &s);
native_box<runtime::obj::string> make_box(native_persistent_string_view const &s);
}
Loading

0 comments on commit 72f3e38

Please sign in to comment.