blob: 9bb06978da2608a8413acd046f282157a22a023c [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;
6typedef PyObject * object;
7
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008/* It would be nice if the code generated by asdl_c.py was completely
9 independent of Python, but it is a goal the requires too much work
10 at this stage. So, for example, I'll represent identifiers as
11 interned Python strings.
12*/
13
14/* XXX A sequence should be typed so that its use can be typechecked. */
15
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000016typedef struct {
17 int size;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000018 void *elements[1];
19} asdl_seq;
20
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000021typedef struct {
22 int size;
23 int elements[1];
24} asdl_int_seq;
25
Neal Norwitzadb69fc2005-12-17 20:54:49 +000026asdl_seq *asdl_seq_new(int size, PyArena *arena);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000027asdl_int_seq *asdl_int_seq_new(int size, PyArena *arena);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000028
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000029#define asdl_seq_GET(S, I) (S)->elements[(I)]
Jeremy Hyltona8293132006-02-28 17:58:27 +000030#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
31#ifdef Py_DEBUG
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000032#define asdl_seq_SET(S, I, V) { \
33 int _asdl_i = (I); \
34 assert((S) && _asdl_i < (S)->size); \
35 (S)->elements[_asdl_i] = (V); \
36}
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000037#else
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000038#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039#endif
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000040
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000041#endif /* !Py_ASDL_H */