mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 16:00:27 +00:00
Fix description semantics. describe returns string, does not print.
This commit is contained in:
parent
1ec704feb9
commit
c0ac44a650
@ -360,6 +360,6 @@ onvalue."
|
||||
(file-read stdin :line buf))
|
||||
(defn onvalue [x]
|
||||
(put newenv '_ @{'value x})
|
||||
(print x))
|
||||
(print (describe x)))
|
||||
(run-context newenv (if getchunk getchunk chunks) onvalue
|
||||
(fn [t x] (print (string t " error: " x)))))
|
||||
|
@ -48,16 +48,16 @@ int dst_core_print(DstArgs args) {
|
||||
|
||||
int dst_core_describe(DstArgs args) {
|
||||
int32_t i;
|
||||
DstBuffer b;
|
||||
dst_buffer_init(&b, 0);
|
||||
for (i = 0; i < args.n; ++i) {
|
||||
int32_t j, len;
|
||||
const uint8_t *vstr = dst_description(args.v[i]);
|
||||
len = dst_string_length(vstr);
|
||||
for (j = 0; j < len; ++j) {
|
||||
putc(vstr[j], stdout);
|
||||
}
|
||||
putc('\n', stdout);
|
||||
int32_t len;
|
||||
const uint8_t *str = dst_description(args.v[i]);
|
||||
len = dst_string_length(str);
|
||||
dst_buffer_push_bytes(&b, str, len);
|
||||
}
|
||||
if (!i) putc('\n', stdout);
|
||||
*args.ret = dst_stringv(b.data, b.count);
|
||||
dst_buffer_deinit(&b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
* 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) {
|
||||
int32_t cap = dst_struct_capacity(st);
|
||||
int32_t hash = dst_hash(key);
|
||||
|
Loading…
Reference in New Issue
Block a user