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.
diff --git a/py/runtime.h b/py/runtime.h
index 711b15f..7a9c6ee 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -26,6 +26,7 @@
#ifndef __MICROPY_INCLUDED_PY_RUNTIME_H__
#define __MICROPY_INCLUDED_PY_RUNTIME_H__
+#include "py/mpstate.h"
#include "py/obj.h"
typedef enum {
@@ -64,10 +65,10 @@
NORETURN void mp_arg_error_terse_mismatch(void);
NORETURN void mp_arg_error_unimpl_kw(void);
-mp_obj_dict_t *mp_locals_get(void);
-void mp_locals_set(mp_obj_dict_t *d);
-mp_obj_dict_t *mp_globals_get(void);
-void mp_globals_set(mp_obj_dict_t *d);
+static inline mp_obj_dict_t *mp_locals_get(void) { return MP_STATE_CTX(dict_locals); }
+static inline void mp_locals_set(mp_obj_dict_t *d) { MP_STATE_CTX(dict_locals) = d; }
+static inline mp_obj_dict_t *mp_globals_get(void) { return MP_STATE_CTX(dict_globals); }
+static inline void mp_globals_set(mp_obj_dict_t *d) { MP_STATE_CTX(dict_globals) = d; }
mp_obj_t mp_load_name(qstr qstr);
mp_obj_t mp_load_global(qstr qstr);
@@ -120,7 +121,6 @@
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, const mp_obj_t *args);
NORETURN void mp_native_raise(mp_obj_t o);
-extern mp_obj_t mp_pending_exception;
extern struct _mp_obj_list_t mp_sys_path_obj;
extern struct _mp_obj_list_t mp_sys_argv_obj;
#define mp_sys_path ((mp_obj_t)&mp_sys_path_obj)