blob: 495153c576ffb9ae25919e6705a18f8c8debd98c [file] [log] [blame]
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001#ifndef Py_ASDL_H
2#define Py_ASDL_H
3
4typedef PyObject * identifier;
5typedef PyObject * string;
Benjamin Petersone2498412011-08-09 16:08:39 -05006typedef PyObject * bytes;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00007typedef PyObject * object;
Benjamin Peterson442f2092012-12-06 17:41:04 -05008typedef PyObject * singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00009
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010/* It would be nice if the code generated by asdl_c.py was completely
11 independent of Python, but it is a goal the requires too much work
12 at this stage. So, for example, I'll represent identifiers as
13 interned Python strings.
14*/
15
16/* XXX A sequence should be typed so that its use can be typechecked. */
17
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000018typedef struct {
Martin v. Löwiscc10a372012-05-15 14:45:03 +020019 Py_ssize_t size;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000020 void *elements[1];
21} asdl_seq;
22
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000023typedef struct {
Martin v. Löwiscc10a372012-05-15 14:45:03 +020024 Py_ssize_t size;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000025 int elements[1];
26} asdl_int_seq;
27
Antoine Pitroud01d396e2013-10-12 22:52:43 +020028asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena);
29asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000030
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000031#define asdl_seq_GET(S, I) (S)->elements[(I)]
Jeremy Hyltona8293132006-02-28 17:58:27 +000032#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
33#ifdef Py_DEBUG
Victor Stinner042cb462013-11-16 00:16:58 +010034#define asdl_seq_SET(S, I, V) \
35 do { \
36 Py_ssize_t _asdl_i = (I); \
37 assert((S) != NULL); \
38 assert(_asdl_i < (S)->size); \
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039 (S)->elements[_asdl_i] = (V); \
Victor Stinner042cb462013-11-16 00:16:58 +010040 } while (0)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000041#else
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000042#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000043#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000044
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000045#endif /* !Py_ASDL_H */