mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Added marshalling code to save tuple_flag
This commit is contained in:
parent
86ba69c16b
commit
5020a1bae9
@ -556,7 +556,7 @@ JanetSlot janetc_value(JanetFopts opts, Janet x) {
|
|||||||
/* Empty tuple is tuple literal */
|
/* Empty tuple is tuple literal */
|
||||||
if (janet_tuple_length(tup) == 0) {
|
if (janet_tuple_length(tup) == 0) {
|
||||||
ret = janetc_cslot(x);
|
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);
|
ret = janetc_tuple(opts, x);
|
||||||
} else {
|
} else {
|
||||||
JanetSlot head = janetc_value(subopts, tup[0]);
|
JanetSlot head = janetc_value(subopts, tup[0]);
|
||||||
|
@ -402,11 +402,13 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
|
|||||||
goto done;
|
goto done;
|
||||||
case JANET_TUPLE:
|
case JANET_TUPLE:
|
||||||
{
|
{
|
||||||
int32_t i, count;
|
int32_t i, count,flag;
|
||||||
const Janet *tup = janet_unwrap_tuple(x);
|
const Janet *tup = janet_unwrap_tuple(x);
|
||||||
count = janet_tuple_length(tup);
|
count = janet_tuple_length(tup);
|
||||||
|
flag = janet_tuple_flag(tup);
|
||||||
pushbyte(st, LB_TUPLE);
|
pushbyte(st, LB_TUPLE);
|
||||||
pushint(st, count);
|
pushint(st, count);
|
||||||
|
pushint(st, flag);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
marshal_one(st, tup[i], flags + 1);
|
marshal_one(st, tup[i], flags + 1);
|
||||||
/* Mark as seen AFTER marshaling */
|
/* Mark as seen AFTER marshaling */
|
||||||
@ -1044,6 +1046,8 @@ static const uint8_t *unmarshal_one(
|
|||||||
} else if (lead == LB_TUPLE) {
|
} else if (lead == LB_TUPLE) {
|
||||||
/* Tuple */
|
/* Tuple */
|
||||||
Janet *tup = janet_tuple_begin(len);
|
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++) {
|
for (int32_t i = 0; i < len; i++) {
|
||||||
data = unmarshal_one(st, data, tup + i, flags + 1);
|
data = unmarshal_one(st, data, tup + i, flags + 1);
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ static Janet close_tuple(JanetParser *p, JanetParseState *state) {
|
|||||||
|
|
||||||
static Janet close_ltuple(JanetParser *p, JanetParseState *state) {
|
static Janet close_ltuple(JanetParser *p, JanetParseState *state) {
|
||||||
Janet *ret = janet_tuple_begin(state->argn);
|
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--)
|
for (int32_t i = state->argn - 1; i >= 0; i--)
|
||||||
ret[i] = p->args[--p->argcount];
|
ret[i] = p->args[--p->argcount];
|
||||||
return janet_wrap_tuple(janet_tuple_end(ret));
|
return janet_wrap_tuple(janet_tuple_end(ret));
|
||||||
|
@ -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);
|
JANET_API void janet_buffer_push_u64(JanetBuffer *buffer, uint64_t x);
|
||||||
|
|
||||||
/* Tuple */
|
/* Tuple */
|
||||||
|
|
||||||
|
#define JANET_TUPLE_FLAG_BRACKETCTOR 1
|
||||||
|
|
||||||
#define janet_tuple_raw(t) ((int32_t *)(t) - 5)
|
#define janet_tuple_raw(t) ((int32_t *)(t) - 5)
|
||||||
#define janet_tuple_length(t) (janet_tuple_raw(t)[0])
|
#define janet_tuple_length(t) (janet_tuple_raw(t)[0])
|
||||||
#define janet_tuple_hash(t) ((janet_tuple_raw(t)[1]))
|
#define janet_tuple_hash(t) ((janet_tuple_raw(t)[1]))
|
||||||
|
Loading…
Reference in New Issue
Block a user