2 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
4 # This file is part of the PyMite VM.
5 # The PyMite VM is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
8 # The PyMite VM is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
12 # is seen in the file COPYING in this directory.
29 * The maximum number of local variables a native function can have.
30 * This defines the length of the locals array in the native frame struct.
32 #define NATIVE_MAX_NUM_LOCALS 8
38 * Numerical values to put in the 'b_type' field of the tPmBlockType struct.
40 typedef enum PmBlockType_e
42 /** Invalid block type */
50 } PmBlockType_t
, *pPmBlockType_t
;
56 * Extra info for loops and trys (others?)
57 * Frames use linked list of blocks to handle
58 * nested loops and try-catch blocks.
60 typedef struct PmBlock_s
62 /** Obligatory obj descriptor */
65 /** Ptr to backup stack ptr */
68 /** Handler fxn obj */
69 uint8_t const *b_handler
;
72 PmBlockType_t b_type
:8;
74 /** Next block in stack */
75 struct PmBlock_s
*next
;
83 * A struct that holds the execution frame of a function, including the stack,
84 * local vars and pointer to the code object.
86 * This struct doesn't declare the stack.
87 * frame_new() is responsible for allocating the extra memory
88 * at the tail of fo_locals[] to hold both the locals and stack.
90 typedef struct PmFrame_s
92 /** Obligatory obj descriptor */
95 /** Ptr to previous frame obj */
96 struct PmFrame_s
*fo_back
;
101 /** Mem space where func's CO comes from */
102 PmMemSpace_t fo_memspace
:8;
104 /** Instrxn ptr (pts into memspace) */
105 uint8_t const *fo_ip
;
107 /** Linked list of blocks */
108 pPmBlock_t fo_blockstack
;
110 /** Local attributes dict (non-fast locals) */
113 /** Global attributes dict (pts to root frame's globals */
114 pPmDict_t fo_globals
;
116 /** Points to next empty slot in fo_locals (1 past TOS) */
119 /** Frame can be an import-frame that handles RETURN differently */
120 uint8_t fo_isImport
:1;
123 /** Flag to indicate class initailzer frame; handle RETURN differently */
125 #endif /* HAVE_CLASSES */
127 /** Array of local vars and stack (space appended at alloc) */
128 pPmObj_t fo_locals
[1];
129 /* WARNING: Do not put new fields below fo_locals */
137 * A struct that holds the execution frame of a native function,
138 * including the args and single stack slot, and pointer to the code object.
140 * This struct doesn't need an OD because it is only used statically in the
141 * globals struct. There's only one native frame, the global one.
142 * This happens because a native function is a leaf node
143 * in the call tree (a native func can't call python funcs).
145 typedef struct PmNativeFrame_s
147 /** Object descriptor */
150 /** Ptr to previous frame obj */
151 struct PmFrame_s
*nf_back
;
153 /** Ptr to fxn obj */
156 /** Single stack slot */
159 /** Boolean to indicate if the native frame is active */
162 /** Number of args passed to the native function */
163 uint8_t nf_numlocals
;
166 pPmObj_t nf_locals
[NATIVE_MAX_NUM_LOCALS
];
172 * Allocate space for a new frame, fill its fields
173 * with respect to the given function object.
174 * Return pointer to the new frame.
176 * @param pfunc ptr to Function object.
177 * @param r_pobj Return value; the new frame.
178 * @return Return status.
180 PmReturn_t
frame_new(pPmObj_t pfunc
, pPmObj_t
*r_pobj
);
182 #endif /* __FRAME_H__ */