Numworks Epsilon  1.4.1
Graphing Calculator Operating System
qstr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 #ifndef MICROPY_INCLUDED_PY_QSTR_H
27 #define MICROPY_INCLUDED_PY_QSTR_H
28 
29 #include "py/mpconfig.h"
30 #include "py/misc.h"
31 
32 // See qstrdefs.h for a list of qstr's that are available as constants.
33 // Reference them as MP_QSTR_xxxx.
34 //
35 // Note: it would be possible to define MP_QSTR_xxx as qstr_from_str_static("xxx")
36 // for qstrs that are referenced this way, but you don't want to have them in ROM.
37 
38 // first entry in enum will be MP_QSTR_NULL=0, which indicates invalid/no qstr
39 enum {
40 #ifndef NO_QSTR
41 #define QDEF(id, str) id,
42 #include "genhdr/qstrdefs.generated.h"
43 #undef QDEF
44 #endif
45  MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
46 };
47 
48 typedef size_t qstr;
49 
50 typedef struct _qstr_pool_t {
51  struct _qstr_pool_t *prev;
53  size_t alloc;
54  size_t len;
55  const byte *qstrs[];
56 } qstr_pool_t;
57 
58 #define QSTR_FROM_STR_STATIC(s) (qstr_from_strn((s), strlen(s)))
59 
60 void qstr_init(void);
61 
62 mp_uint_t qstr_compute_hash(const byte *data, size_t len);
63 qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTR_NULL if not found
64 
65 qstr qstr_from_str(const char *str);
66 qstr qstr_from_strn(const char *str, size_t len);
67 
68 byte *qstr_build_start(size_t len, byte **q_ptr);
69 qstr qstr_build_end(byte *q_ptr);
70 
72 const char *qstr_str(qstr q);
73 size_t qstr_len(qstr q);
74 const byte *qstr_data(qstr q, size_t *len);
75 
76 void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes);
77 void qstr_dump_data(void);
78 
79 #endif // MICROPY_INCLUDED_PY_QSTR_H
mp_uint_t qstr_hash(qstr q)
Definition: qstr.c:269
struct _qstr_pool_t * prev
Definition: qstr.h:51
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
def data
Definition: i18n.py:176
const byte * qstrs[]
Definition: qstr.h:55
qstr qstr_from_strn(const char *str, size_t len)
Definition: qstr.c:187
byte * qstr_build_start(size_t len, byte **q_ptr)
Definition: qstr.c:246
struct _qstr_pool_t qstr_pool_t
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes)
Definition: qstr.c:289
qstr qstr_find_strn(const char *str, size_t str_len)
Definition: qstr.c:166
size_t len
Definition: qstr.h:54
size_t alloc
Definition: qstr.h:53
size_t qstr
Definition: qstr.h:48
size_t total_prev_len
Definition: qstr.h:52
unsigned char byte
Definition: misc.h:37
qstr qstr_build_end(byte *q_ptr)
Definition: qstr.c:253
void qstr_init(void)
Definition: qstr.c:119
void qstr_dump_data(void)
const byte * qstr_data(qstr q, size_t *len)
Definition: qstr.c:283
qstr qstr_from_str(const char *str)
Definition: qstr.c:183
mp_uint_t qstr_compute_hash(const byte *data, size_t len)
Definition: qstr.c:84
const char * qstr_str(qstr q)
Definition: qstr.c:278
size_t qstr_len(qstr q)
Definition: qstr.c:273