From a7860f1dd1dcb95b15be9792d8bb39ba58256e94 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 19 Nov 2018 09:57:24 -0500 Subject: [PATCH] Update pretty printer to remove values from seen table. --- src/core/asm.c | 7 +++++++ src/core/string.c | 4 +++- src/include/janet/janet.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/asm.c b/src/core/asm.c index 593365f3..050aae26 100644 --- a/src/core/asm.c +++ b/src/core/asm.c @@ -541,6 +541,10 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int x = janet_get(s, janet_csymbolv("vararg")); if (janet_truthy(x)) def->flags |= JANET_FUNCDEF_FLAG_VARARG; + /* Check strict arity */ + x = janet_get(s, janet_csymbolv("fix-arity")); + if (janet_truthy(x)) def->flags |= JANET_FUNCDEF_FLAG_FIXARITY; + /* Check source */ x = janet_get(s, janet_csymbolv("source")); if (janet_checktype(x, JANET_STRING)) def->source = janet_unwrap_string(x); @@ -836,6 +840,9 @@ Janet janet_disasm(JanetFuncDef *def) { if (def->flags & JANET_FUNCDEF_FLAG_VARARG) { janet_table_put(ret, janet_csymbolv("vararg"), janet_wrap_true()); } + if (def->flags & JANET_FUNCDEF_FLAG_FIXARITY) { + janet_table_put(ret, janet_csymbolv("fix-arity"), janet_wrap_true()); + } if (NULL != def->name) { janet_table_put(ret, janet_csymbolv("name"), janet_wrap_string(def->name)); } diff --git a/src/core/string.c b/src/core/string.c index e5fa6f90..a299d78e 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -518,7 +518,7 @@ static void janet_pretty_one(struct pretty *S, Janet x) { switch (janet_type(x)) { default: janet_description_b(S->buffer, x); - return; + break; case JANET_ARRAY: case JANET_TUPLE: { @@ -579,6 +579,8 @@ static void janet_pretty_one(struct pretty *S, Janet x) { break; } } + /* Remove from seen */ + janet_table_remove(&S->seen, x); return; } diff --git a/src/include/janet/janet.h b/src/include/janet/janet.h index 7307001a..29ed4384 100644 --- a/src/include/janet/janet.h +++ b/src/include/janet/janet.h @@ -1094,6 +1094,7 @@ JANET_API int janet_equals(Janet x, Janet y); JANET_API int32_t janet_hash(Janet x); JANET_API int janet_compare(Janet x, Janet y); JANET_API int janet_cstrcmp(const uint8_t *str, const char *other); +JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, Janet x); /* VM functions */ JANET_API int janet_init(void);