Skip to content

Commit b2369c5

Browse files
authored
Allow wrapping using _anonymous_ type (#430)
* Work on ano type * Work on ano type * Work on ano type * work on ano * val * global `enum` definition * Upd tests, memleak for modules test * Upd test * Fixed #431 * added test with invalid type keys * add comment * Update changelog * Added tests
1 parent 08f0004 commit b2369c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1978
-336
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# v1.8.2
1+
# v1.8.2-alpha3
22

3-
* Allow converting `mpdata` to `bytes, issue #427.
3+
* Allow converting `mpdata` to `bytes`, issue #427.
44
* Fixed: map cache for nested structure not cleared, issue #428.
5+
* Add global `enum` definition, issue #429.
6+
* Add _anonymous_ wrap only type syntax (`&{..}`), pr #430.
7+
* Added `ano()` function, pr #430.
8+
* Definition `*str` now exposes enumerator keys, issue #431.
59

610
# v1.8.1
711

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ set(SOURCES
120120
src/cleri/tokens.c
121121
src/cleri/version.c
122122
src/ti/access.c
123+
src/ti/ano.c
123124
src/ti/api.c
124125
src/ti/archfile.c
125126
src/ti/archive.c
@@ -226,6 +227,7 @@ set(SOURCES
226227
src/ti/vint.c
227228
src/ti/vset.c
228229
src/ti/vtask.c
230+
src/ti/wano.c
229231
src/ti/warn.c
230232
src/ti/watch.c
231233
src/ti/web.c

grammar/grammar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class LangDef(Grammar):
5151
x_preopr = Regex(r'(\s*~)*(\s*!|\s*[\-+](?=[^0-9]))*')
5252
x_ternary = Token('?')
5353
x_thing = Token('{')
54+
x_ano = Token('&{')
5455
x_template = Token('`')
5556

5657
template = Sequence(
@@ -81,6 +82,7 @@ class LangDef(Grammar):
8182
chain = Ref()
8283

8384
closure = Sequence(x_closure, List(var), '|', THIS)
85+
t_ano = Sequence(x_ano, List(Sequence(name, ':', Optional(THIS))), '}')
8486

8587
thing = Sequence(x_thing, List(Sequence(name, ':', Optional(THIS))), '}')
8688
array = Sequence(x_array, List(THIS), ']')
@@ -184,6 +186,7 @@ class LangDef(Grammar):
184186
t_int,
185187
t_string,
186188
t_regex,
189+
t_ano,
187190
# end immutable values
188191
template,
189192
var_opt_more,

inc/doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/* Collection API */
1515
#define DOC_ALT_RAISE DOC_SEE("collection-api/alt_raise")
16+
#define DOC_ANO DOC_SEE("collection-api/ano")
1617
#define DOC_ASSERT DOC_SEE("collection-api/assert")
1718
#define DOC_BASE64_DECODE DOC_SEE("collection-api/base64_decode")
1819
#define DOC_BASE64_ENCODE DOC_SEE("collection-api/base64_encode")

inc/doc.inline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static inline const char * doc_copy(ti_val_t * val)
145145
case TI_VAL_WRAP: return DOC_WTYPE_COPY;
146146
case TI_VAL_ARR: return DOC_LIST_COPY;
147147
case TI_VAL_SET: return DOC_SET_COPY;
148+
case TI_VAL_WANO: return DOC_WTYPE_COPY;
148149
default: return NULL;
149150
}
150151
}
@@ -157,6 +158,7 @@ static inline const char * doc_dup(ti_val_t * val)
157158
case TI_VAL_WRAP: return DOC_WTYPE_DUP;
158159
case TI_VAL_ARR: return DOC_LIST_DUP;
159160
case TI_VAL_SET: return DOC_SET_DUP;
161+
case TI_VAL_WANO: return DOC_WTYPE_DUP;
160162
default: return NULL;
161163
}
162164
}

