aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2014-04-14 21:20:30 +0100
committerDamien George2014-04-14 21:20:30 +0100
commit3bb8bd899b2b1e5970b5ceb822bdf3df9b2e2d13 (patch)
tree0396642ad4a39c2de561330b02b4ae1d6e9fc5b5
parent0ae9c7042ae0839cea575955f36af280943cb99f (diff)
Make USE_COMPUTED_GOTO a config option in mpconfig.h.
Disabled by default. Enabled in unix port.
-rw-r--r--py/mpconfig.h6
-rw-r--r--py/objstr.c2
-rw-r--r--py/vm.c6
-rw-r--r--unix/Makefile2
-rw-r--r--unix/mpconfigport.h1
5 files changed, 12 insertions, 5 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index f9c02a6f0..8f60c997b 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -154,6 +154,12 @@ typedef double mp_float_t;
#define MICROPY_PATH_MAX (512)
#endif
+// Whether to use computed gotos in the VM, or a switch
+// Computed gotos are roughly 10% faster, and increase VM code size by a little
+#ifndef MICROPY_USE_COMPUTED_GOTO
+#define MICROPY_USE_COMPUTED_GOTO (0)
+#endif
+
// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
#ifndef MICROPY_EXTRA_BUILTINS
#define MICROPY_EXTRA_BUILTINS
diff --git a/py/objstr.c b/py/objstr.c
index 08db2af66..fc1e1c569 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -662,7 +662,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
if (arg_i > 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from automatic field numbering to manual field specification"));
}
- int index;
+ int index = 0;
if (str_to_int(vstr_str(field_name), &index) != vstr_len(field_name) - 1) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "attributes not supported yet"));
}
diff --git a/py/vm.c b/py/vm.c
index f928ad694..6c117c7cb 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -167,7 +167,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
volatile mp_obj_t inject_exc) {
// careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think)
-#ifdef MICROPY_USE_COMPUTED_GOTO
+#if MICROPY_USE_COMPUTED_GOTO
# define DISPATCH() do { \
save_ip = ip; \
@@ -299,7 +299,7 @@ outer_dispatch_loop:
// loop to execute byte code
for (;;) {
dispatch_loop:
-#ifdef MICROPY_USE_COMPUTED_GOTO
+#if MICROPY_USE_COMPUTED_GOTO
DISPATCH();
#else
save_ip = ip;
@@ -1005,7 +1005,7 @@ yield:
nlr_pop();
fastn[0] = obj1;
return MP_VM_RETURN_EXCEPTION;
-#ifndef MICROPY_USE_COMPUTED_GOTO
+#if !MICROPY_USE_COMPUTED_GOTO
}
#endif
}
diff --git a/unix/Makefile b/unix/Makefile
index 64f5a6cf1..ac1baf3d0 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -11,7 +11,7 @@ QSTR_DEFS = qstrdefsport.h
include ../py/py.mk
# compiler settings
-CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -DMICROPY_USE_COMPUTED_GOTO
+CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index fe35e5b09..75f119e91 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -14,6 +14,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_PATH_MAX (PATH_MAX)
+#define MICROPY_USE_COMPUTED_GOTO (1)
#define MICROPY_MOD_SYS_STDFILES (1)
// type definitions for the specific machine