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; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame^] | 9 | typedef PyObject * constant; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | /* It would be nice if the code generated by asdl_c.py was completely |
| 12 | independent of Python, but it is a goal the requires too much work |
| 13 | at this stage. So, for example, I'll represent identifiers as |
| 14 | interned Python strings. |
| 15 | */ |
| 16 | |
| 17 | /* XXX A sequence should be typed so that its use can be typechecked. */ |
| 18 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 19 | typedef struct { |
Martin v. Löwis | cc10a37 | 2012-05-15 14:45:03 +0200 | [diff] [blame] | 20 | Py_ssize_t size; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 21 | void *elements[1]; |
| 22 | } asdl_seq; |
| 23 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 24 | typedef struct { |
Martin v. Löwis | cc10a37 | 2012-05-15 14:45:03 +0200 | [diff] [blame] | 25 | Py_ssize_t size; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 26 | int elements[1]; |
| 27 | } asdl_int_seq; |
| 28 | |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 29 | asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena); |
| 30 | 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] | 31 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 32 | #define asdl_seq_GET(S, I) (S)->elements[(I)] |
Jeremy Hylton | a829313 | 2006-02-28 17:58:27 +0000 | [diff] [blame] | 33 | #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size) |
| 34 | #ifdef Py_DEBUG |
Victor Stinner | 042cb46 | 2013-11-16 00:16:58 +0100 | [diff] [blame] | 35 | #define asdl_seq_SET(S, I, V) \ |
| 36 | do { \ |
| 37 | Py_ssize_t _asdl_i = (I); \ |
| 38 | assert((S) != NULL); \ |
| 39 | assert(_asdl_i < (S)->size); \ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 40 | (S)->elements[_asdl_i] = (V); \ |
Victor Stinner | 042cb46 | 2013-11-16 00:16:58 +0100 | [diff] [blame] | 41 | } while (0) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 42 | #else |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 43 | #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 44 | #endif |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 45 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 46 | #endif /* !Py_ASDL_H */ |