Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1 | #ifndef Py_ASDL_H |
| 2 | #define Py_ASDL_H |
| 3 | |
| 4 | typedef PyObject * identifier; |
| 5 | typedef PyObject * string; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 6 | typedef PyObject * bytes; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7 | typedef PyObject * object; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 8 | typedef PyObject * singleton; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10 | /* 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 Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 18 | typedef struct { |
Martin v. Löwis | cc10a37 | 2012-05-15 14:45:03 +0200 | [diff] [blame] | 19 | Py_ssize_t size; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 20 | void *elements[1]; |
| 21 | } asdl_seq; |
| 22 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 23 | typedef struct { |
Martin v. Löwis | cc10a37 | 2012-05-15 14:45:03 +0200 | [diff] [blame] | 24 | Py_ssize_t size; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 25 | int elements[1]; |
| 26 | } asdl_int_seq; |
| 27 | |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 28 | asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena); |
| 29 | asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 30 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 31 | #define asdl_seq_GET(S, I) (S)->elements[(I)] |
Jeremy Hylton | a829313 | 2006-02-28 17:58:27 +0000 | [diff] [blame] | 32 | #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size) |
| 33 | #ifdef Py_DEBUG |
Victor Stinner | 042cb46 | 2013-11-16 00:16:58 +0100 | [diff] [blame] | 34 | #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 Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 39 | (S)->elements[_asdl_i] = (V); \ |
Victor Stinner | 042cb46 | 2013-11-16 00:16:58 +0100 | [diff] [blame] | 40 | } while (0) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 41 | #else |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 42 | #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 43 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 44 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 45 | #endif /* !Py_ASDL_H */ |