From bfd38452181b8b79c814cdb717370c48281b198b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 27 Mar 2019 00:14:51 -0400 Subject: [PATCH] Fix cfunction debugging issue Cfunction were not describing themselves very well, as their names were not be added to the registry. --- src/core/pp.c | 15 +++++++++------ src/core/util.c | 15 ++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/core/pp.c b/src/core/pp.c index 4e42b20c..fc7a138b 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -333,6 +333,9 @@ static const char *janet_pretty_colors[] = { NULL }; +#define JANET_PRETTY_DICT_ONELINE 4 +#define JANET_PRETTY_IND_ONELINE 10 + /* Helper for pretty printing */ static void janet_pretty_one(struct pretty *S, Janet x, int is_dict_value) { /* Add to seen */ @@ -383,11 +386,11 @@ static void janet_pretty_one(struct pretty *S, Janet x, int is_dict_value) { if (S->depth == 0) { janet_buffer_push_cstring(S->buffer, "..."); } else { - if (!isarray && len >= 5) + if (!isarray && len >= JANET_PRETTY_IND_ONELINE) janet_buffer_push_u8(S->buffer, ' '); - if (is_dict_value && len >= 5) print_newline(S, 0); + if (is_dict_value && len >= JANET_PRETTY_IND_ONELINE) print_newline(S, 0); for (i = 0; i < len; i++) { - if (i) print_newline(S, len < 5); + if (i) print_newline(S, len < JANET_PRETTY_IND_ONELINE); janet_pretty_one(S, arr[i], 0); } } @@ -424,15 +427,15 @@ static void janet_pretty_one(struct pretty *S, Janet x, int is_dict_value) { int first_kv_pair = 1; const JanetKV *kvs = NULL; janet_dictionary_view(x, &kvs, &len, &cap); - if (!istable && len >= 4) + if (!istable && len >= JANET_PRETTY_DICT_ONELINE) janet_buffer_push_u8(S->buffer, ' '); - if (is_dict_value && len >= 5) print_newline(S, 0); + if (is_dict_value && len >= JANET_PRETTY_DICT_ONELINE) print_newline(S, 0); for (i = 0; i < cap; i++) { if (!janet_checktype(kvs[i].key, JANET_NIL)) { if (first_kv_pair) { first_kv_pair = 0; } else { - print_newline(S, len < 4); + print_newline(S, len < JANET_PRETTY_DICT_ONELINE); } janet_pretty_one(S, kvs[i].key, 0); janet_buffer_push_u8(S->buffer, ' '); diff --git a/src/core/util.c b/src/core/util.c index 214b6418..a2d56594 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -270,12 +270,13 @@ void janet_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns) int32_t nmlen = 0; while (regprefix[reglen]) reglen++; while (cfuns->name[nmlen]) nmlen++; - uint8_t *longname_buffer = - janet_string_begin(reglen + 1 + nmlen); + int32_t symlen = reglen + 1 + nmlen; + uint8_t *longname_buffer = malloc(symlen); memcpy(longname_buffer, regprefix, reglen); longname_buffer[reglen] = '/'; memcpy(longname_buffer + reglen + 1, cfuns->name, nmlen); - longname = janet_wrap_symbol(janet_string_end(longname_buffer)); + longname = janet_wrap_symbol(janet_symbol(longname_buffer, symlen)); + free(longname_buffer); } Janet fun = janet_wrap_cfunction(cfuns->cfun); janet_def(env, cfuns->name, fun, cfuns->documentation); @@ -331,18 +332,18 @@ void janet_core_def(JanetTable *env, const char *name, Janet x, const void *p) { (void) p; Janet key = janet_csymbolv(name); Janet value; - /* During boot, allow replacing core library cfunctions with values from + /* During init, allow replacing core library cfunctions with values from * the env. */ Janet check = janet_table_get(env, key); if (janet_checktype(check, JANET_NIL)) { value = x; } else { value = check; - if (janet_checktype(check, JANET_CFUNCTION)) { - janet_table_put(janet_vm_registry, value, key); - } } janet_table_put(env, key, value); + if (janet_checktype(value, JANET_CFUNCTION)) { + janet_table_put(janet_vm_registry, value, key); + } } void janet_core_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns) {