mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
Change printing of abstracts with tostring in pp
This change makes pretty printing not hide "abstractness".
This commit is contained in:
parent
962cd7e5f5
commit
174ff87946
@ -224,7 +224,7 @@
|
|||||||
r (gensym)]
|
r (gensym)]
|
||||||
~(let [,f (,fiber/new (fn [] ,body) :ie)
|
~(let [,f (,fiber/new (fn [] ,body) :ie)
|
||||||
,r (,resume ,f)]
|
,r (,resume ,f)]
|
||||||
(if (= (,fiber/status ,f) :error)
|
(if (,= (,fiber/status ,f) :error)
|
||||||
(do (def ,err ,r) ,(if fib ~(def ,fib ,f)) ,;(tuple/slice catch 1))
|
(do (def ,err ,r) ,(if fib ~(def ,fib ,f)) ,;(tuple/slice catch 1))
|
||||||
,r))))
|
,r))))
|
||||||
|
|
||||||
|
@ -181,49 +181,43 @@ static void janet_escape_buffer_b(JanetBuffer *buffer, JanetBuffer *bx) {
|
|||||||
janet_escape_string_impl(buffer, bx->data, bx->count);
|
janet_escape_string_impl(buffer, bx->data, bx->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void janet_description_b(JanetBuffer *buffer, Janet x) {
|
void janet_to_string_b(JanetBuffer *buffer, Janet x) {
|
||||||
switch (janet_type(x)) {
|
switch (janet_type(x)) {
|
||||||
case JANET_NIL:
|
case JANET_NIL:
|
||||||
janet_buffer_push_cstring(buffer, "nil");
|
janet_buffer_push_cstring(buffer, "nil");
|
||||||
return;
|
break;
|
||||||
case JANET_BOOLEAN:
|
case JANET_BOOLEAN:
|
||||||
janet_buffer_push_cstring(buffer,
|
janet_buffer_push_cstring(buffer,
|
||||||
janet_unwrap_boolean(x) ? "true" : "false");
|
janet_unwrap_boolean(x) ? "true" : "false");
|
||||||
return;
|
break;
|
||||||
case JANET_NUMBER:
|
case JANET_NUMBER:
|
||||||
number_to_string_b(buffer, janet_unwrap_number(x));
|
number_to_string_b(buffer, janet_unwrap_number(x));
|
||||||
return;
|
break;
|
||||||
case JANET_KEYWORD:
|
case JANET_STRING:
|
||||||
janet_buffer_push_u8(buffer, ':');
|
|
||||||
/* fallthrough */
|
|
||||||
case JANET_SYMBOL:
|
case JANET_SYMBOL:
|
||||||
|
case JANET_KEYWORD:
|
||||||
janet_buffer_push_bytes(buffer,
|
janet_buffer_push_bytes(buffer,
|
||||||
janet_unwrap_string(x),
|
janet_unwrap_string(x),
|
||||||
janet_string_length(janet_unwrap_string(x)));
|
janet_string_length(janet_unwrap_string(x)));
|
||||||
return;
|
break;
|
||||||
case JANET_STRING:
|
|
||||||
janet_escape_string_b(buffer, janet_unwrap_string(x));
|
|
||||||
return;
|
|
||||||
case JANET_BUFFER: {
|
case JANET_BUFFER: {
|
||||||
JanetBuffer *b = janet_unwrap_buffer(x);
|
JanetBuffer *to = janet_unwrap_buffer(x);
|
||||||
if (b == buffer) {
|
/* Prevent resizing buffer while appending */
|
||||||
/* Ensures buffer won't resize while escaping */
|
if (buffer == to) janet_buffer_extra(buffer, to->count);
|
||||||
janet_buffer_ensure(b, 5 * b->count + 3, 1);
|
janet_buffer_push_bytes(buffer, to->data, to->count);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
janet_escape_buffer_b(buffer, b);
|
case JANET_ABSTRACT:
|
||||||
return;
|
{
|
||||||
}
|
JanetAbstract p = janet_unwrap_abstract(x);
|
||||||
case JANET_ABSTRACT: {
|
const JanetAbstractType *t = janet_abstract_type(p);
|
||||||
void *p = janet_unwrap_abstract(x);
|
if (t->tostring != NULL) {
|
||||||
const JanetAbstractType *at = janet_abstract_type(p);
|
t->tostring(p, buffer);
|
||||||
if (at->tostring) {
|
|
||||||
at->tostring(p, buffer);
|
|
||||||
} else {
|
} else {
|
||||||
const char *n = at->name;
|
string_description_b(buffer, t->name, p);
|
||||||
string_description_b(buffer, n, janet_unwrap_abstract(x));
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
case JANET_CFUNCTION: {
|
case JANET_CFUNCTION: {
|
||||||
Janet check = janet_table_get(janet_vm_registry, x);
|
Janet check = janet_table_get(janet_vm_registry, x);
|
||||||
if (janet_checktype(check, JANET_SYMBOL)) {
|
if (janet_checktype(check, JANET_SYMBOL)) {
|
||||||
@ -255,26 +249,43 @@ void janet_description_b(JanetBuffer *buffer, Janet x) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void janet_to_string_b(JanetBuffer *buffer, Janet x) {
|
|
||||||
|
void janet_description_b(JanetBuffer *buffer, Janet x) {
|
||||||
switch (janet_type(x)) {
|
switch (janet_type(x)) {
|
||||||
default:
|
default:
|
||||||
janet_description_b(buffer, x);
|
|
||||||
break;
|
break;
|
||||||
case JANET_BUFFER: {
|
|
||||||
JanetBuffer *to = janet_unwrap_buffer(x);
|
|
||||||
/* Prevent resizing buffer while appending */
|
|
||||||
if (buffer == to) janet_buffer_extra(buffer, to->count);
|
|
||||||
janet_buffer_push_bytes(buffer, to->data, to->count);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case JANET_STRING:
|
|
||||||
case JANET_SYMBOL:
|
|
||||||
case JANET_KEYWORD:
|
case JANET_KEYWORD:
|
||||||
janet_buffer_push_bytes(buffer,
|
janet_buffer_push_u8(buffer, ':');
|
||||||
janet_unwrap_string(x),
|
|
||||||
janet_string_length(janet_unwrap_string(x)));
|
|
||||||
break;
|
break;
|
||||||
|
case JANET_STRING:
|
||||||
|
janet_escape_string_b(buffer, janet_unwrap_string(x));
|
||||||
|
return;
|
||||||
|
case JANET_BUFFER: {
|
||||||
|
JanetBuffer *b = janet_unwrap_buffer(x);
|
||||||
|
if (b == buffer) {
|
||||||
|
/* Ensures buffer won't resize while escaping */
|
||||||
|
janet_buffer_ensure(b, 5 * b->count + 3, 1);
|
||||||
}
|
}
|
||||||
|
janet_escape_buffer_b(buffer, b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case JANET_ABSTRACT:
|
||||||
|
{
|
||||||
|
JanetAbstract p = janet_unwrap_abstract(x);
|
||||||
|
const JanetAbstractType *t = janet_abstract_type(p);
|
||||||
|
if (t->tostring != NULL) {
|
||||||
|
janet_buffer_push_cstring(buffer, "<");
|
||||||
|
janet_buffer_push_cstring(buffer, t->name);
|
||||||
|
janet_buffer_push_cstring(buffer, " ");
|
||||||
|
t->tostring(p, buffer);
|
||||||
|
janet_buffer_push_cstring(buffer, ">");
|
||||||
|
} else {
|
||||||
|
string_description_b(buffer, t->name, p);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
janet_to_string_b(buffer, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *janet_description(Janet x) {
|
const uint8_t *janet_description(Janet x) {
|
||||||
|
Loading…
Reference in New Issue
Block a user