mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50:27 +00:00
Add symbol/slice and keyword/slice
This commit is contained in:
parent
9c5e97144d
commit
d033412b1f
@ -2,6 +2,9 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Unreleased - ???
|
||||
- Add `symbol/slice`
|
||||
- Add `keyword/slice`
|
||||
- Allow cross compilation with Makefile.
|
||||
- Change `compare-primitve` to `cmp` and make it more efficient.
|
||||
- Change `reverse` to `reversed`, reverse now mutates the backing array
|
||||
- `janet_dobytes` and `janet_dostring` return parse errors in \*out
|
||||
|
@ -176,6 +176,18 @@ static Janet cfun_string_slice(int32_t argc, Janet *argv) {
|
||||
return janet_stringv(view.bytes + range.start, range.end - range.start);
|
||||
}
|
||||
|
||||
static Janet cfun_symbol_slice(int32_t argc, Janet *argv) {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_symbolv(view.bytes + range.start, range.end - range.start);
|
||||
}
|
||||
|
||||
static Janet cfun_keyword_slice(int32_t argc, Janet *argv) {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_keywordv(view.bytes + range.start, range.end - range.start);
|
||||
}
|
||||
|
||||
static Janet cfun_string_repeat(int32_t argc, Janet *argv) {
|
||||
janet_fixarity(argc, 2);
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
@ -529,6 +541,16 @@ static const JanetReg string_cfuns[] = {
|
||||
"from the end of the string. Note that index -1 is synonymous with "
|
||||
"index (length bytes) to allow a full negative slice range. ")
|
||||
},
|
||||
{
|
||||
"keyword/slice", cfun_keyword_slice,
|
||||
JDOC("(keyword/slice bytes &opt start end)\n\n"
|
||||
"Same a string/slice, but returns a keyword.")
|
||||
},
|
||||
{
|
||||
"symbol/slice", cfun_symbol_slice,
|
||||
JDOC("(symbol/slice bytes &opt start end)\n\n"
|
||||
"Same a string/slice, but returns a symbol.")
|
||||
},
|
||||
{
|
||||
"string/repeat", cfun_string_repeat,
|
||||
JDOC("(string/repeat bytes n)\n\n"
|
||||
|
@ -1399,7 +1399,7 @@ int janet_init(void) {
|
||||
* a collection pretty much every cycle, which is
|
||||
* incredibly horrible for performance, but can help ensure
|
||||
* there are no memory bugs during development */
|
||||
janet_vm_gc_interval = 0x10000;
|
||||
janet_vm_gc_interval = 0x400000;
|
||||
janet_symcache_init();
|
||||
/* Initialize gc roots */
|
||||
janet_vm_roots = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user