1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Added marshalling code to save tuple_flag

This commit is contained in:
J.-F. Cap 2019-02-09 17:00:35 +01:00
parent 86ba69c16b
commit 5020a1bae9
4 changed files with 10 additions and 3 deletions

View File

@ -556,7 +556,7 @@ JanetSlot janetc_value(JanetFopts opts, Janet x) {
/* Empty tuple is tuple literal */
if (janet_tuple_length(tup) == 0) {
ret = janetc_cslot(x);
} else if (janet_tuple_flag(tup) == 1) { // [] tuples are not function call
} else if (janet_tuple_flag(tup) & JANET_TUPLE_FLAG_BRACKETCTOR) { // [] tuples are not function call
ret = janetc_tuple(opts, x);
} else {
JanetSlot head = janetc_value(subopts, tup[0]);

View File

@ -402,11 +402,13 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
goto done;
case JANET_TUPLE:
{
int32_t i, count;
int32_t i, count,flag;
const Janet *tup = janet_unwrap_tuple(x);
count = janet_tuple_length(tup);
flag = janet_tuple_flag(tup);
pushbyte(st, LB_TUPLE);
pushint(st, count);
pushint(st, flag);
for (i = 0; i < count; i++)
marshal_one(st, tup[i], flags + 1);
/* Mark as seen AFTER marshaling */
@ -1044,6 +1046,8 @@ static const uint8_t *unmarshal_one(
} else if (lead == LB_TUPLE) {
/* Tuple */
Janet *tup = janet_tuple_begin(len);
int32_t flag = readint(st, &data);
janet_tuple_flag(tup)=flag;
for (int32_t i = 0; i < len; i++) {
data = unmarshal_one(st, data, tup + i, flags + 1);
}

View File

@ -344,7 +344,7 @@ static Janet close_tuple(JanetParser *p, JanetParseState *state) {
static Janet close_ltuple(JanetParser *p, JanetParseState *state) {
Janet *ret = janet_tuple_begin(state->argn);
janet_tuple_flag(ret)=1;
janet_tuple_flag(ret) |= JANET_TUPLE_FLAG_BRACKETCTOR;
for (int32_t i = state->argn - 1; i >= 0; i--)
ret[i] = p->args[--p->argcount];
return janet_wrap_tuple(janet_tuple_end(ret));

View File

@ -980,6 +980,9 @@ JANET_API void janet_buffer_push_u32(JanetBuffer *buffer, uint32_t x);
JANET_API void janet_buffer_push_u64(JanetBuffer *buffer, uint64_t x);
/* Tuple */
#define JANET_TUPLE_FLAG_BRACKETCTOR 1
#define janet_tuple_raw(t) ((int32_t *)(t) - 5)
#define janet_tuple_length(t) (janet_tuple_raw(t)[0])
#define janet_tuple_hash(t) ((janet_tuple_raw(t)[1]))