diff options
Diffstat (limited to 'py/parse.h')
-rw-r--r-- | py/parse.h | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/py/parse.h b/py/parse.h index 722d9f6c20..7326243ea4 100644 --- a/py/parse.h +++ b/py/parse.h @@ -1,6 +1,6 @@ -struct _py_lexer_t; +struct _mp_lexer_t; -// a py_parse_node_t is: +// a mp_parse_node_t is: // - 0000...0000: no node // - xxxx...0001: an identifier; bits 4 and above are the qstr // - xxxx...0011: a small integer; bits 4 and above are the signed value, 2's complement @@ -8,58 +8,58 @@ struct _py_lexer_t; // - xxxx...0111: a decimal; bits 4 and above are the qstr holding the value // - xxxx...1001: a string; bits 4 and above are the qstr holding the value // - xxxx...1011: a string with triple quotes; bits 4 and above are the qstr holding the value -// - xxxx...1101: a token; bits 4 and above are py_token_kind_t -// - xxxx...xxx0: pointer to py_parse_node_struct_t +// - xxxx...1101: a token; bits 4 and above are mp_token_kind_t +// - xxxx...xxx0: pointer to mp_parse_node_struct_t // makes sure the top 5 bits of x are all cleared (positive number) or all set (negavite number) // these macros can probably go somewhere else because they are used more than just in the parser -#define PY_UINT_HIGH_5_BITS (~((~((machine_uint_t)0)) >> 5)) -#define PY_FIT_SMALL_INT(x) (((((machine_uint_t)(x)) & PY_UINT_HIGH_5_BITS) == 0) || ((((machine_uint_t)(x)) & PY_UINT_HIGH_5_BITS) == PY_UINT_HIGH_5_BITS)) +#define MP_UINT_HIGH_5_BITS (~((~((machine_uint_t)0)) >> 5)) +#define MP_FIT_SMALL_INT(x) (((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == 0) || ((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == MP_UINT_HIGH_5_BITS)) -#define PY_PARSE_NODE_NULL (0) -#define PY_PARSE_NODE_ID (0x1) -#define PY_PARSE_NODE_SMALL_INT (0x3) -#define PY_PARSE_NODE_INTEGER (0x5) -#define PY_PARSE_NODE_DECIMAL (0x7) -#define PY_PARSE_NODE_STRING (0x9) -#define PY_PARSE_NODE_BYTES (0xb) -#define PY_PARSE_NODE_TOKEN (0xd) +#define MP_PARSE_NODE_NULL (0) +#define MP_PARSE_NODE_ID (0x1) +#define MP_PARSE_NODE_SMALL_INT (0x3) +#define MP_PARSE_NODE_INTEGER (0x5) +#define MP_PARSE_NODE_DECIMAL (0x7) +#define MP_PARSE_NODE_STRING (0x9) +#define MP_PARSE_NODE_BYTES (0xb) +#define MP_PARSE_NODE_TOKEN (0xd) -typedef machine_uint_t py_parse_node_t; // must be pointer size +typedef machine_uint_t mp_parse_node_t; // must be pointer size -typedef struct _py_parse_node_struct_t { +typedef struct _mp_parse_node_struct_t { uint32_t source; // file identifier, and line number uint32_t kind_num_nodes; // parse node kind, and number of nodes - py_parse_node_t nodes[]; // nodes -} py_parse_node_struct_t; + mp_parse_node_t nodes[]; // nodes +} mp_parse_node_struct_t; -// macros for py_parse_node_t usage +// macros for mp_parse_node_t usage // some of these evaluate their argument more than once -#define PY_PARSE_NODE_IS_NULL(pn) ((pn) == PY_PARSE_NODE_NULL) -#define PY_PARSE_NODE_IS_LEAF(pn) ((pn) & 1) -#define PY_PARSE_NODE_IS_STRUCT(pn) ((pn) != PY_PARSE_NODE_NULL && ((pn) & 1) == 0) -#define PY_PARSE_NODE_IS_STRUCT_KIND(pn, k) ((pn) != PY_PARSE_NODE_NULL && ((pn) & 1) == 0 && PY_PARSE_NODE_STRUCT_KIND((py_parse_node_struct_t*)(pn)) == (k)) +#define MP_PARSE_NODE_IS_NULL(pn) ((pn) == MP_PARSE_NODE_NULL) +#define MP_PARSE_NODE_IS_LEAF(pn) ((pn) & 1) +#define MP_PARSE_NODE_IS_STRUCT(pn) ((pn) != MP_PARSE_NODE_NULL && ((pn) & 1) == 0) +#define MP_PARSE_NODE_IS_STRUCT_KIND(pn, k) ((pn) != MP_PARSE_NODE_NULL && ((pn) & 1) == 0 && MP_PARSE_NODE_STRUCT_KIND((mp_parse_node_struct_t*)(pn)) == (k)) -#define PY_PARSE_NODE_IS_ID(pn) (((pn) & 0xf) == PY_PARSE_NODE_ID) -#define PY_PARSE_NODE_IS_SMALL_INT(pn) (((pn) & 0xf) == PY_PARSE_NODE_SMALL_INT) -#define PY_PARSE_NODE_IS_TOKEN(pn) (((pn) & 0xf) == PY_PARSE_NODE_TOKEN) -#define PY_PARSE_NODE_IS_TOKEN_KIND(pn, k) ((pn) == (PY_PARSE_NODE_TOKEN | (k << 4))) +#define MP_PARSE_NODE_IS_ID(pn) (((pn) & 0xf) == MP_PARSE_NODE_ID) +#define MP_PARSE_NODE_IS_SMALL_INT(pn) (((pn) & 0xf) == MP_PARSE_NODE_SMALL_INT) +#define MP_PARSE_NODE_IS_TOKEN(pn) (((pn) & 0xf) == MP_PARSE_NODE_TOKEN) +#define MP_PARSE_NODE_IS_TOKEN_KIND(pn, k) ((pn) == (MP_PARSE_NODE_TOKEN | (k << 4))) -#define PY_PARSE_NODE_LEAF_KIND(pn) ((pn) & 0xf) +#define MP_PARSE_NODE_LEAF_KIND(pn) ((pn) & 0xf) // TODO should probably have int and uint versions of this macro -#define PY_PARSE_NODE_LEAF_ARG(pn) (((machine_int_t)(pn)) >> 4) -#define PY_PARSE_NODE_STRUCT_KIND(pns) ((pns)->kind_num_nodes & 0xff) -#define PY_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8) +#define MP_PARSE_NODE_LEAF_ARG(pn) (((machine_int_t)(pn)) >> 4) +#define MP_PARSE_NODE_STRUCT_KIND(pns) ((pns)->kind_num_nodes & 0xff) +#define MP_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8) -py_parse_node_t py_parse_node_new_leaf(machine_int_t kind, machine_int_t arg); +mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg); -void py_parse_node_show(py_parse_node_t pn, int indent); +void mp_parse_node_show(mp_parse_node_t pn, int indent); typedef enum { - PY_PARSE_SINGLE_INPUT, - PY_PARSE_FILE_INPUT, - PY_PARSE_EVAL_INPUT, -} py_parse_input_kind_t; + MP_PARSE_SINGLE_INPUT, + MP_PARSE_FILE_INPUT, + MP_PARSE_EVAL_INPUT, +} mp_parse_input_kind_t; -py_parse_node_t py_parse(struct _py_lexer_t *lex, py_parse_input_kind_t input_kind); +mp_parse_node_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind); |