mirror of
https://github.com/janet-lang/janet
synced 2025-01-12 16:40:27 +00:00
Fix cfunction debugging issue
Cfunction were not describing themselves very well, as their names were not be added to the registry.
This commit is contained in:
parent
22d75d017f
commit
bfd3845218
@ -333,6 +333,9 @@ static const char *janet_pretty_colors[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define JANET_PRETTY_DICT_ONELINE 4
|
||||||
|
#define JANET_PRETTY_IND_ONELINE 10
|
||||||
|
|
||||||
/* Helper for pretty printing */
|
/* Helper for pretty printing */
|
||||||
static void janet_pretty_one(struct pretty *S, Janet x, int is_dict_value) {
|
static void janet_pretty_one(struct pretty *S, Janet x, int is_dict_value) {
|
||||||
/* Add to seen */
|
/* 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) {
|
if (S->depth == 0) {
|
||||||
janet_buffer_push_cstring(S->buffer, "...");
|
janet_buffer_push_cstring(S->buffer, "...");
|
||||||
} else {
|
} else {
|
||||||
if (!isarray && len >= 5)
|
if (!isarray && len >= JANET_PRETTY_IND_ONELINE)
|
||||||
janet_buffer_push_u8(S->buffer, ' ');
|
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++) {
|
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);
|
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;
|
int first_kv_pair = 1;
|
||||||
const JanetKV *kvs = NULL;
|
const JanetKV *kvs = NULL;
|
||||||
janet_dictionary_view(x, &kvs, &len, &cap);
|
janet_dictionary_view(x, &kvs, &len, &cap);
|
||||||
if (!istable && len >= 4)
|
if (!istable && len >= JANET_PRETTY_DICT_ONELINE)
|
||||||
janet_buffer_push_u8(S->buffer, ' ');
|
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++) {
|
for (i = 0; i < cap; i++) {
|
||||||
if (!janet_checktype(kvs[i].key, JANET_NIL)) {
|
if (!janet_checktype(kvs[i].key, JANET_NIL)) {
|
||||||
if (first_kv_pair) {
|
if (first_kv_pair) {
|
||||||
first_kv_pair = 0;
|
first_kv_pair = 0;
|
||||||
} else {
|
} else {
|
||||||
print_newline(S, len < 4);
|
print_newline(S, len < JANET_PRETTY_DICT_ONELINE);
|
||||||
}
|
}
|
||||||
janet_pretty_one(S, kvs[i].key, 0);
|
janet_pretty_one(S, kvs[i].key, 0);
|
||||||
janet_buffer_push_u8(S->buffer, ' ');
|
janet_buffer_push_u8(S->buffer, ' ');
|
||||||
|
@ -270,12 +270,13 @@ void janet_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns)
|
|||||||
int32_t nmlen = 0;
|
int32_t nmlen = 0;
|
||||||
while (regprefix[reglen]) reglen++;
|
while (regprefix[reglen]) reglen++;
|
||||||
while (cfuns->name[nmlen]) nmlen++;
|
while (cfuns->name[nmlen]) nmlen++;
|
||||||
uint8_t *longname_buffer =
|
int32_t symlen = reglen + 1 + nmlen;
|
||||||
janet_string_begin(reglen + 1 + nmlen);
|
uint8_t *longname_buffer = malloc(symlen);
|
||||||
memcpy(longname_buffer, regprefix, reglen);
|
memcpy(longname_buffer, regprefix, reglen);
|
||||||
longname_buffer[reglen] = '/';
|
longname_buffer[reglen] = '/';
|
||||||
memcpy(longname_buffer + reglen + 1, cfuns->name, nmlen);
|
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 fun = janet_wrap_cfunction(cfuns->cfun);
|
||||||
janet_def(env, cfuns->name, fun, cfuns->documentation);
|
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;
|
(void) p;
|
||||||
Janet key = janet_csymbolv(name);
|
Janet key = janet_csymbolv(name);
|
||||||
Janet value;
|
Janet value;
|
||||||
/* During boot, allow replacing core library cfunctions with values from
|
/* During init, allow replacing core library cfunctions with values from
|
||||||
* the env. */
|
* the env. */
|
||||||
Janet check = janet_table_get(env, key);
|
Janet check = janet_table_get(env, key);
|
||||||
if (janet_checktype(check, JANET_NIL)) {
|
if (janet_checktype(check, JANET_NIL)) {
|
||||||
value = x;
|
value = x;
|
||||||
} else {
|
} else {
|
||||||
value = check;
|
value = check;
|
||||||
if (janet_checktype(check, JANET_CFUNCTION)) {
|
|
||||||
janet_table_put(janet_vm_registry, value, key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
janet_table_put(env, key, value);
|
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) {
|
void janet_core_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns) {
|
||||||
|
Loading…
Reference in New Issue
Block a user