aboutsummaryrefslogtreecommitdiff
path: root/py/frozenmod.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-20 11:52:12 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-20 11:52:12 +0200
commit640e0b221e972f9a2da2d870bf3fc5a93c18f0ec (patch)
tree0af9af3d5d8b1bcca3bcbae917e19e8a03a5a82c /py/frozenmod.c
parent438b3d26b5337493dfe345495605fe08ea306bf9 (diff)
py: Implement very simple frozen modules support.
Only modules (not packages) supported now. Source modules can be converted to frozen module structures using tools/make-frozen.py script.
Diffstat (limited to 'py/frozenmod.c')
-rw-r--r--py/frozenmod.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/py/frozenmod.c b/py/frozenmod.c
new file mode 100644
index 000000000..5cb484b8a
--- /dev/null
+++ b/py/frozenmod.c
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Paul Sokolovsky
+ *
+ * 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.
+ */
+
+#include <string.h>
+#include <stdint.h>
+
+#include "py/lexer.h"
+
+#if MICROPY_MODULE_FROZEN
+
+extern const uint16_t mp_frozen_sizes[];
+extern const char mp_frozen_content[];
+
+mp_lexer_t *mp_find_frozen_module(const char *str, int len) {
+ const uint16_t *sz_ptr = mp_frozen_sizes;
+ const char *s = mp_frozen_content;
+
+ while (*sz_ptr) {
+ int l = strlen(s);
+ if (l == len && !memcmp(str, s, l)) {
+ s += l + 1;
+ mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR_, s, *sz_ptr, 0);
+ return lex;
+ }
+ s += l + 1 + *sz_ptr++;
+ }
+ return NULL;
+}
+
+#endif // MICROPY_MODULE_FROZEN