Norimasa Okamoto
/
pymite
python-on-a-chip online compiler
- http://pymbed.appspot.com/
- https://code.google.com/p/python-on-a-chip/
- http://www.youtube.com/watch?v=Oyqc2bFRW9I
- https://bitbucket.org/va009039/pymbed/
more info: python-on-a-chip
vm/interp.h@0:65f1469d6bfb, 2013-03-02 (annotated)
- Committer:
- va009039
- Date:
- Sat Mar 02 11:54:20 2013 +0000
- Revision:
- 0:65f1469d6bfb
- Child:
- 1:28afb064a41c
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:65f1469d6bfb | 1 | /* |
va009039 | 0:65f1469d6bfb | 2 | # This file is Copyright 2002 Dean Hall. |
va009039 | 0:65f1469d6bfb | 3 | # This file is part of the PyMite VM. |
va009039 | 0:65f1469d6bfb | 4 | # This file is licensed under the MIT License. |
va009039 | 0:65f1469d6bfb | 5 | # See the LICENSE file for details. |
va009039 | 0:65f1469d6bfb | 6 | */ |
va009039 | 0:65f1469d6bfb | 7 | |
va009039 | 0:65f1469d6bfb | 8 | |
va009039 | 0:65f1469d6bfb | 9 | #ifndef __INTERP_H__ |
va009039 | 0:65f1469d6bfb | 10 | #define __INTERP_H__ |
va009039 | 0:65f1469d6bfb | 11 | |
va009039 | 0:65f1469d6bfb | 12 | |
va009039 | 0:65f1469d6bfb | 13 | /** |
va009039 | 0:65f1469d6bfb | 14 | * \file |
va009039 | 0:65f1469d6bfb | 15 | * \brief VM Interpreter |
va009039 | 0:65f1469d6bfb | 16 | * |
va009039 | 0:65f1469d6bfb | 17 | * VM interpreter header. |
va009039 | 0:65f1469d6bfb | 18 | */ |
va009039 | 0:65f1469d6bfb | 19 | |
va009039 | 0:65f1469d6bfb | 20 | |
va009039 | 0:65f1469d6bfb | 21 | #include "thread.h" |
va009039 | 0:65f1469d6bfb | 22 | |
va009039 | 0:65f1469d6bfb | 23 | |
va009039 | 0:65f1469d6bfb | 24 | #define INTERP_LOOP_FOREVER 0 |
va009039 | 0:65f1469d6bfb | 25 | #define INTERP_RETURN_ON_NO_THREADS 1 |
va009039 | 0:65f1469d6bfb | 26 | |
va009039 | 0:65f1469d6bfb | 27 | |
va009039 | 0:65f1469d6bfb | 28 | /** Frame pointer ; currently for single thread */ |
va009039 | 0:65f1469d6bfb | 29 | #define PM_FP (gVmGlobal.pthread->pframe) |
va009039 | 0:65f1469d6bfb | 30 | /** Instruction pointer */ |
va009039 | 0:65f1469d6bfb | 31 | #define PM_IP (PM_FP->fo_ip) |
va009039 | 0:65f1469d6bfb | 32 | /** Argument stack pointer */ |
va009039 | 0:65f1469d6bfb | 33 | #define PM_SP (PM_FP->fo_sp) |
va009039 | 0:65f1469d6bfb | 34 | |
va009039 | 0:65f1469d6bfb | 35 | /** top of stack */ |
va009039 | 0:65f1469d6bfb | 36 | #define TOS (*(PM_SP - 1)) |
va009039 | 0:65f1469d6bfb | 37 | /** one under TOS */ |
va009039 | 0:65f1469d6bfb | 38 | #define TOS1 (*(PM_SP - 2)) |
va009039 | 0:65f1469d6bfb | 39 | /** two under TOS */ |
va009039 | 0:65f1469d6bfb | 40 | #define TOS2 (*(PM_SP - 3)) |
va009039 | 0:65f1469d6bfb | 41 | /** three under TOS */ |
va009039 | 0:65f1469d6bfb | 42 | #define TOS3 (*(PM_SP - 4)) |
va009039 | 0:65f1469d6bfb | 43 | /** index into stack; 0 is top, 1 is next */ |
va009039 | 0:65f1469d6bfb | 44 | #define STACK(n) (*(PM_SP - ((n) + 1))) |
va009039 | 0:65f1469d6bfb | 45 | /** pops an obj from the stack */ |
va009039 | 0:65f1469d6bfb | 46 | #define PM_POP() (*(--PM_SP)) |
va009039 | 0:65f1469d6bfb | 47 | /** pushes an obj on the stack */ |
va009039 | 0:65f1469d6bfb | 48 | #define PM_PUSH(pobj) (*(PM_SP++) = (pobj)) |
va009039 | 0:65f1469d6bfb | 49 | /** gets the argument (S16) from the instruction stream */ |
va009039 | 0:65f1469d6bfb | 50 | #define GET_ARG() mem_getWord(PM_FP->fo_memspace, &PM_IP) |
va009039 | 0:65f1469d6bfb | 51 | |
va009039 | 0:65f1469d6bfb | 52 | /** pushes an obj in the only stack slot of the native frame */ |
va009039 | 0:65f1469d6bfb | 53 | #define NATIVE_SET_TOS(pobj) (gVmGlobal.nativeframe.nf_stack = \ |
va009039 | 0:65f1469d6bfb | 54 | (pobj)) |
va009039 | 0:65f1469d6bfb | 55 | /** gets the nth local var from the native frame locals */ |
va009039 | 0:65f1469d6bfb | 56 | #define NATIVE_GET_LOCAL(n) (gVmGlobal.nativeframe.nf_locals[n]) |
va009039 | 0:65f1469d6bfb | 57 | /** gets a pointer to the frame that called this native fxn */ |
va009039 | 0:65f1469d6bfb | 58 | #define NATIVE_GET_PFRAME() (*ppframe) |
va009039 | 0:65f1469d6bfb | 59 | /** gets the number of args passed to the native fxn */ |
va009039 | 0:65f1469d6bfb | 60 | #define NATIVE_GET_NUM_ARGS() (gVmGlobal.nativeframe.nf_numlocals) |
va009039 | 0:65f1469d6bfb | 61 | |
va009039 | 0:65f1469d6bfb | 62 | |
va009039 | 0:65f1469d6bfb | 63 | /** |
va009039 | 0:65f1469d6bfb | 64 | * COMPARE_OP enum. |
va009039 | 0:65f1469d6bfb | 65 | * Used by the COMPARE_OP bytecode to determine |
va009039 | 0:65f1469d6bfb | 66 | * which type of compare to perform. |
va009039 | 0:65f1469d6bfb | 67 | * Must match those defined in Python. |
va009039 | 0:65f1469d6bfb | 68 | */ |
va009039 | 0:65f1469d6bfb | 69 | typedef enum PmCompare_e |
va009039 | 0:65f1469d6bfb | 70 | { |
va009039 | 0:65f1469d6bfb | 71 | COMP_LT = 0, /**< less than */ |
va009039 | 0:65f1469d6bfb | 72 | COMP_LE, /**< less than or equal */ |
va009039 | 0:65f1469d6bfb | 73 | COMP_EQ, /**< equal */ |
va009039 | 0:65f1469d6bfb | 74 | COMP_NE, /**< not equal */ |
va009039 | 0:65f1469d6bfb | 75 | COMP_GT, /**< greater than */ |
va009039 | 0:65f1469d6bfb | 76 | COMP_GE, /**< greater than or equal */ |
va009039 | 0:65f1469d6bfb | 77 | COMP_IN, /**< is in */ |
va009039 | 0:65f1469d6bfb | 78 | COMP_NOT_IN, /**< is not in */ |
va009039 | 0:65f1469d6bfb | 79 | COMP_IS, /**< is */ |
va009039 | 0:65f1469d6bfb | 80 | COMP_IS_NOT, /**< is not */ |
va009039 | 0:65f1469d6bfb | 81 | COMP_EXN_MATCH /**< do exceptions match */ |
va009039 | 0:65f1469d6bfb | 82 | } PmCompare_t, *pPmCompare_t; |
va009039 | 0:65f1469d6bfb | 83 | |
va009039 | 0:65f1469d6bfb | 84 | /** |
va009039 | 0:65f1469d6bfb | 85 | * Byte code enumeration |
va009039 | 0:65f1469d6bfb | 86 | */ |
va009039 | 0:65f1469d6bfb | 87 | typedef enum PmBcode_e |
va009039 | 0:65f1469d6bfb | 88 | { |
va009039 | 0:65f1469d6bfb | 89 | /* |
va009039 | 0:65f1469d6bfb | 90 | * Python source to create this list: |
va009039 | 0:65f1469d6bfb | 91 | * import dis |
va009039 | 0:65f1469d6bfb | 92 | * o = dis.opname |
va009039 | 0:65f1469d6bfb | 93 | * for i in range(256): |
va009039 | 0:65f1469d6bfb | 94 | * if o[i][0] != '<': |
va009039 | 0:65f1469d6bfb | 95 | * print "\t%s," % o[i] |
va009039 | 0:65f1469d6bfb | 96 | * else: |
va009039 | 0:65f1469d6bfb | 97 | * print "\tUNUSED_%02X," % i |
va009039 | 0:65f1469d6bfb | 98 | */ |
va009039 | 0:65f1469d6bfb | 99 | STOP_CODE = 0, /* 0x00 */ |
va009039 | 0:65f1469d6bfb | 100 | POP_TOP, |
va009039 | 0:65f1469d6bfb | 101 | ROT_TWO, |
va009039 | 0:65f1469d6bfb | 102 | ROT_THREE, |
va009039 | 0:65f1469d6bfb | 103 | DUP_TOP, |
va009039 | 0:65f1469d6bfb | 104 | ROT_FOUR, |
va009039 | 0:65f1469d6bfb | 105 | UNUSED_06, |
va009039 | 0:65f1469d6bfb | 106 | UNUSED_07, |
va009039 | 0:65f1469d6bfb | 107 | UNUSED_08, |
va009039 | 0:65f1469d6bfb | 108 | NOP, |
va009039 | 0:65f1469d6bfb | 109 | UNARY_POSITIVE, /* d010 */ |
va009039 | 0:65f1469d6bfb | 110 | UNARY_NEGATIVE, |
va009039 | 0:65f1469d6bfb | 111 | UNARY_NOT, |
va009039 | 0:65f1469d6bfb | 112 | UNARY_CONVERT, |
va009039 | 0:65f1469d6bfb | 113 | UNUSED_0E, |
va009039 | 0:65f1469d6bfb | 114 | UNARY_INVERT, |
va009039 | 0:65f1469d6bfb | 115 | UNUSED_10, /* 0x10 */ |
va009039 | 0:65f1469d6bfb | 116 | UNUSED_11, |
va009039 | 0:65f1469d6bfb | 117 | LIST_APPEND, |
va009039 | 0:65f1469d6bfb | 118 | BINARY_POWER, |
va009039 | 0:65f1469d6bfb | 119 | BINARY_MULTIPLY, /* d020 */ |
va009039 | 0:65f1469d6bfb | 120 | BINARY_DIVIDE, |
va009039 | 0:65f1469d6bfb | 121 | BINARY_MODULO, |
va009039 | 0:65f1469d6bfb | 122 | BINARY_ADD, |
va009039 | 0:65f1469d6bfb | 123 | BINARY_SUBTRACT, |
va009039 | 0:65f1469d6bfb | 124 | BINARY_SUBSCR, |
va009039 | 0:65f1469d6bfb | 125 | BINARY_FLOOR_DIVIDE, |
va009039 | 0:65f1469d6bfb | 126 | BINARY_TRUE_DIVIDE, |
va009039 | 0:65f1469d6bfb | 127 | INPLACE_FLOOR_DIVIDE, |
va009039 | 0:65f1469d6bfb | 128 | INPLACE_TRUE_DIVIDE, |
va009039 | 0:65f1469d6bfb | 129 | SLICE_0, /* d030 */ |
va009039 | 0:65f1469d6bfb | 130 | SLICE_1, |
va009039 | 0:65f1469d6bfb | 131 | SLICE_2, /* 0x20 */ |
va009039 | 0:65f1469d6bfb | 132 | SLICE_3, |
va009039 | 0:65f1469d6bfb | 133 | UNUSED_22, |
va009039 | 0:65f1469d6bfb | 134 | UNUSED_23, |
va009039 | 0:65f1469d6bfb | 135 | UNUSED_24, |
va009039 | 0:65f1469d6bfb | 136 | UNUSED_25, |
va009039 | 0:65f1469d6bfb | 137 | UNUSED_26, |
va009039 | 0:65f1469d6bfb | 138 | UNUSED_27, |
va009039 | 0:65f1469d6bfb | 139 | STORE_SLICE_0, /* d040 */ |
va009039 | 0:65f1469d6bfb | 140 | STORE_SLICE_1, |
va009039 | 0:65f1469d6bfb | 141 | STORE_SLICE_2, |
va009039 | 0:65f1469d6bfb | 142 | STORE_SLICE_3, |
va009039 | 0:65f1469d6bfb | 143 | UNUSED_2C, |
va009039 | 0:65f1469d6bfb | 144 | UNUSED_2D, |
va009039 | 0:65f1469d6bfb | 145 | UNUSED_2E, |
va009039 | 0:65f1469d6bfb | 146 | UNUSED_2F, |
va009039 | 0:65f1469d6bfb | 147 | UNUSED_30, /* 0x30 */ |
va009039 | 0:65f1469d6bfb | 148 | UNUSED_31, |
va009039 | 0:65f1469d6bfb | 149 | DELETE_SLICE_0, /* d050 */ |
va009039 | 0:65f1469d6bfb | 150 | DELETE_SLICE_1, |
va009039 | 0:65f1469d6bfb | 151 | DELETE_SLICE_2, |
va009039 | 0:65f1469d6bfb | 152 | DELETE_SLICE_3, |
va009039 | 0:65f1469d6bfb | 153 | STORE_MAP, |
va009039 | 0:65f1469d6bfb | 154 | INPLACE_ADD, |
va009039 | 0:65f1469d6bfb | 155 | INPLACE_SUBTRACT, |
va009039 | 0:65f1469d6bfb | 156 | INPLACE_MULTIPLY, |
va009039 | 0:65f1469d6bfb | 157 | INPLACE_DIVIDE, |
va009039 | 0:65f1469d6bfb | 158 | INPLACE_MODULO, |
va009039 | 0:65f1469d6bfb | 159 | STORE_SUBSCR, /* d060 */ |
va009039 | 0:65f1469d6bfb | 160 | DELETE_SUBSCR, |
va009039 | 0:65f1469d6bfb | 161 | BINARY_LSHIFT, |
va009039 | 0:65f1469d6bfb | 162 | BINARY_RSHIFT, |
va009039 | 0:65f1469d6bfb | 163 | BINARY_AND, /* 0x40 */ |
va009039 | 0:65f1469d6bfb | 164 | BINARY_XOR, |
va009039 | 0:65f1469d6bfb | 165 | BINARY_OR, |
va009039 | 0:65f1469d6bfb | 166 | INPLACE_POWER, |
va009039 | 0:65f1469d6bfb | 167 | GET_ITER, |
va009039 | 0:65f1469d6bfb | 168 | UNUSED_45, |
va009039 | 0:65f1469d6bfb | 169 | PRINT_EXPR, /* d070 */ |
va009039 | 0:65f1469d6bfb | 170 | PRINT_ITEM, |
va009039 | 0:65f1469d6bfb | 171 | PRINT_NEWLINE, |
va009039 | 0:65f1469d6bfb | 172 | PRINT_ITEM_TO, |
va009039 | 0:65f1469d6bfb | 173 | PRINT_NEWLINE_TO, |
va009039 | 0:65f1469d6bfb | 174 | INPLACE_LSHIFT, |
va009039 | 0:65f1469d6bfb | 175 | INPLACE_RSHIFT, |
va009039 | 0:65f1469d6bfb | 176 | INPLACE_AND, |
va009039 | 0:65f1469d6bfb | 177 | INPLACE_XOR, |
va009039 | 0:65f1469d6bfb | 178 | INPLACE_OR, |
va009039 | 0:65f1469d6bfb | 179 | BREAK_LOOP, /* 0x50 *//* d080 */ |
va009039 | 0:65f1469d6bfb | 180 | WITH_CLEANUP, |
va009039 | 0:65f1469d6bfb | 181 | LOAD_LOCALS, |
va009039 | 0:65f1469d6bfb | 182 | RETURN_VALUE, |
va009039 | 0:65f1469d6bfb | 183 | IMPORT_STAR, |
va009039 | 0:65f1469d6bfb | 184 | EXEC_STMT, |
va009039 | 0:65f1469d6bfb | 185 | YIELD_VALUE, |
va009039 | 0:65f1469d6bfb | 186 | POP_BLOCK, |
va009039 | 0:65f1469d6bfb | 187 | END_FINALLY, |
va009039 | 0:65f1469d6bfb | 188 | BUILD_CLASS, |
va009039 | 0:65f1469d6bfb | 189 | |
va009039 | 0:65f1469d6bfb | 190 | /* Opcodes from here have an argument */ |
va009039 | 0:65f1469d6bfb | 191 | HAVE_ARGUMENT = 90, /* d090 */ |
va009039 | 0:65f1469d6bfb | 192 | STORE_NAME = 90, |
va009039 | 0:65f1469d6bfb | 193 | DELETE_NAME, |
va009039 | 0:65f1469d6bfb | 194 | UNPACK_SEQUENCE, |
va009039 | 0:65f1469d6bfb | 195 | FOR_ITER, |
va009039 | 0:65f1469d6bfb | 196 | UNUSED_5E, |
va009039 | 0:65f1469d6bfb | 197 | STORE_ATTR, |
va009039 | 0:65f1469d6bfb | 198 | DELETE_ATTR, /* 0x60 */ |
va009039 | 0:65f1469d6bfb | 199 | STORE_GLOBAL, |
va009039 | 0:65f1469d6bfb | 200 | DELETE_GLOBAL, |
va009039 | 0:65f1469d6bfb | 201 | DUP_TOPX, |
va009039 | 0:65f1469d6bfb | 202 | LOAD_CONST, /* d100 */ |
va009039 | 0:65f1469d6bfb | 203 | LOAD_NAME, |
va009039 | 0:65f1469d6bfb | 204 | BUILD_TUPLE, |
va009039 | 0:65f1469d6bfb | 205 | BUILD_LIST, |
va009039 | 0:65f1469d6bfb | 206 | BUILD_MAP, |
va009039 | 0:65f1469d6bfb | 207 | LOAD_ATTR, |
va009039 | 0:65f1469d6bfb | 208 | COMPARE_OP, |
va009039 | 0:65f1469d6bfb | 209 | IMPORT_NAME, |
va009039 | 0:65f1469d6bfb | 210 | IMPORT_FROM, |
va009039 | 0:65f1469d6bfb | 211 | UNUSED_6D, |
va009039 | 0:65f1469d6bfb | 212 | JUMP_FORWARD, /* d110 */ |
va009039 | 0:65f1469d6bfb | 213 | JUMP_IF_FALSE, |
va009039 | 0:65f1469d6bfb | 214 | JUMP_IF_TRUE, /* 0x70 */ |
va009039 | 0:65f1469d6bfb | 215 | JUMP_ABSOLUTE, |
va009039 | 0:65f1469d6bfb | 216 | UNUSED_72, |
va009039 | 0:65f1469d6bfb | 217 | UNUSED_73, |
va009039 | 0:65f1469d6bfb | 218 | LOAD_GLOBAL, |
va009039 | 0:65f1469d6bfb | 219 | UNUSED_75, |
va009039 | 0:65f1469d6bfb | 220 | UNUSED_76, |
va009039 | 0:65f1469d6bfb | 221 | CONTINUE_LOOP, |
va009039 | 0:65f1469d6bfb | 222 | SETUP_LOOP, /* d120 */ |
va009039 | 0:65f1469d6bfb | 223 | SETUP_EXCEPT, |
va009039 | 0:65f1469d6bfb | 224 | SETUP_FINALLY, |
va009039 | 0:65f1469d6bfb | 225 | UNUSED_7B, |
va009039 | 0:65f1469d6bfb | 226 | LOAD_FAST, |
va009039 | 0:65f1469d6bfb | 227 | STORE_FAST, |
va009039 | 0:65f1469d6bfb | 228 | DELETE_FAST, |
va009039 | 0:65f1469d6bfb | 229 | UNUSED_79, |
va009039 | 0:65f1469d6bfb | 230 | UNUSED_80, /* 0x80 */ |
va009039 | 0:65f1469d6bfb | 231 | UNUSED_81, |
va009039 | 0:65f1469d6bfb | 232 | RAISE_VARARGS, /* d130 */ |
va009039 | 0:65f1469d6bfb | 233 | CALL_FUNCTION, |
va009039 | 0:65f1469d6bfb | 234 | MAKE_FUNCTION, |
va009039 | 0:65f1469d6bfb | 235 | BUILD_SLICE, |
va009039 | 0:65f1469d6bfb | 236 | MAKE_CLOSURE, |
va009039 | 0:65f1469d6bfb | 237 | LOAD_CLOSURE, |
va009039 | 0:65f1469d6bfb | 238 | LOAD_DEREF, |
va009039 | 0:65f1469d6bfb | 239 | STORE_DEREF, |
va009039 | 0:65f1469d6bfb | 240 | UNUSED_8A, |
va009039 | 0:65f1469d6bfb | 241 | UNUSED_8B, |
va009039 | 0:65f1469d6bfb | 242 | CALL_FUNCTION_VAR, /* d140 */ |
va009039 | 0:65f1469d6bfb | 243 | CALL_FUNCTION_KW, |
va009039 | 0:65f1469d6bfb | 244 | CALL_FUNCTION_VAR_KW, |
va009039 | 0:65f1469d6bfb | 245 | EXTENDED_ARG, |
va009039 | 0:65f1469d6bfb | 246 | |
va009039 | 0:65f1469d6bfb | 247 | UNUSED_90, UNUSED_91, UNUSED_92, UNUSED_93, |
va009039 | 0:65f1469d6bfb | 248 | UNUSED_94, UNUSED_95, UNUSED_96, UNUSED_97, |
va009039 | 0:65f1469d6bfb | 249 | UNUSED_98, UNUSED_99, UNUSED_9A, UNUSED_9B, |
va009039 | 0:65f1469d6bfb | 250 | UNUSED_9C, UNUSED_9D, UNUSED_9E, UNUSED_9F, |
va009039 | 0:65f1469d6bfb | 251 | UNUSED_A0, UNUSED_A1, UNUSED_A2, UNUSED_A3, |
va009039 | 0:65f1469d6bfb | 252 | UNUSED_A4, UNUSED_A5, UNUSED_A6, UNUSED_A7, |
va009039 | 0:65f1469d6bfb | 253 | UNUSED_A8, UNUSED_A9, UNUSED_AA, UNUSED_AB, |
va009039 | 0:65f1469d6bfb | 254 | UNUSED_AC, UNUSED_AD, UNUSED_AE, UNUSED_AF, |
va009039 | 0:65f1469d6bfb | 255 | UNUSED_B0, UNUSED_B1, UNUSED_B2, UNUSED_B3, |
va009039 | 0:65f1469d6bfb | 256 | UNUSED_B4, UNUSED_B5, UNUSED_B6, UNUSED_B7, |
va009039 | 0:65f1469d6bfb | 257 | UNUSED_B8, UNUSED_B9, UNUSED_BA, UNUSED_BB, |
va009039 | 0:65f1469d6bfb | 258 | UNUSED_BC, UNUSED_BD, UNUSED_BE, UNUSED_BF, |
va009039 | 0:65f1469d6bfb | 259 | UNUSED_C0, UNUSED_C1, UNUSED_C2, UNUSED_C3, |
va009039 | 0:65f1469d6bfb | 260 | UNUSED_C4, UNUSED_C5, UNUSED_C6, UNUSED_C7, |
va009039 | 0:65f1469d6bfb | 261 | UNUSED_C8, UNUSED_C9, UNUSED_CA, UNUSED_CB, |
va009039 | 0:65f1469d6bfb | 262 | UNUSED_CC, UNUSED_CD, UNUSED_CE, UNUSED_CF, |
va009039 | 0:65f1469d6bfb | 263 | UNUSED_D0, UNUSED_D1, UNUSED_D2, UNUSED_D3, |
va009039 | 0:65f1469d6bfb | 264 | UNUSED_D4, UNUSED_D5, UNUSED_D6, UNUSED_D7, |
va009039 | 0:65f1469d6bfb | 265 | UNUSED_D8, UNUSED_D9, UNUSED_DA, UNUSED_DB, |
va009039 | 0:65f1469d6bfb | 266 | UNUSED_DC, UNUSED_DD, UNUSED_DE, UNUSED_DF, |
va009039 | 0:65f1469d6bfb | 267 | UNUSED_E0, UNUSED_E1, UNUSED_E2, UNUSED_E3, |
va009039 | 0:65f1469d6bfb | 268 | UNUSED_E4, UNUSED_E5, UNUSED_E6, UNUSED_E7, |
va009039 | 0:65f1469d6bfb | 269 | UNUSED_E8, UNUSED_E9, UNUSED_EA, UNUSED_EB, |
va009039 | 0:65f1469d6bfb | 270 | UNUSED_EC, UNUSED_ED, UNUSED_EE, UNUSED_EF, |
va009039 | 0:65f1469d6bfb | 271 | UNUSED_F0, UNUSED_F1, UNUSED_F2, UNUSED_F3, |
va009039 | 0:65f1469d6bfb | 272 | UNUSED_F4, UNUSED_F5, UNUSED_F6, UNUSED_F7, |
va009039 | 0:65f1469d6bfb | 273 | UNUSED_F8, UNUSED_F9, UNUSED_FA, UNUSED_FB, |
va009039 | 0:65f1469d6bfb | 274 | UNUSED_FC, UNUSED_FD, UNUSED_FE, UNUSED_FF |
va009039 | 0:65f1469d6bfb | 275 | } PmBcode_t, *pPmBcode_t; |
va009039 | 0:65f1469d6bfb | 276 | |
va009039 | 0:65f1469d6bfb | 277 | |
va009039 | 0:65f1469d6bfb | 278 | /** |
va009039 | 0:65f1469d6bfb | 279 | * Interprets the available threads. Does not return. |
va009039 | 0:65f1469d6bfb | 280 | * |
va009039 | 0:65f1469d6bfb | 281 | * @param returnOnNoThreads Loop forever if 0, exit with status if no more |
va009039 | 0:65f1469d6bfb | 282 | * threads left. |
va009039 | 0:65f1469d6bfb | 283 | * @return Return status if called with returnOnNoThreads != 0, |
va009039 | 0:65f1469d6bfb | 284 | * will not return otherwise. |
va009039 | 0:65f1469d6bfb | 285 | */ |
va009039 | 0:65f1469d6bfb | 286 | PmReturn_t interpret(const uint8_t returnOnNoThreads); |
va009039 | 0:65f1469d6bfb | 287 | |
va009039 | 0:65f1469d6bfb | 288 | /** |
va009039 | 0:65f1469d6bfb | 289 | * Selects a thread to run and changes the VM internal variables to |
va009039 | 0:65f1469d6bfb | 290 | * let the switch-loop execute the chosen one in the next iteration. |
va009039 | 0:65f1469d6bfb | 291 | * For the moment the algorithm is primitive and will change the |
va009039 | 0:65f1469d6bfb | 292 | * thread each time it is called in a round-robin fashion. |
va009039 | 0:65f1469d6bfb | 293 | */ |
va009039 | 0:65f1469d6bfb | 294 | PmReturn_t interp_reschedule(void); |
va009039 | 0:65f1469d6bfb | 295 | |
va009039 | 0:65f1469d6bfb | 296 | /** |
va009039 | 0:65f1469d6bfb | 297 | * Creates a thread object and adds it to the queue of threads to be |
va009039 | 0:65f1469d6bfb | 298 | * executed while interpret() is running. |
va009039 | 0:65f1469d6bfb | 299 | * |
va009039 | 0:65f1469d6bfb | 300 | * The given obj may be a function, module, or class. |
va009039 | 0:65f1469d6bfb | 301 | * Creates a frame for the given function. |
va009039 | 0:65f1469d6bfb | 302 | * |
va009039 | 0:65f1469d6bfb | 303 | * @param pfunc Ptr to function to be executed as a thread. |
va009039 | 0:65f1469d6bfb | 304 | * @return Return status |
va009039 | 0:65f1469d6bfb | 305 | */ |
va009039 | 0:65f1469d6bfb | 306 | PmReturn_t interp_addThread(pPmFunc_t pfunc); |
va009039 | 0:65f1469d6bfb | 307 | |
va009039 | 0:65f1469d6bfb | 308 | /** |
va009039 | 0:65f1469d6bfb | 309 | * Sets the reschedule flag. |
va009039 | 0:65f1469d6bfb | 310 | * |
va009039 | 0:65f1469d6bfb | 311 | * @param boolean Reschedule on next occasion if boolean is true; clear |
va009039 | 0:65f1469d6bfb | 312 | * the flag otherwise. |
va009039 | 0:65f1469d6bfb | 313 | */ |
va009039 | 0:65f1469d6bfb | 314 | void interp_setRescheduleFlag(uint8_t boolean); |
va009039 | 0:65f1469d6bfb | 315 | |
va009039 | 0:65f1469d6bfb | 316 | #endif /* __INTERP_H__ */ |