1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-12 05:23:02 +00:00

Fix some code style, add tuple/type function.

We need to be able to detect tuple type from janet code, otherwise
tuples will contain hidden state. The tuple/type function is able
to detect the flags in the tuple so the programmer can access them
if needed.
This commit is contained in:
Calvin Rose
2019-02-09 12:21:11 -05:00
parent 5020a1bae9
commit c6edf03ae8
6 changed files with 46 additions and 29 deletions

View File

@@ -335,22 +335,14 @@ static int comment(JanetParser *p, JanetParseState *state, uint8_t c) {
return 1;
}
static Janet close_tuple(JanetParser *p, JanetParseState *state) {
static Janet close_tuple(JanetParser *p, JanetParseState *state, int32_t flag) {
Janet *ret = janet_tuple_begin(state->argn);
janet_tuple_flag(ret) = flag;
for (int32_t i = state->argn - 1; i >= 0; i--)
ret[i] = p->args[--p->argcount];
return janet_wrap_tuple(janet_tuple_end(ret));
}
static Janet close_ltuple(JanetParser *p, JanetParseState *state) {
Janet *ret = janet_tuple_begin(state->argn);
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));
}
static Janet close_array(JanetParser *p, JanetParseState *state) {
JanetArray *array = janet_array(state->argn);
for (int32_t i = state->argn - 1; i >= 0; i--)
@@ -495,11 +487,7 @@ static int root(JanetParser *p, JanetParseState *state, uint8_t c) {
if (state->flags & PFLAG_ATSYM) {
ds = close_array(p, state);
} else {
if (c == ']') {
ds = close_ltuple(p, state);
} else {
ds = close_tuple(p, state);
}
ds = close_tuple(p, state, c == ']' ? JANET_TUPLE_FLAG_BRACKETCTOR : 0);
}
} else if (c == '}' && (state->flags & PFLAG_CURLYBRACKETS)) {
if (state->argn & 1) {