summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-01 23:30:53 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-07 20:33:00 +0000
commitb4b10fd350852e321624d74983cca286091b55a1 (patch)
tree7ac4aa40d70be0170a61f649e9d73c42faa4ba33 /unix
parentad2307c92c15f0aa90dbd0741fd2538719d0b5e1 (diff)
downloadmicropython-b4b10fd350852e321624d74983cca286091b55a1.tar.gz
micropython-b4b10fd350852e321624d74983cca286091b55a1.zip
py: Put all global state together in state structures.
This patch consolidates all global variables in py/ core into one place, in a global structure. Root pointers are all located together to make GC tracing easier and more efficient.
Diffstat (limited to 'unix')
-rw-r--r--unix/gccollect.c15
-rw-r--r--unix/main.c15
-rw-r--r--unix/mpconfigport.h3
3 files changed, 12 insertions, 21 deletions
diff --git a/unix/gccollect.c b/unix/gccollect.c
index ab20220d3f..f8bcbf965d 100644
--- a/unix/gccollect.c
+++ b/unix/gccollect.c
@@ -26,6 +26,7 @@
#include <stdio.h>
+#include "py/mpstate.h"
#include "py/gc.h"
#if MICROPY_ENABLE_GC
@@ -127,23 +128,11 @@ void gc_collect(void) {
//gc_dump_info();
gc_collect_start();
- // this traces the .bss section
-#if defined( __CYGWIN__ )
-#define BSS_START __bss_start__
-#elif defined( _MSC_VER ) || defined( __MINGW32__ )
-#define BSS_START *bss_start
-#define _end *bss_end
-#else
-#define BSS_START __bss_start
-#endif
- extern char BSS_START, _end;
- //printf(".bss: %p-%p\n", &BSS_START, &_end);
- gc_collect_root((void**)&BSS_START, ((mp_uint_t)&_end - (mp_uint_t)&BSS_START) / sizeof(mp_uint_t));
regs_t regs;
gc_helper_get_regs(regs);
// GC stack (and regs because we captured them)
void **regs_ptr = (void**)(void*)&regs;
- gc_collect_root(regs_ptr, ((mp_uint_t)stack_top - (mp_uint_t)&regs) / sizeof(mp_uint_t));
+ gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_VM(stack_top) - (mp_uint_t)&regs) / sizeof(mp_uint_t));
gc_collect_end();
//printf("-----\n");
diff --git a/unix/main.c b/unix/main.c
index 0f1e26f51c..3dd71eff8c 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <errno.h>
+#include "py/mpstate.h"
#include "py/nlr.h"
#include "py/compile.h"
#include "py/parsehelper.h"
@@ -61,12 +62,10 @@ long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4);
#ifndef _WIN32
#include <signal.h>
-STATIC mp_obj_t keyboard_interrupt_obj;
-
STATIC void sighandler(int signum) {
if (signum == SIGINT) {
- mp_obj_exception_clear_traceback(keyboard_interrupt_obj);
- mp_pending_exception = keyboard_interrupt_obj;
+ mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj));
+ MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(keyboard_interrupt_obj);
// disable our handler so next we really die
struct sigaction sa;
sa.sa_handler = SIG_DFL;
@@ -336,7 +335,7 @@ int main(int argc, char **argv) {
#ifndef _WIN32
// create keyboard interrupt object
- keyboard_interrupt_obj = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
+ MP_STATE_VM(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
#endif
char *home = getenv("HOME");
@@ -448,10 +447,10 @@ int main(int argc, char **argv) {
mp_verbose_flag++;
} else if (strncmp(argv[a], "-O", 2) == 0) {
if (isdigit(argv[a][2])) {
- mp_optimise_value = argv[a][2] & 0xf;
+ MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf;
} else {
- mp_optimise_value = 0;
- for (char *p = argv[a] + 1; *p && *p == 'O'; p++, mp_optimise_value++);
+ MP_STATE_VM(mp_optimise_value) = 0;
+ for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++);
}
} else {
return usage(argv);
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index fc2a18278f..8918dfc516 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -153,6 +153,9 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+#define MICROPY_PORT_ROOT_POINTERS \
+ mp_obj_t keyboard_interrupt_obj;
+
// We need to provide a declaration/definition of alloca()
#ifdef __FreeBSD__
#include <stdlib.h>