-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement 9 of 21 clojure.string vars #201
Open
frenchy64
wants to merge
20
commits into
jank-lang:main
Choose a base branch
from
frenchy64:clojure-string
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e8572a6
clojure.string
frenchy64 b8a8835
[skip ci] rm debug
frenchy64 362b4d0
[skip ci] test framework
frenchy64 d191c5d
add test
frenchy64 bf07b5e
rm indirection
frenchy64 c367fd5
[skip ci]
frenchy64 7d8a213
[skip ci] rm test runner
frenchy64 7680bea
[skip ci] ends-with?
frenchy64 567bb12
blank?
frenchy64 948b9e8
upper-case
frenchy64 1765e0d
lower-case
frenchy64 7b92163
capitalize
frenchy64 6e504a9
[skip ci] wip str/escape
frenchy64 02009f8
escape
frenchy64 a360c0e
Merge branch 'main' into clojure-string
frenchy64 af39e71
tests
frenchy64 ccc81d8
fmt
frenchy64 ca42efc
[skip ci] rm comments
frenchy64 63b00bf
rm old script
frenchy64 11a40e6
[skip ci] rm includes
frenchy64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include <jank/c_api.h> | ||
|
||
jank_object_ptr jank_load_clojure_string_native(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <boost/algorithm/string.hpp> | ||
|
||
#include <jank/native_persistent_string/fmt.hpp> | ||
#include <clojure/core_native.hpp> | ||
#include <jank/runtime/convert.hpp> | ||
#include <jank/runtime/core.hpp> | ||
#include <jank/runtime/context.hpp> | ||
#include <jank/runtime/visit.hpp> | ||
|
||
namespace clojure::string_native | ||
{ | ||
using namespace jank; | ||
using namespace jank::runtime; | ||
|
||
static object_ptr blank(object_ptr const s) | ||
{ | ||
if(runtime::is_nil(s)) | ||
{ | ||
return obj::boolean::true_const(); | ||
} | ||
auto const s_str(runtime::to_string(s)); | ||
return make_box(s_str.is_blank()); | ||
} | ||
|
||
static object_ptr reverse(object_ptr const s) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
return make_box<obj::persistent_string>( | ||
native_persistent_string{ s_str.rbegin(), s_str.rend() }); | ||
} | ||
|
||
static object_ptr lower_case(object_ptr const s) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
return make_box(boost::to_lower_copy(s_str)); | ||
} | ||
|
||
static object_ptr starts_with(object_ptr const s, object_ptr const substr) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
auto const substr_str(runtime::to_string(substr)); | ||
return make_box(s_str.starts_with(substr_str)); | ||
} | ||
|
||
static object_ptr ends_with(object_ptr const s, object_ptr const substr) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
auto const substr_str(runtime::to_string(substr)); | ||
return make_box(s_str.ends_with(substr_str)); | ||
} | ||
|
||
static object_ptr includes(object_ptr const s, object_ptr const substr) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
auto const substr_str(runtime::to_string(substr)); | ||
return make_box(s_str.contains(substr_str)); | ||
} | ||
|
||
static object_ptr upper_case(object_ptr const s) | ||
{ | ||
auto const s_str(runtime::to_string(s)); | ||
return make_box(boost::to_upper_copy(s_str)); | ||
} | ||
} | ||
|
||
jank_object_ptr jank_load_clojure_string_native() | ||
{ | ||
using namespace jank; | ||
using namespace jank::runtime; | ||
using namespace clojure; | ||
|
||
auto const ns(__rt_ctx->intern_ns("clojure.string-native")); | ||
|
||
auto const intern_fn([=](native_persistent_string const &name, auto const fn) { | ||
ns->intern_var(name)->bind_root( | ||
make_box<obj::native_function_wrapper>(convert_function(fn)) | ||
->with_meta(obj::persistent_hash_map::create_unique(std::make_pair( | ||
__rt_ctx->intern_keyword("name").expect_ok(), | ||
make_box(obj::symbol{ __rt_ctx->current_ns()->to_string(), name }.to_string()))))); | ||
}); | ||
|
||
intern_fn("blank?", &string_native::blank); | ||
intern_fn("ends-with?", &string_native::ends_with); | ||
intern_fn("includes?", &string_native::includes); | ||
intern_fn("lower-case", &string_native::lower_case); | ||
intern_fn("reverse", &string_native::reverse); | ||
intern_fn("starts-with?", &string_native::starts_with); | ||
intern_fn("upper-case", &string_native::upper_case); | ||
|
||
return erase(obj::nil::nil_const()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not using any visting fns, while this is an incredibly expensive include. Please audit all of the includes here to ensure they're needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still working on this.