2014-05-03 23:27:38 +01:00
|
|
|
/*
|
2017-06-30 09:22:17 +02:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 23:27:38 +01:00
|
|
|
*
|
|
|
|
|
* The MIT License (MIT)
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
|
|
|
|
*/
|
2017-06-29 23:14:58 +02:00
|
|
|
#ifndef MICROPY_INCLUDED_PY_QSTR_H
|
|
|
|
|
#define MICROPY_INCLUDED_PY_QSTR_H
|
2014-12-29 01:02:19 +00:00
|
|
|
|
|
|
|
|
#include "py/mpconfig.h"
|
|
|
|
|
#include "py/misc.h"
|
2014-05-03 23:27:38 +01:00
|
|
|
|
2014-06-04 03:15:46 +10:00
|
|
|
// See qstrdefs.h for a list of qstr's that are available as constants.
|
2014-01-21 21:40:13 +00:00
|
|
|
// Reference them as MP_QSTR_xxxx.
|
|
|
|
|
//
|
2021-01-16 09:18:31 +01:00
|
|
|
// Note: it would be possible to define MP_QSTR_xxx as qstr_from_str("xxx")
|
2014-01-21 21:40:13 +00:00
|
|
|
// for qstrs that are referenced this way, but you don't want to have them in ROM.
|
|
|
|
|
|
2019-09-25 17:53:30 +12:00
|
|
|
// first entry in enum will be MP_QSTRnull=0, which indicates invalid/no qstr
|
2014-01-21 21:40:13 +00:00
|
|
|
enum {
|
2020-02-27 15:36:53 +11:00
|
|
|
#ifndef NO_QSTR
|
2015-01-11 17:52:45 +00:00
|
|
|
#define QDEF(id, str) id,
|
2020-02-27 15:36:53 +11:00
|
|
|
#include "genhdr/qstrdefs.generated.h"
|
2015-01-11 17:52:45 +00:00
|
|
|
#undef QDEF
|
2020-02-27 15:36:53 +11:00
|
|
|
#endif
|
2016-01-31 22:24:16 +00:00
|
|
|
MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
|
2014-04-12 17:53:05 +01:00
|
|
|
};
|
2014-01-21 21:40:13 +00:00
|
|
|
|
2015-12-17 12:45:22 +00:00
|
|
|
typedef size_t qstr;
|
2014-01-21 21:40:13 +00:00
|
|
|
|
2015-01-01 23:30:53 +00:00
|
|
|
typedef struct _qstr_pool_t {
|
|
|
|
|
struct _qstr_pool_t *prev;
|
2015-12-17 12:41:40 +00:00
|
|
|
size_t total_prev_len;
|
|
|
|
|
size_t alloc;
|
|
|
|
|
size_t len;
|
2015-01-01 23:30:53 +00:00
|
|
|
const byte *qstrs[];
|
|
|
|
|
} qstr_pool_t;
|
|
|
|
|
|
2018-02-15 18:12:01 +11:00
|
|
|
#define QSTR_TOTAL() (MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len)
|
2014-01-21 21:40:13 +00:00
|
|
|
|
|
|
|
|
void qstr_init(void);
|
|
|
|
|
|
2015-11-27 12:23:18 +00:00
|
|
|
mp_uint_t qstr_compute_hash(const byte *data, size_t len);
|
2019-09-25 17:53:30 +12:00
|
|
|
qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTRnull if not found
|
2014-01-22 14:35:10 +00:00
|
|
|
|
2014-01-21 21:40:13 +00:00
|
|
|
qstr qstr_from_str(const char *str);
|
2015-11-27 12:23:18 +00:00
|
|
|
qstr qstr_from_strn(const char *str, size_t len);
|
2014-01-21 21:40:13 +00:00
|
|
|
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_uint_t qstr_hash(qstr q);
|
2015-04-04 15:53:11 +01:00
|
|
|
const char *qstr_str(qstr q);
|
2015-11-27 12:23:18 +00:00
|
|
|
size_t qstr_len(qstr q);
|
|
|
|
|
const byte *qstr_data(qstr q, size_t *len);
|
2014-01-29 18:56:46 +00:00
|
|
|
|
2015-12-17 12:41:40 +00:00
|
|
|
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes);
|
2015-02-10 11:02:28 +00:00
|
|
|
void qstr_dump_data(void);
|
2014-12-29 01:02:19 +00:00
|
|
|
|
2019-09-26 22:19:29 +10:00
|
|
|
#if MICROPY_ROM_TEXT_COMPRESSION
|
|
|
|
|
void mp_decompress_rom_string(byte *dst, mp_rom_error_text_t src);
|
|
|
|
|
#define MP_IS_COMPRESSED_ROM_STRING(s) (*(byte *)(s) == 0xff)
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-29 23:14:58 +02:00
|
|
|
#endif // MICROPY_INCLUDED_PY_QSTR_H
|