summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-06-28 03:03:47 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-07-09 19:28:24 +0300
commit8215847b4d3bbbf859893db44f6de8a9fdea9f35 (patch)
tree7d8bbf9f219e5ccbda0693b03f335b58d6bd0cf8 /py
parent42b6419056a67a0ea8e28eaf27e51f53bc65eec2 (diff)
downloadmicropython-8215847b4d3bbbf859893db44f6de8a9fdea9f35.tar.gz
micropython-8215847b4d3bbbf859893db44f6de8a9fdea9f35.zip
moductypes: Foreign data interface module, roughly based on ctype ideas.
But much smaller and memory-efficient. Uses Python builtin data structures (dict, tuple, int) to describe structure layout.
Diffstat (limited to 'py')
-rw-r--r--py/builtin.h3
-rw-r--r--py/builtintables.c6
-rw-r--r--py/compile.c3
-rw-r--r--py/mpconfig.h6
-rw-r--r--py/py.mk1
-rw-r--r--py/qstrdefs.h37
6 files changed, 56 insertions, 0 deletions
diff --git a/py/builtin.h b/py/builtin.h
index 2e4d2023d0..361cef604e 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -80,3 +80,6 @@ extern const mp_obj_module_t mp_module_micropython;
extern const mp_obj_module_t mp_module_struct;
extern const mp_obj_module_t mp_module_sys;
extern const mp_obj_module_t mp_module_gc;
+
+// extmod modules
+extern const mp_obj_module_t mp_module_uctypes;
diff --git a/py/builtintables.c b/py/builtintables.c
index c42cdf89bb..ff530b93be 100644
--- a/py/builtintables.c
+++ b/py/builtintables.c
@@ -190,6 +190,12 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_gc), (mp_obj_t)&mp_module_gc },
#endif
+ // extmod modules
+
+#if MICROPY_PY_UCTYPES
+ { MP_OBJ_NEW_QSTR(MP_QSTR_uctypes), (mp_obj_t)&mp_module_uctypes },
+#endif
+
// extra builtin modules as defined by a port
MICROPY_PORT_BUILTIN_MODULES
};
diff --git a/py/compile.c b/py/compile.c
index c5f2166003..e89554a4fc 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -104,6 +104,9 @@ STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const cha
}
STATIC const mp_map_elem_t mp_constants_table[] = {
+ #if MICROPY_PY_UCTYPES
+ { MP_OBJ_NEW_QSTR(MP_QSTR_uctypes), (mp_obj_t)&mp_module_uctypes },
+ #endif
// Extra constants as defined by a port
MICROPY_PORT_CONSTANTS
};
diff --git a/py/mpconfig.h b/py/mpconfig.h
index c04c69c639..99d697f9ad 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -351,6 +351,12 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_STDFILES (0)
#endif
+
+// Extended modules
+#ifndef MICROPY_PY_UCTYPES
+#define MICROPY_PY_UCTYPES (0)
+#endif
+
/*****************************************************************************/
/* Hooks for a port to add builtins */
diff --git a/py/py.mk b/py/py.mk
index 549c35d320..1615c4bbaa 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -102,6 +102,7 @@ PY_O_BASENAME = \
repl.o \
smallint.o \
pfenv.o \
+ ../extmod/moductypes.o
# prepend the build destination prefix to the py object files
PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 6fbfabde67..cb40bdb835 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -363,6 +363,43 @@ Q(pack)
Q(unpack)
#endif
+#if MICROPY_PY_UCTYPES
+Q(uctypes)
+Q(sizeof)
+Q(addressof)
+Q(bytes_at)
+Q(bytearray_at)
+
+Q(NATIVE)
+Q(LITTLE_ENDIAN)
+Q(BIG_ENDIAN)
+
+Q(VOID)
+
+Q(UINT8)
+Q(INT8)
+Q(UINT16)
+Q(INT16)
+Q(UINT32)
+Q(INT32)
+Q(UINT64)
+Q(INT64)
+
+Q(BFUINT8)
+Q(BFINT8)
+Q(BFUINT16)
+Q(BFINT16)
+Q(BFUINT32)
+Q(BFINT32)
+
+Q(FLOAT32)
+Q(FLOAT64)
+
+Q(ARRAY)
+Q(PTR)
+//Q(BITFIELD)
+#endif
+
#if MICROPY_PY_IO
Q(_io)
Q(readall)