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; |
| 6 | typedef PyObject * object; |
| 7 | |
| 8 | typedef enum {false, true} bool; |
| 9 | |
| 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 | |
| 18 | /* XXX We shouldn't pay for offset when we don't need APPEND. */ |
| 19 | |
| 20 | typedef struct { |
| 21 | int size; |
| 22 | int offset; |
| 23 | void *elements[1]; |
| 24 | } asdl_seq; |
| 25 | |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 26 | asdl_seq *asdl_seq_new(int size, PyArena *arena); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 27 | void asdl_seq_free(asdl_seq *); |
| 28 | |
| 29 | #ifdef Py_DEBUG |
| 30 | #define asdl_seq_GET(S, I) (S)->elements[(I)] |
| 31 | #define asdl_seq_SET(S, I, V) { \ |
| 32 | int _asdl_i = (I); \ |
| 33 | assert((S) && _asdl_i < (S)->size); \ |
| 34 | (S)->elements[_asdl_i] = (V); \ |
| 35 | } |
| 36 | #define asdl_seq_APPEND(S, V) { \ |
| 37 | assert((S) && (S)->offset < (S)->size); \ |
| 38 | (S)->elements[(S)->offset++] = (V); \ |
| 39 | } |
| 40 | #else |
| 41 | #define asdl_seq_GET(S, I) (S)->elements[(I)] |
| 42 | #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V) |
| 43 | #define asdl_seq_APPEND(S, V) (S)->elements[(S)->offset++] = (V) |
| 44 | #endif |
| 45 | #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size) |
| 46 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 47 | #endif /* !Py_ASDL_H */ |