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 | */ |
Paul Sokolovsky | 8ab6f90 | 2014-12-25 23:29:19 +0200 | [diff] [blame] | 26 | #ifndef __MICROPY_INCLUDED_PY_EMITGLUE_H__ |
| 27 | #define __MICROPY_INCLUDED_PY_EMITGLUE_H__ |
Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 28 | |
Damien George | 51dfcb4 | 2015-01-01 20:27:54 +0000 | [diff] [blame] | 29 | #include "py/obj.h" |
| 30 | |
Damien George | 2326d52 | 2014-03-27 23:26:35 +0000 | [diff] [blame] | 31 | // These variables and functions glue the code emitters to the runtime. |
| 32 | |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 33 | typedef enum { |
| 34 | MP_CODE_UNUSED, |
| 35 | MP_CODE_RESERVED, |
Damien George | ccc85ea | 2014-05-10 13:40:46 +0100 | [diff] [blame] | 36 | MP_CODE_BYTECODE, |
| 37 | MP_CODE_NATIVE_PY, |
| 38 | MP_CODE_NATIVE_VIPER, |
| 39 | MP_CODE_NATIVE_ASM, |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 40 | } mp_raw_code_kind_t; |
| 41 | |
Damien George | 32444b7 | 2015-01-24 23:14:12 +0000 | [diff] [blame] | 42 | typedef struct _mp_raw_code_t mp_raw_code_t; |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 43 | |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 44 | mp_raw_code_t *mp_emit_glue_new_raw_code(void); |
| 45 | |
Damien George | d8c834c | 2015-11-02 21:55:42 +0000 | [diff] [blame] | 46 | void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, mp_uint_t len, |
| 47 | const mp_uint_t *const_table, |
| 48 | #if MICROPY_PERSISTENT_CODE_SAVE |
| 49 | uint16_t n_obj, uint16_t n_raw_code, |
| 50 | #endif |
| 51 | mp_uint_t scope_flags); |
Damien George | 713ea18 | 2015-10-23 01:23:11 +0100 | [diff] [blame] | 52 | void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table, mp_uint_t n_pos_args, mp_uint_t scope_flags, mp_uint_t type_sig); |
Damien George | df8127a | 2014-04-13 11:04:33 +0100 | [diff] [blame] | 53 | |
| 54 | 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 | 3c658a4 | 2014-08-24 16:28:17 +0100 | [diff] [blame] | 55 | mp_obj_t mp_make_closure_from_raw_code(mp_raw_code_t *rc, mp_uint_t n_closed_over, const mp_obj_t *args); |
Paul Sokolovsky | 8ab6f90 | 2014-12-25 23:29:19 +0200 | [diff] [blame] | 56 | |
Damien George | d8c834c | 2015-11-02 21:55:42 +0000 | [diff] [blame] | 57 | #if MICROPY_PERSISTENT_CODE_LOAD |
| 58 | typedef struct _mp_reader_t { |
| 59 | void *data; |
| 60 | mp_uint_t (*read_byte)(void *data); |
| 61 | void (*close)(void *data); |
| 62 | } mp_reader_t; |
| 63 | |
| 64 | mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader); |
Damien George | b5b1f2c | 2015-11-20 12:44:20 +0000 | [diff] [blame] | 65 | mp_raw_code_t *mp_raw_code_load_mem(const byte *buf, size_t len); |
Damien George | d8c834c | 2015-11-02 21:55:42 +0000 | [diff] [blame] | 66 | mp_raw_code_t *mp_raw_code_load_file(const char *filename); |
| 67 | #endif |
| 68 | |
| 69 | #if MICROPY_PERSISTENT_CODE_SAVE |
| 70 | void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print); |
| 71 | void mp_raw_code_save_file(mp_raw_code_t *rc, const char *filename); |
| 72 | #endif |
| 73 | |
Paul Sokolovsky | 8ab6f90 | 2014-12-25 23:29:19 +0200 | [diff] [blame] | 74 | #endif // __MICROPY_INCLUDED_PY_EMITGLUE_H__ |