Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy-33 committed Jul 1, 2024
1 parent c55a43a commit 138283c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 54 deletions.
1 change: 0 additions & 1 deletion compiler+runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ add_library(
jank_lib STATIC
src/cpp/jank/native_box.cpp
src/cpp/jank/hash.cpp
src/cpp/jank/util/character.cpp
src/cpp/jank/util/cli.cpp
src/cpp/jank/util/mapped_file.cpp
src/cpp/jank/util/scope_exit.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ namespace jank
return make_box<runtime::obj::integer>(i);
}

[[gnu::always_inline, gnu::flatten, gnu::hot]]
inline auto make_box(char const i)
{
return make_box<runtime::obj::character>(native_persistent_string(1, i));
}

[[gnu::always_inline, gnu::flatten, gnu::hot]]
inline auto make_box(size_t const i)
{
Expand Down
6 changes: 5 additions & 1 deletion compiler+runtime/include/cpp/jank/runtime/obj/character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace jank::runtime
template <>
struct static_object<object_type::character> : gc
{
static constexpr native_bool pointer_free{ true };
static constexpr native_bool pointer_free{ false };

static_object() = default;
static_object(static_object &&) = default;
static_object(static_object const &) = default;
static_object(native_persistent_string_view const &);
static_object(native_persistent_string const &);
static_object(char);

/* behavior::objectable */
native_bool equal(object const &) const;
Expand All @@ -21,6 +23,8 @@ namespace jank::runtime
native_hash to_hash() const;

object base{ object_type::character };

/* Holds the litereal form of the character as it's written eg. "\\tab" */
native_persistent_string data;
};

Expand Down
8 changes: 0 additions & 8 deletions compiler+runtime/include/cpp/jank/util/character.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/codegen/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace jank::codegen
{
return "jank::runtime::obj::character_ptr";
}
return "jank::native_persistent_string";
return "jank::runtime::obj::character";
}
case jank::runtime::object_type::real:
{
Expand Down
50 changes: 47 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/obj/character.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
#include <jank/runtime/obj/character.hpp>
#include <jank/util/character.hpp>

namespace jank::runtime
{

static option<char> get_char_from_repr(native_persistent_string const &sv)
{
if(sv.size() == 2)
{
return sv[1];
}
else if(sv == "\\newline")
{
return '\n';
}
else if(sv == "\\space")
{
return ' ';
}
else if(sv == "\\tab")
{
return '\t';
}
else if(sv == "\\backspace")
{
return '\b';
}
else if(sv == "\\formfeed")
{
return '\f';
}
else if(sv == "\\return")
{
return '\r';
}

return none;
}

obj::character::static_object(native_persistent_string_view const &d)
: data{ native_persistent_string(d) }
: data{ d }
{
}

obj::character::static_object(native_persistent_string const &d)
: data{ d }
{
}

obj::character::static_object(char ch)
: data{ 1, ch }
{
}

Expand Down Expand Up @@ -33,6 +77,6 @@ namespace jank::runtime

native_hash obj::character::to_hash() const
{
return static_cast<native_hash>(util::character::get_char_from_repr(data).unwrap());
return static_cast<native_hash>(get_char_from_repr(data).unwrap());
}
}
38 changes: 0 additions & 38 deletions compiler+runtime/src/cpp/jank/util/character.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion compiler+runtime/test/cpp/jank/read/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ namespace jank::read::lex
}));
}

SUBCASE("character followed by a backticked keyword")
SUBCASE("Character followed by a backticked keyword")
{
processor p{ R"(\a`:kw)" };
native_vector<result<token, error>> tokens(p.begin(), p.end());
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/test/cpp/jank/read/parse.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "jank/type.hpp"
#include <unistd.h>

#include <jank/read/lex.hpp>
Expand Down

0 comments on commit 138283c

Please sign in to comment.