diff options
| author | Damien George <damien@micropython.org> | 2022-11-11 15:43:48 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-11-11 15:43:48 +1100 |
| commit | ec12cc5ba670d8ac82ca421d0739d61291a82b5e (patch) | |
| tree | e77cf4d9a8f1b74c161434cd1400d8e3c4d73a62 /docs/develop/compiler.rst | |
| parent | 9c9f06ad9dbf49ffd2fe0d336091f4293e403ee7 (diff) | |
docs/develop: Fix mp_compile snippet to match latest code.
Signed-off-by: Damien George <damien.p.george@gmail.com>
Diffstat (limited to 'docs/develop/compiler.rst')
| -rw-r--r-- | docs/develop/compiler.rst | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/docs/develop/compiler.rst b/docs/develop/compiler.rst index 200765749..4b43bc08f 100644 --- a/docs/develop/compiler.rst +++ b/docs/develop/compiler.rst @@ -147,10 +147,15 @@ The most relevant method you should know about is this: .. code-block:: c mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) { + // Create a context for this module, and set its globals dict. + mp_module_context_t *context = m_new_obj(mp_module_context_t); + context->module.globals = mp_globals_get(); + // Compile the input parse_tree to a raw-code structure. - mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, is_repl); + mp_compiled_module_t cm = mp_compile_to_raw_code(parse_tree, source_file, is_repl, context); + // Create and return a function object that executes the outer module. - return mp_make_function_from_raw_code(rc, MP_OBJ_NULL, MP_OBJ_NULL); + return mp_make_function_from_raw_code(cm.rc, cm.context, NULL); } The compiler compiles the code in four passes: scope, stack size, code size and emit. |
