summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-07 14:54:15 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-07 14:54:15 +0000
commit136f67523b10d24dd65cb25e49e07a7e4e5341a1 (patch)
tree95a8e704f85c3813735d287afccc74a6df172f29 /py
parent880ce2d7fabc127b4bca7b6f2ea8b82d0977045f (diff)
downloadmicropython-136f67523b10d24dd65cb25e49e07a7e4e5341a1.tar.gz
micropython-136f67523b10d24dd65cb25e49e07a7e4e5341a1.zip
Factor and simplify Makefile's and mpconfig.
Diffstat (limited to 'py')
-rw-r--r--py/mpconfig.h70
-rw-r--r--py/py.mk100
-rw-r--r--py/repl.c5
-rw-r--r--py/repl.h2
4 files changed, 163 insertions, 14 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 56495d9156..8ce432a61e 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -4,26 +4,52 @@
#include <mpconfigport.h>
-#ifndef INT_FMT
-// printf format spec to use for machine_int_t and friends
-#ifdef __LP64__
-// Archs where machine_int_t == long, long != int
-#define UINT_FMT "%lu"
-#define INT_FMT "%ld"
-#else
-// Archs where machine_int_t == int
-#define UINT_FMT "%u"
-#define INT_FMT "%d"
+// Any options not explicitly set in mpconfigport.h will get default
+// values below.
+
+/*****************************************************************************/
+/* Micro Python emitters */
+
+// Whether to emit CPython byte codes (for debugging/testing)
+// Enabling this overrides all other emitters
+#ifndef MICROPY_EMIT_CPYTHON
+#define MICROPY_EMIT_CPYTHON (0)
+#endif
+
+// Whether to emit x64 native code
+#ifndef MICROPY_EMIT_X64
+#define MICROPY_EMIT_X64 (0)
#endif
-#endif //INT_FMT
+// Whether to emit thumb native code
+#ifndef MICROPY_EMIT_THUMB
+#define MICROPY_EMIT_THUMB (0)
+#endif
-// Any options not explicitly set in mpconfigport.h will get default
-// values below.
+// Whether to enable the thumb inline assembler
+#ifndef MICROPY_EMIT_INLINE_THUMB
+#define MICROPY_EMIT_INLINE_THUMB (0)
+#endif
+
+/*****************************************************************************/
+/* Internal debugging stuff */
// Whether to collect memory allocation stats
#ifndef MICROPY_MEM_STATS
-#define MICROPY_MEM_STATS (1)
+#define MICROPY_MEM_STATS (0)
+#endif
+
+/*****************************************************************************/
+/* Fine control over Python features */
+
+// Whether to include REPL helper function
+#ifndef MICROPY_ENABLE_REPL_HELPERS
+#define MICROPY_ENABLE_REPL_HELPERS (0)
+#endif
+
+// Whether to support float and complex types
+#ifndef MICROPY_ENABLE_FLOAT
+#define MICROPY_ENABLE_FLOAT (0)
#endif
// Whether to support slice object and correspondingly
@@ -31,3 +57,19 @@
#ifndef MICROPY_ENABLE_SLICE
#define MICROPY_ENABLE_SLICE (1)
#endif
+
+/*****************************************************************************/
+/* Miscellaneous settings */
+
+// printf format spec to use for machine_int_t and friends
+#ifndef INT_FMT
+#ifdef __LP64__
+// Archs where machine_int_t == long, long != int
+#define UINT_FMT "%lu"
+#define INT_FMT "%ld"
+#else
+// Archs where machine_int_t == int
+#define UINT_FMT "%u"
+#define INT_FMT "%d"
+#endif
+#endif //INT_FMT
diff --git a/py/py.mk b/py/py.mk
new file mode 100644
index 0000000000..e673c713c7
--- /dev/null
+++ b/py/py.mk
@@ -0,0 +1,100 @@
+# default settings; can be overriden in main Makefile
+
+ifndef PY_SRC
+PY_SRC = ../py
+endif
+
+ifndef BUILD
+BUILD = build
+endif
+
+# to create the build directory
+
+$(BUILD):
+ mkdir -p $@
+
+# where py object files go (they have a name prefix to prevent filename clashes)
+
+PY_BUILD = $(BUILD)/py.
+
+# py object files
+
+PY_O_BASENAME = \
+ nlrx86.o \
+ nlrx64.o \
+ nlrthumb.o \
+ malloc.o \
+ qstr.o \
+ vstr.o \
+ unicode.o \
+ lexer.o \
+ lexerunix.o \
+ parse.o \
+ scope.o \
+ compile.o \
+ emitcommon.o \
+ emitpass1.o \
+ emitcpy.o \
+ emitbc.o \
+ asmx64.o \
+ emitnx64.o \
+ asmthumb.o \
+ emitnthumb.o \
+ emitinlinethumb.o \
+ runtime.o \
+ map.o \
+ obj.o \
+ objbool.o \
+ objboundmeth.o \
+ objcell.o \
+ objclass.o \
+ objclosure.o \
+ objcomplex.o \
+ objdict.o \
+ objexcept.o \
+ objfloat.o \
+ objfun.o \
+ objgenerator.o \
+ objinstance.o \
+ objint.o \
+ objlist.o \
+ objmodule.o \
+ objnone.o \
+ objrange.o \
+ objset.o \
+ objslice.o \
+ objstr.o \
+ objtuple.o \
+ objtype.o \
+ builtin.o \
+ builtinimport.o \
+ vm.o \
+ showbc.o \
+ repl.o \
+
+# prepend the build destination prefix to the py object files
+
+PY_O = $(addprefix $(PY_BUILD), $(PY_O_BASENAME))
+
+$(PY_BUILD)emitnx64.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h
+ $(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
+
+$(PY_BUILD)emitnthumb.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h
+ $(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
+
+$(PY_BUILD)%.o: $(PY_SRC)/%.S
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+$(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
+$(PY_BUILD)vm.o: $(PY_SRC)/vm.c
+ $(CC) $(CFLAGS) -O3 -c -o $@ $<
+
+# header dependencies
+
+$(PY_BUILD)parse.o: $(PY_SRC)/grammar.h
+$(PY_BUILD)compile.o: $(PY_SRC)/grammar.h
+$(PY_BUILD)/emitcpy.o: $(PY_SRC)/emit.h
+$(PY_BUILD)emitbc.o: $(PY_SRC)/emit.h
diff --git a/py/repl.c b/py/repl.c
index 4241ef0e4c..473313c1ef 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -1,6 +1,9 @@
#include "misc.h"
+#include "mpconfig.h"
#include "repl.h"
+#if MICROPY_ENABLE_REPL_HELPERS
+
bool str_startswith_word(const char *str, const char *head) {
int i;
for (i = 0; str[i] && head[i]; i++) {
@@ -42,3 +45,5 @@ bool mp_repl_is_compound_stmt(const char *line) {
}
return n_paren > 0 || n_brack > 0 || n_brace > 0;
}
+
+#endif // MICROPY_ENABLE_REPL_HELPERS
diff --git a/py/repl.h b/py/repl.h
index 02fe523ed4..23259fa90d 100644
--- a/py/repl.h
+++ b/py/repl.h
@@ -1 +1,3 @@
+#if MICROPY_ENABLE_REPL_HELPERS
bool mp_repl_is_compound_stmt(const char *line);
+#endif