summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/asmx64.c8
-rw-r--r--py/gc.c4
-rw-r--r--py/lexerunix.c5
-rw-r--r--py/mpconfig.h15
-rw-r--r--py/py.mk5
-rw-r--r--py/showbc.c4
6 files changed, 38 insertions, 3 deletions
diff --git a/py/asmx64.c b/py/asmx64.c
index 226d4efee8..d3158170fb 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -1,16 +1,18 @@
#include <stdio.h>
#include <assert.h>
-#include <sys/types.h>
-#include <sys/mman.h>
#include <string.h>
#include "misc.h"
-#include "asmx64.h"
#include "mpconfig.h"
// wrapper around everything in this file
#if MICROPY_EMIT_X64
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include "asmx64.h"
+
#if defined(__OpenBSD__) || defined(__MACH__)
#define MAP_ANONYMOUS MAP_ANON
#endif
diff --git a/py/gc.c b/py/gc.c
index 7d4cac6e74..054a3cc315 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -6,6 +6,8 @@
#include "mpconfig.h"
#include "gc.h"
+#if MICROPY_ENABLE_GC
+
// a machine word is big enough to hold a pointer
/*
#define BYTES_PER_WORD (8)
@@ -380,3 +382,5 @@ int main(void) {
gc_dump_at();
}
*/
+
+#endif // MICROPY_ENABLE_GC
diff --git a/py/lexerunix.c b/py/lexerunix.c
index 14c28c16d9..5336610bae 100644
--- a/py/lexerunix.c
+++ b/py/lexerunix.c
@@ -4,8 +4,11 @@
#include <fcntl.h>
#include "misc.h"
+#include "mpconfig.h"
#include "lexer.h"
+#if MICROPY_ENABLE_LEXER_UNIX
+
typedef struct _str_buf_t {
bool free; // free src_beg when done
const char *src_beg; // beginning of source
@@ -78,3 +81,5 @@ mp_lexer_t *mp_import_open_file(qstr mod_name) {
vstr_printf(vstr, "%s.py", qstr_str(mod_name));
return mp_lexer_new_from_file(vstr_str(vstr)); // TODO does lexer need to copy the string? can we free it here?
}
+
+#endif // MICROPY_ENABLE_LEXER_UNIX
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 8ce432a61e..2017ba366a 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -39,14 +39,29 @@
#define MICROPY_MEM_STATS (0)
#endif
+// Whether to build code to show byte code
+#ifndef MICROPY_SHOW_BC
+#define MICROPY_SHOW_BC (0)
+#endif
+
/*****************************************************************************/
/* Fine control over Python features */
+// Whether to include the garbage collector
+#ifndef MICROPY_ENABLE_GC
+#define MICROPY_ENABLE_GC (0)
+#endif
+
// Whether to include REPL helper function
#ifndef MICROPY_ENABLE_REPL_HELPERS
#define MICROPY_ENABLE_REPL_HELPERS (0)
#endif
+// Whether to include lexer helper function for unix
+#ifndef MICROPY_ENABLE_LEXER_UNIX
+#define MICROPY_ENABLE_LEXER_UNIX (0)
+#endif
+
// Whether to support float and complex types
#ifndef MICROPY_ENABLE_FLOAT
#define MICROPY_ENABLE_FLOAT (0)
diff --git a/py/py.mk b/py/py.mk
index e673c713c7..3ed8a3e3d7 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -24,6 +24,7 @@ PY_O_BASENAME = \
nlrx64.o \
nlrthumb.o \
malloc.o \
+ gc.o \
qstr.o \
vstr.o \
unicode.o \
@@ -88,6 +89,10 @@ $(PY_BUILD)%.o: $(PY_SRC)/%.S
$(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h
$(CC) $(CFLAGS) -c -o $@ $<
+# optimising gc for speed; 5ms down to 4ms on pybv2
+$(PY_BUILD)gc.o: $(PY_SRC)/gc.c
+ $(CC) $(CFLAGS) -O3 -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 $@ $<
diff --git a/py/showbc.c b/py/showbc.c
index eb7d41b24d..aea0aff67a 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -8,6 +8,8 @@
#include "mpconfig.h"
#include "bc0.h"
+#if MICROPY_SHOW_BC
+
#define DECODE_UINT do { unum = *ip++; if (unum > 127) { unum = ((unum & 0x3f) << 8) | (*ip++); } } while (0)
#define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0)
#define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0)
@@ -363,3 +365,5 @@ void mp_show_byte_code(const byte *ip, int len) {
printf("\n");
}
}
+
+#endif // MICROPY_SHOW_BC