inc/langdef/langdef.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* should be used with the libcleri module.
66
*
77
* Source class: LangDef
8-
* Created at: 2024-02-11 20:55:25
8+
* Created at: 2025-11-07 13:13:19
99
*/
1010
#ifndef CLERI_EXPORT_LANGDEF_H_
1111
#define CLERI_EXPORT_LANGDEF_H_
@@ -58,6 +58,7 @@ enum cleri_grammar_ids {
5858
CLERI_GID_STATEMENT,
5959
CLERI_GID_TEMPLATE,
6060
CLERI_GID_THING,
61+
CLERI_GID_T_ANO,
6162
CLERI_GID_T_FALSE,
6263
CLERI_GID_T_FLOAT,
6364
CLERI_GID_T_INT,
@@ -67,6 +68,7 @@ enum cleri_grammar_ids {
6768
CLERI_GID_T_TRUE,
6869
CLERI_GID_VAR,
6970
CLERI_GID_VAR_OPT_MORE,
71+
CLERI_GID_X_ANO,
7072
CLERI_GID_X_ARRAY,
7173
CLERI_GID_X_ASSIGN,
7274
CLERI_GID_X_BLOCK,

inc/ti/ano.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* ti/ano.h
3+
*/
4+
#ifndef TI_ANO_H_
5+
#define TI_ANO_H_
6+
7+
#include <ti/ano.t.h>
8+
#include <ti/val.t.h>
9+
#include <ti/collection.t.h>
10+
#include <util/mpack.h>
11+
#include <ex.h>
12+
13+
#define ANO_T(__x) ((ti_ano_t *) (__x))->type
14+
15+
ti_ano_t * ti_ano_new(void);
16+
int ti_ano_init(
17+
ti_ano_t * ano,
18+
ti_collection_t * collection,
19+
ti_raw_t * spec_raw,
20+
ex_t * e);
21+
ti_ano_t * ti_ano_from_raw(
22+
ti_collection_t * collection,
23+
ti_raw_t * spec_raw,
24+
ex_t * e);
25+
ti_ano_t * ti_ano_create(
26+
ti_collection_t * collection,
27+
const unsigned char * bin,
28+
size_t n,
29+
ex_t * e);
30+
void ti_ano_destroy(ti_ano_t * ano);
31+
32+
static inline int ti_ano_to_client_pk(
33+
ti_ano_t * ano,
34+
msgpack_packer * pk)
35+
{
36+
return mp_pack_append(pk, ano->spec_raw->data, ano->spec_raw->n);
37+
}
38+
39+
static inline _Bool ti_ano_uninitialized(ti_ano_t * ano)
40+
{
41+
return !ano->spec_raw;
42+
}
43+
44+
static inline int ti_ano_to_store_pk(
45+
ti_ano_t * ano,
46+
msgpack_packer * pk)
47+
{
48+
return mp_pack_ext(
49+
pk,
50+
MPACK_EXT_ANO,
51+
ano->spec_raw->data,
52+
ano->spec_raw->n);
53+
}
54+
55+
#endif /* TI_ANO_H_ */

inc/ti/ano.t.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* ti/ano.t.h
3+
*/
4+
#ifndef TI_ANO_T_H_
5+
#define TI_ANO_T_H_
6+
7+
typedef struct ti_ano_s ti_ano_t;
8+
9+
#include <ti/type.t.h>
10+
#include <ti/val.t.h>
11+
12+
struct ti_ano_s
13+
{
14+
uint32_t ref;
15+
uint8_t tp;
16+
int:24;
17+
ti_raw_t * spec_raw; /* mpdata, in log use <anonymous> */
18+
ti_type_t * type;
19+
};
20+
21+
#endif /* TI_ANO_T_H_ */

inc/ti/collection.t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct ti_collection_s
3434
vec_t * access; /* ti_auth_t */
3535
smap_t * procedures; /* ti_procedure_t */
3636
smap_t * named_rooms; /* weak map for ti_room_t (only named rooms) */
37+
smap_t * ano_types; /* weak map for ti_ano_t */
3738
ti_thing_t * root; /* without extra reference */
3839
ti_types_t * types;
3940
ti_enums_t * enums;

inc/ti/do.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int ti_do_prepare_for_loop(ti_query_t * query, cleri_node_t * vars_nd);
4141
int ti_do_init(void);
4242
void ti_do_drop(void);
4343

44+
4445
static inline int ti_do_statement(
4546
ti_query_t * query,
4647
cleri_node_t * nd,

0 commit comments

Comments
 (0)