Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013, 2014 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Damien George | 2326d52 | 2014-03-27 23:26:35 +0000 | [diff] [blame] | 27 | // These variables and functions glue the code emitters to the runtime. |
| 28 | |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 29 | typedef enum { |
| 30 | MP_CODE_UNUSED, |
| 31 | MP_CODE_RESERVED, |
Damien George | ccc85ea | 2014-05-10 13:40:46 +0100 | [diff] [blame] | 32 | MP_CODE_BYTECODE, |
| 33 | MP_CODE_NATIVE_PY, |
| 34 | MP_CODE_NATIVE_VIPER, |
| 35 | MP_CODE_NATIVE_ASM, |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 36 | } mp_raw_code_kind_t; |
| 37 | |
| 38 | typedef struct _mp_code_t { |
Damien George | 2827d62 | 2014-04-27 15:50:52 +0100 | [diff] [blame] | 39 | mp_raw_code_kind_t kind : 3; |
| 40 | uint scope_flags : 7; |
| 41 | uint n_pos_args : 11; |
| 42 | uint n_kwonly_args : 11; |
| 43 | qstr *arg_names; |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 44 | union { |
| 45 | struct { |
| 46 | byte *code; |
| 47 | uint len; |
| 48 | } u_byte; |
| 49 | struct { |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 50 | void *fun; |
Damien George | ccc85ea | 2014-05-10 13:40:46 +0100 | [diff] [blame] | 51 | } u_native; |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 52 | }; |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 53 | } mp_raw_code_t; |
| 54 | |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 55 | mp_raw_code_t *mp_emit_glue_new_raw_code(void); |
| 56 | |
Damien George | 3417bc2 | 2014-05-10 10:36:38 +0100 | [diff] [blame] | 57 | void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, uint len, uint n_pos_args, uint n_kwonly_args, qstr *arg_names, uint scope_flags); |
Damien George | ccc85ea | 2014-05-10 13:40:46 +0100 | [diff] [blame] | 58 | void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *f, uint len, int n_args); |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 59 | |
| 60 | mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args); |
Damien George | 3558f62 | 2014-04-20 17:50:40 +0100 | [diff] [blame] | 61 | mp_obj_t mp_make_closure_from_raw_code(mp_raw_code_t *rc, uint n_closed_over, const mp_obj_t *args); |