blob: a6d41c160e74d1498ad820a609caacc78ede9821 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
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
Paul Sokolovskyc0abc282014-03-22 13:49:31 +020027// Exception stack entry
28typedef struct _mp_exc_stack {
29 const byte *handler;
30 // bit 0 is saved currently_in_except_block value
Paul Sokolovsky16734202014-03-22 23:20:07 +020031 mp_obj_t *val_sp;
Paul Sokolovsky0c904df2014-03-30 00:48:21 +020032 // Saved exception, valid if currently_in_except_block bit is 1
33 mp_obj_t prev_exc;
Paul Sokolovskyc0abc282014-03-22 13:49:31 +020034 // We might only have 2 interesting cases here: SETUP_EXCEPT & SETUP_FINALLY,
35 // consider storing it in bit 1 of val_sp. TODO: SETUP_WITH?
36 byte opcode;
Damien George89f94b52014-03-30 00:57:09 +000037} mp_exc_stack_t;
Paul Sokolovskyc0abc282014-03-22 13:49:31 +020038
Damien Georgebee17b02014-03-27 11:07:04 +000039mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret);
Damien George89f94b52014-03-30 00:57:09 +000040mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out, mp_exc_stack_t *exc_stack, mp_exc_stack_t **exc_sp_in_out, volatile mp_obj_t inject_exc);
Damien Georgecbd2f742014-01-19 11:48:48 +000041void mp_byte_code_print(const byte *code, int len);
Paul Sokolovskyc5e32c62014-04-23 03:40:24 +030042void mp_byte_code_print2(const byte *code, int len);
Paul Sokolovsky16734202014-03-22 23:20:07 +020043
44// Helper macros to access pointer with least significant bit holding a flag
45#define MP_TAGPTR_PTR(x) ((void*)((machine_uint_t)(x) & ~((machine_uint_t)1)))
46#define MP_TAGPTR_TAG(x) ((machine_uint_t)(x) & 1)
47#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((machine_uint_t)(ptr) | tag))