Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Micro Python 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 | |
Chris Angelico | 29bf739 | 2014-06-04 03:15:46 +1000 | [diff] [blame] | 27 | // See qstrdefs.h for a list of qstr's that are available as constants. |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 28 | // Reference them as MP_QSTR_xxxx. |
| 29 | // |
| 30 | // Note: it would be possible to define MP_QSTR_xxx as qstr_from_str_static("xxx") |
| 31 | // for qstrs that are referenced this way, but you don't want to have them in ROM. |
| 32 | |
| 33 | enum { |
| 34 | MP_QSTR_NULL = 0, // indicates invalid/no qstr |
| 35 | MP_QSTR_ = 1, // the empty qstr |
| 36 | #define Q(id, str) MP_QSTR_##id, |
Damien George | d553be5 | 2014-04-17 18:03:27 +0100 | [diff] [blame] | 37 | #include "genhdr/qstrdefs.generated.h" |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 38 | #undef Q |
| 39 | MP_QSTR_number_of, |
Damien George | 2813cb6 | 2014-04-12 17:53:05 +0100 | [diff] [blame] | 40 | }; |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 41 | |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 42 | typedef mp_uint_t qstr; |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 43 | |
| 44 | #define QSTR_FROM_STR_STATIC(s) (qstr_from_strn((s), strlen(s))) |
| 45 | |
| 46 | void qstr_init(void); |
| 47 | |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 48 | mp_uint_t qstr_compute_hash(const byte *data, uint len); |
Damien George | 2617eeb | 2014-05-25 22:27:57 +0100 | [diff] [blame] | 49 | qstr qstr_find_strn(const char *str, uint str_len); // returns MP_QSTR_NULL if not found |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 50 | |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 51 | qstr qstr_from_str(const char *str); |
| 52 | qstr qstr_from_strn(const char *str, uint len); |
| 53 | //qstr qstr_from_str_static(const char *str); |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 54 | //qstr qstr_from_strn_copy(const char *str, int len); |
| 55 | |
| 56 | byte* qstr_build_start(uint len, byte **q_ptr); |
| 57 | qstr qstr_build_end(byte *q_ptr); |
| 58 | |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 59 | mp_uint_t qstr_hash(qstr q); |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 60 | const char* qstr_str(qstr q); |
| 61 | uint qstr_len(qstr q); |
| 62 | const byte* qstr_data(qstr q, uint *len); |
Damien George | 4d5b28c | 2014-01-29 18:56:46 +0000 | [diff] [blame] | 63 | |
| 64 | void qstr_pool_info(uint *n_pool, uint *n_qstr, uint *n_str_data_bytes, uint *n_total_bytes); |