summaryrefslogtreecommitdiff
path: root/py/parse.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-08 01:57:40 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-08 01:57:40 +0000
commit7d414a1b52d193bab2c94cf56932e1eba23ba542 (patch)
tree69f6840e4f825ffc1047fe7cb0f52eba27b20d86 /py/parse.h
parent5f97aaeca4dc607a2d32e758c3ef6131ffb168a6 (diff)
py: Parse big-int/float/imag constants directly in parser.
Previous to this patch, a big-int, float or imag constant was interned (made into a qstr) and then parsed at runtime to create an object each time it was needed. This is wasteful in RAM and not efficient. Now, these constants are parsed straight away in the parser and turned into objects. This allows constants with large numbers of digits (so addresses issue #1103) and takes us a step closer to #722.
Diffstat (limited to 'py/parse.h')
-rw-r--r--py/parse.h28
1 files changed, 12 insertions, 16 deletions
diff --git a/py/parse.h b/py/parse.h
index ee0025a7b..5d992a6b9 100644
--- a/py/parse.h
+++ b/py/parse.h
@@ -36,21 +36,17 @@ struct _mp_lexer_t;
// - 0000...0000: no node
// - xxxx...xxx1: a small integer; bits 1 and above are the signed value, 2's complement
// - xxxx...xx00: pointer to mp_parse_node_struct_t
-// - xx...x00010: an identifier; bits 5 and above are the qstr
-// - xx...x00110: an integer; bits 5 and above are the qstr holding the value
-// - xx...x01010: a decimal; bits 5 and above are the qstr holding the value
-// - xx...x01110: a string; bits 5 and above are the qstr holding the value
-// - xx...x10010: a string of bytes; bits 5 and above are the qstr holding the value
-// - xx...x10110: a token; bits 5 and above are mp_token_kind_t
+// - xx...xx0010: an identifier; bits 4 and above are the qstr
+// - xx...xx0110: a string; bits 4 and above are the qstr holding the value
+// - xx...xx1010: a string of bytes; bits 4 and above are the qstr holding the value
+// - xx...xx1110: a token; bits 4 and above are mp_token_kind_t
#define MP_PARSE_NODE_NULL (0)
#define MP_PARSE_NODE_SMALL_INT (0x1)
#define MP_PARSE_NODE_ID (0x02)
-#define MP_PARSE_NODE_INTEGER (0x06)
-#define MP_PARSE_NODE_DECIMAL (0x0a)
-#define MP_PARSE_NODE_STRING (0x0e)
-#define MP_PARSE_NODE_BYTES (0x12)
-#define MP_PARSE_NODE_TOKEN (0x16)
+#define MP_PARSE_NODE_STRING (0x06)
+#define MP_PARSE_NODE_BYTES (0x0a)
+#define MP_PARSE_NODE_TOKEN (0x0e)
typedef mp_uint_t mp_parse_node_t; // must be pointer size
@@ -69,12 +65,12 @@ typedef struct _mp_parse_node_struct_t {
#define MP_PARSE_NODE_IS_STRUCT_KIND(pn, k) ((pn) != MP_PARSE_NODE_NULL && ((pn) & 3) == 0 && MP_PARSE_NODE_STRUCT_KIND((mp_parse_node_struct_t*)(pn)) == (k))
#define MP_PARSE_NODE_IS_SMALL_INT(pn) (((pn) & 0x1) == MP_PARSE_NODE_SMALL_INT)
-#define MP_PARSE_NODE_IS_ID(pn) (((pn) & 0x1f) == MP_PARSE_NODE_ID)
-#define MP_PARSE_NODE_IS_TOKEN(pn) (((pn) & 0x1f) == MP_PARSE_NODE_TOKEN)
-#define MP_PARSE_NODE_IS_TOKEN_KIND(pn, k) ((pn) == (MP_PARSE_NODE_TOKEN | ((k) << 5)))
+#define MP_PARSE_NODE_IS_ID(pn) (((pn) & 0x0f) == MP_PARSE_NODE_ID)
+#define MP_PARSE_NODE_IS_TOKEN(pn) (((pn) & 0x0f) == MP_PARSE_NODE_TOKEN)
+#define MP_PARSE_NODE_IS_TOKEN_KIND(pn, k) ((pn) == (MP_PARSE_NODE_TOKEN | ((k) << 4)))
-#define MP_PARSE_NODE_LEAF_KIND(pn) ((pn) & 0x1f)
-#define MP_PARSE_NODE_LEAF_ARG(pn) (((mp_uint_t)(pn)) >> 5)
+#define MP_PARSE_NODE_LEAF_KIND(pn) ((pn) & 0x0f)
+#define MP_PARSE_NODE_LEAF_ARG(pn) (((mp_uint_t)(pn)) >> 4)
#define MP_PARSE_NODE_LEAF_SMALL_INT(pn) (((mp_int_t)(pn)) >> 1)
#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)