From d033412b1f91488acbb848d817d2d8c3d9108267 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 27 Jun 2020 15:21:17 -0500 Subject: [PATCH] Add symbol/slice and keyword/slice --- CHANGELOG.md | 3 +++ src/core/string.c | 22 ++++++++++++++++++++++ src/core/vm.c | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37dd8e80..20307351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/core/string.c b/src/core/string.c index 7c4ed80c..e37d1687 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -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" diff --git a/src/core/vm.c b/src/core/vm.c index 1eb372cb..6e7a0c3d 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -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;