1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00

Fix description semantics. describe returns string, does not print.

This commit is contained in:
Calvin Rose 2018-03-14 18:57:26 -04:00
parent 1ec704feb9
commit c0ac44a650
3 changed files with 16 additions and 10 deletions

View File

@ -360,6 +360,6 @@ onvalue."
(file-read stdin :line buf)) (file-read stdin :line buf))
(defn onvalue [x] (defn onvalue [x]
(put newenv '_ @{'value x}) (put newenv '_ @{'value x})
(print x)) (print (describe x)))
(run-context newenv (if getchunk getchunk chunks) onvalue (run-context newenv (if getchunk getchunk chunks) onvalue
(fn [t x] (print (string t " error: " x))))) (fn [t x] (print (string t " error: " x)))))

View File

@ -48,16 +48,16 @@ int dst_core_print(DstArgs args) {
int dst_core_describe(DstArgs args) { int dst_core_describe(DstArgs args) {
int32_t i; int32_t i;
DstBuffer b;
dst_buffer_init(&b, 0);
for (i = 0; i < args.n; ++i) { for (i = 0; i < args.n; ++i) {
int32_t j, len; int32_t len;
const uint8_t *vstr = dst_description(args.v[i]); const uint8_t *str = dst_description(args.v[i]);
len = dst_string_length(vstr); len = dst_string_length(str);
for (j = 0; j < len; ++j) { dst_buffer_push_bytes(&b, str, len);
putc(vstr[j], stdout);
}
putc('\n', stdout);
} }
if (!i) putc('\n', stdout); *args.ret = dst_stringv(b.data, b.count);
dst_buffer_deinit(&b);
return 0; return 0;
} }

View File

@ -59,7 +59,13 @@ const DstKV *dst_struct_find(const DstKV *st, Dst key) {
/* Put a kv pair into a struct that has not yet been fully constructed. /* Put a kv pair into a struct that has not yet been fully constructed.
* Nil keys and values are ignored, extra keys are ignore, and duplicate keys are * Nil keys and values are ignored, extra keys are ignore, and duplicate keys are
* ignored. */ * ignored.
*
* Much of this complexity is in the robinhood hashing scheme, an
* attempt to make structs that are created with arguments in a different
* order to have the same internal representation. If this turns out to be
* incorrect or too complicated, another scheme that would definitely work
* is inserting all keys in sorted order with any deterministic hashing scheme. */
void dst_struct_put(DstKV *st, Dst key, Dst value) { void dst_struct_put(DstKV *st, Dst key, Dst value) {
int32_t cap = dst_struct_capacity(st); int32_t cap = dst_struct_capacity(st);
int32_t hash = dst_hash(key); int32_t hash = dst_hash(key);