Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
frame.h
00001 /* 00002 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. 00003 # 00004 # This file is part of the PyMite VM. 00005 # The PyMite VM is free software: you can redistribute it and/or modify 00006 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. 00007 # 00008 # The PyMite VM is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 00012 # is seen in the file COPYING in this directory. 00013 */ 00014 00015 00016 #ifndef __FRAME_H__ 00017 #define __FRAME_H__ 00018 00019 00020 /** 00021 * \file 00022 * \brief VM Frame 00023 * 00024 * VM frame header. 00025 */ 00026 00027 00028 /** 00029 * The maximum number of local variables a native function can have. 00030 * This defines the length of the locals array in the native frame struct. 00031 */ 00032 #define NATIVE_MAX_NUM_LOCALS 8 00033 00034 00035 /** 00036 * Block Type 00037 * 00038 * Numerical values to put in the 'b_type' field of the tPmBlockType struct. 00039 */ 00040 typedef enum PmBlockType_e 00041 { 00042 /** Invalid block type */ 00043 B_INVALID = 0, 00044 00045 /** Loop type */ 00046 B_LOOP, 00047 00048 /** Try type */ 00049 B_TRY 00050 } PmBlockType_t, *pPmBlockType_t; 00051 00052 00053 /** 00054 * Block 00055 * 00056 * Extra info for loops and trys (others?) 00057 * Frames use linked list of blocks to handle 00058 * nested loops and try-catch blocks. 00059 */ 00060 typedef struct PmBlock_s 00061 { 00062 /** Obligatory obj descriptor */ 00063 PmObjDesc_t od; 00064 00065 /** Ptr to backup stack ptr */ 00066 pPmObj_t *b_sp; 00067 00068 /** Handler fxn obj */ 00069 uint8_t const *b_handler; 00070 00071 /** Block type */ 00072 PmBlockType_t b_type:8; 00073 00074 /** Next block in stack */ 00075 struct PmBlock_s *next; 00076 } PmBlock_t, 00077 *pPmBlock_t; 00078 00079 00080 /** 00081 * Frame 00082 * 00083 * A struct that holds the execution frame of a function, including the stack, 00084 * local vars and pointer to the code object. 00085 * 00086 * This struct doesn't declare the stack. 00087 * frame_new() is responsible for allocating the extra memory 00088 * at the tail of fo_locals[] to hold both the locals and stack. 00089 */ 00090 typedef struct PmFrame_s 00091 { 00092 /** Obligatory obj descriptor */ 00093 PmObjDesc_t od; 00094 00095 /** Ptr to previous frame obj */ 00096 struct PmFrame_s *fo_back; 00097 00098 /** Ptr to fxn obj */ 00099 pPmFunc_t fo_func; 00100 00101 /** Mem space where func's CO comes from */ 00102 PmMemSpace_t fo_memspace:8; 00103 00104 /** Instrxn ptr (pts into memspace) */ 00105 uint8_t const *fo_ip; 00106 00107 /** Linked list of blocks */ 00108 pPmBlock_t fo_blockstack; 00109 00110 /** Local attributes dict (non-fast locals) */ 00111 pPmDict_t fo_attrs; 00112 00113 /** Global attributes dict (pts to root frame's globals */ 00114 pPmDict_t fo_globals; 00115 00116 /** Points to next empty slot in fo_locals (1 past TOS) */ 00117 pPmObj_t *fo_sp; 00118 00119 /** Frame can be an import-frame that handles RETURN differently */ 00120 uint8_t fo_isImport:1; 00121 00122 #ifdef HAVE_CLASSES 00123 /** Flag to indicate class initailzer frame; handle RETURN differently */ 00124 uint8_t fo_isInit:1; 00125 #endif /* HAVE_CLASSES */ 00126 00127 /** Array of local vars and stack (space appended at alloc) */ 00128 pPmObj_t fo_locals[1]; 00129 /* WARNING: Do not put new fields below fo_locals */ 00130 } PmFrame_t, 00131 *pPmFrame_t; 00132 00133 00134 /** 00135 * Native Frame 00136 * 00137 * A struct that holds the execution frame of a native function, 00138 * including the args and single stack slot, and pointer to the code object. 00139 * 00140 * This struct doesn't need an OD because it is only used statically in the 00141 * globals struct. There's only one native frame, the global one. 00142 * This happens because a native function is a leaf node 00143 * in the call tree (a native func can't call python funcs). 00144 */ 00145 typedef struct PmNativeFrame_s 00146 { 00147 /** Object descriptor */ 00148 PmObjDesc_t od; 00149 00150 /** Ptr to previous frame obj */ 00151 struct PmFrame_s *nf_back; 00152 00153 /** Ptr to fxn obj */ 00154 pPmFunc_t nf_func; 00155 00156 /** Single stack slot */ 00157 pPmObj_t nf_stack; 00158 00159 /** Boolean to indicate if the native frame is active */ 00160 uint8_t nf_active; 00161 00162 /** Number of args passed to the native function */ 00163 uint8_t nf_numlocals; 00164 00165 /** Local vars */ 00166 pPmObj_t nf_locals[NATIVE_MAX_NUM_LOCALS]; 00167 } PmNativeFrame_t, 00168 *pPmNativeFrame_t; 00169 00170 00171 /** 00172 * Allocate space for a new frame, fill its fields 00173 * with respect to the given function object. 00174 * Return pointer to the new frame. 00175 * 00176 * @param pfunc ptr to Function object. 00177 * @param r_pobj Return value; the new frame. 00178 * @return Return status. 00179 */ 00180 PmReturn_t frame_new(pPmObj_t pfunc, pPmObj_t *r_pobj); 00181 00182 #endif /* __FRAME_H__ */
Generated on Tue Jul 12 2022 17:07:01 by
