python-on-a-chip online compiler

Dependencies:   mbed TSI

/media/uploads/va009039/p14p-f446re.png

more info: python-on-a-chip

Committer:
va009039
Date:
Thu Apr 14 22:32:57 2016 +0000
Revision:
15:94ca5c8003e5
Parent:
0:65f1469d6bfb
update Nucleo-F401RE.

Who changed what in which revision?

UserRevisionLine numberNew 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 __PM_H__
va009039 0:65f1469d6bfb 10 #define __PM_H__
va009039 0:65f1469d6bfb 11
va009039 0:65f1469d6bfb 12
va009039 0:65f1469d6bfb 13 /**
va009039 0:65f1469d6bfb 14 * \file
va009039 0:65f1469d6bfb 15 * \brief PyMite Header
va009039 0:65f1469d6bfb 16 *
va009039 0:65f1469d6bfb 17 * Include things that are needed by nearly everything.
va009039 0:65f1469d6bfb 18 */
va009039 0:65f1469d6bfb 19
va009039 0:65f1469d6bfb 20
va009039 0:65f1469d6bfb 21 #ifdef __cplusplus
va009039 0:65f1469d6bfb 22 extern "C" {
va009039 0:65f1469d6bfb 23 #endif
va009039 0:65f1469d6bfb 24
va009039 0:65f1469d6bfb 25 #ifdef HAVE_SNPRINTF_FORMAT
va009039 0:65f1469d6bfb 26 #include <stdio.h>
va009039 0:65f1469d6bfb 27 #endif
va009039 0:65f1469d6bfb 28 #include <stdint.h>
va009039 0:65f1469d6bfb 29
va009039 0:65f1469d6bfb 30 /**
va009039 0:65f1469d6bfb 31 * Value indicating the release of PyMite
va009039 0:65f1469d6bfb 32 *
va009039 0:65f1469d6bfb 33 * This value should be incremented for every public release.
va009039 0:65f1469d6bfb 34 * It helps locate a defect when used in conjunction with a fileID
va009039 0:65f1469d6bfb 35 * and line number.
va009039 0:65f1469d6bfb 36 */
va009039 0:65f1469d6bfb 37 #define PM_RELEASE 8
va009039 0:65f1469d6bfb 38
va009039 0:65f1469d6bfb 39
va009039 0:65f1469d6bfb 40 /** null for C code */
va009039 0:65f1469d6bfb 41 #define C_NULL 0
va009039 0:65f1469d6bfb 42
va009039 0:65f1469d6bfb 43 /** false for C code */
va009039 0:65f1469d6bfb 44 #define C_FALSE (uint8_t)0
va009039 0:65f1469d6bfb 45
va009039 0:65f1469d6bfb 46 /** true for C code */
va009039 0:65f1469d6bfb 47 #define C_TRUE (uint8_t)1
va009039 0:65f1469d6bfb 48
va009039 0:65f1469d6bfb 49 /** Comparison result is that items are the same */
va009039 0:65f1469d6bfb 50 #define C_SAME (int8_t)0
va009039 0:65f1469d6bfb 51
va009039 0:65f1469d6bfb 52 /** Comparison result is that items differ */
va009039 0:65f1469d6bfb 53 #define C_DIFFER (int8_t)-1
va009039 0:65f1469d6bfb 54
va009039 0:65f1469d6bfb 55 /** PORT inline for C code */
va009039 0:65f1469d6bfb 56 #define INLINE __inline__
va009039 0:65f1469d6bfb 57
va009039 0:65f1469d6bfb 58
va009039 0:65f1469d6bfb 59 /**
va009039 0:65f1469d6bfb 60 * Returns an exception error code and stores debug data
va009039 0:65f1469d6bfb 61 *
va009039 0:65f1469d6bfb 62 * This macro must be used as an rval statement. That is, it must
va009039 0:65f1469d6bfb 63 * be used after an assignment such as "retval = " or a return statement
va009039 0:65f1469d6bfb 64 */
va009039 0:65f1469d6bfb 65 #if __DEBUG__
va009039 0:65f1469d6bfb 66 #define PM_RAISE(retexn, exn) \
va009039 0:65f1469d6bfb 67 do \
va009039 0:65f1469d6bfb 68 { \
va009039 0:65f1469d6bfb 69 retexn = (exn); \
va009039 0:65f1469d6bfb 70 gVmGlobal.errFileId = __FILE_ID__; \
va009039 0:65f1469d6bfb 71 gVmGlobal.errLineNum = (uint16_t)__LINE__; \
va009039 0:65f1469d6bfb 72 } while (0)
va009039 0:65f1469d6bfb 73 #else
va009039 0:65f1469d6bfb 74 #define PM_RAISE(retexn, exn) \
va009039 0:65f1469d6bfb 75 retexn = (exn)
va009039 0:65f1469d6bfb 76 #endif
va009039 0:65f1469d6bfb 77
va009039 0:65f1469d6bfb 78 /** if retval is not OK, break from the block */
va009039 0:65f1469d6bfb 79 #define PM_BREAK_IF_ERROR(retval) if ((retval) != PM_RET_OK) break
va009039 0:65f1469d6bfb 80
va009039 0:65f1469d6bfb 81 /** return an error code if it is not PM_RET_OK */
va009039 0:65f1469d6bfb 82 #define PM_RETURN_IF_ERROR(retval) if ((retval) != PM_RET_OK) return (retval)
va009039 0:65f1469d6bfb 83
va009039 0:65f1469d6bfb 84 /** print an error message if argument is not PM_RET_OK */
va009039 0:65f1469d6bfb 85 #define PM_REPORT_IF_ERROR(retval) if ((retval) != PM_RET_OK) \
va009039 0:65f1469d6bfb 86 plat_reportError(retval)
va009039 0:65f1469d6bfb 87
va009039 0:65f1469d6bfb 88 /** Jumps to a label if argument is not PM_RET_OK */
va009039 0:65f1469d6bfb 89 #define PM_GOTO_IF_ERROR(retval, target) if ((retval) != PM_RET_OK) \
va009039 0:65f1469d6bfb 90 goto target
va009039 0:65f1469d6bfb 91
va009039 0:65f1469d6bfb 92 #if __DEBUG__
va009039 0:65f1469d6bfb 93 /** If the boolean expression fails, return the ASSERT error code */
va009039 0:65f1469d6bfb 94 #define C_ASSERT(boolexpr) \
va009039 0:65f1469d6bfb 95 do \
va009039 0:65f1469d6bfb 96 { \
va009039 0:65f1469d6bfb 97 if (!((boolexpr))) \
va009039 0:65f1469d6bfb 98 { \
va009039 0:65f1469d6bfb 99 gVmGlobal.errFileId = __FILE_ID__; \
va009039 0:65f1469d6bfb 100 gVmGlobal.errLineNum = (uint16_t)__LINE__; \
va009039 0:65f1469d6bfb 101 return PM_RET_ASSERT_FAIL; \
va009039 0:65f1469d6bfb 102 } \
va009039 0:65f1469d6bfb 103 } \
va009039 0:65f1469d6bfb 104 while (0)
va009039 0:65f1469d6bfb 105
va009039 0:65f1469d6bfb 106 #else
va009039 0:65f1469d6bfb 107 /** Assert statements are removed from production code */
va009039 0:65f1469d6bfb 108 #define C_ASSERT(boolexpr)
va009039 0:65f1469d6bfb 109 #endif
va009039 0:65f1469d6bfb 110
va009039 0:65f1469d6bfb 111 /** Use as the first argument to C_DEBUG_PRINT for low volume messages */
va009039 0:65f1469d6bfb 112 #define VERBOSITY_LOW 1
va009039 0:65f1469d6bfb 113
va009039 0:65f1469d6bfb 114 /** Use as the first argument to C_DEBUG_PRINT for medium volume messages */
va009039 0:65f1469d6bfb 115 #define VERBOSITY_MEDIUM 2
va009039 0:65f1469d6bfb 116
va009039 0:65f1469d6bfb 117 /** Use as the first argument to C_DEBUG_PRINT for high volume messages */
va009039 0:65f1469d6bfb 118 #define VERBOSITY_HIGH 3
va009039 0:65f1469d6bfb 119
va009039 0:65f1469d6bfb 120 #if __DEBUG__
va009039 0:65f1469d6bfb 121 #include <stdio.h>
va009039 0:65f1469d6bfb 122
va009039 0:65f1469d6bfb 123 /** To be used to set DEBUG_PRINT_VERBOSITY to a value so no prints occur */
va009039 0:65f1469d6bfb 124 #define VERBOSITY_OFF 0
va009039 0:65f1469d6bfb 125
va009039 0:65f1469d6bfb 126 /** Sets the level of verbosity to allow in debug prints */
va009039 0:65f1469d6bfb 127 #define DEBUG_PRINT_VERBOSITY VERBOSITY_OFF
va009039 0:65f1469d6bfb 128
va009039 0:65f1469d6bfb 129 /** Prints a debug message when the verbosity is within the set value */
va009039 0:65f1469d6bfb 130 #define C_DEBUG_PRINT(v, f, ...) \
va009039 0:65f1469d6bfb 131 do \
va009039 0:65f1469d6bfb 132 { \
va009039 0:65f1469d6bfb 133 if (DEBUG_PRINT_VERBOSITY >= (v)) \
va009039 0:65f1469d6bfb 134 { \
va009039 0:65f1469d6bfb 135 printf("PM_DEBUG: " f, ## __VA_ARGS__); \
va009039 0:65f1469d6bfb 136 } \
va009039 0:65f1469d6bfb 137 } \
va009039 0:65f1469d6bfb 138 while (0)
va009039 0:65f1469d6bfb 139
va009039 0:65f1469d6bfb 140 #else
va009039 0:65f1469d6bfb 141 #define C_DEBUG_PRINT(...)
va009039 0:65f1469d6bfb 142 #endif
va009039 0:65f1469d6bfb 143
va009039 0:65f1469d6bfb 144
va009039 0:65f1469d6bfb 145 /**
va009039 0:65f1469d6bfb 146 * Return values for system functions
va009039 0:65f1469d6bfb 147 * to report status, errors, exceptions, etc.
va009039 0:65f1469d6bfb 148 * Normally, functions which use these values
va009039 0:65f1469d6bfb 149 * should propagate the same return value
va009039 0:65f1469d6bfb 150 * up the call tree to the interpreter.
va009039 0:65f1469d6bfb 151 */
va009039 0:65f1469d6bfb 152 typedef enum PmReturn_e
va009039 0:65f1469d6bfb 153 {
va009039 0:65f1469d6bfb 154 /* general status return values */
va009039 0:65f1469d6bfb 155 PM_RET_OK = 0, /**< Everything is ok */
va009039 0:65f1469d6bfb 156 PM_RET_NO = 0xFF, /**< General "no result" */
va009039 0:65f1469d6bfb 157 PM_RET_ERR = 0xFE, /**< General failure */
va009039 0:65f1469d6bfb 158 PM_RET_STUB = 0xFD, /**< Return val for stub fxn */
va009039 0:65f1469d6bfb 159 PM_RET_ASSERT_FAIL = 0xFC, /**< Assertion failure */
va009039 0:65f1469d6bfb 160 PM_RET_FRAME_SWITCH = 0xFB, /**< Frame pointer was modified */
va009039 0:65f1469d6bfb 161 PM_RET_ALIGNMENT = 0xFA, /**< Heap is not aligned */
va009039 0:65f1469d6bfb 162
va009039 0:65f1469d6bfb 163 /* return vals that indicate an exception occured */
va009039 0:65f1469d6bfb 164 PM_RET_EX = 0xE0, /**< General exception */
va009039 0:65f1469d6bfb 165 PM_RET_EX_EXIT = 0xE1, /**< System exit */
va009039 0:65f1469d6bfb 166 PM_RET_EX_IO = 0xE2, /**< Input/output error */
va009039 0:65f1469d6bfb 167 PM_RET_EX_ZDIV = 0xE3, /**< Zero division error */
va009039 0:65f1469d6bfb 168 PM_RET_EX_ASSRT = 0xE4, /**< Assertion error */
va009039 0:65f1469d6bfb 169 PM_RET_EX_ATTR = 0xE5, /**< Attribute error */
va009039 0:65f1469d6bfb 170 PM_RET_EX_IMPRT = 0xE6, /**< Import error */
va009039 0:65f1469d6bfb 171 PM_RET_EX_INDX = 0xE7, /**< Index error */
va009039 0:65f1469d6bfb 172 PM_RET_EX_KEY = 0xE8, /**< Key error */
va009039 0:65f1469d6bfb 173 PM_RET_EX_MEM = 0xE9, /**< Memory error */
va009039 0:65f1469d6bfb 174 PM_RET_EX_NAME = 0xEA, /**< Name error */
va009039 0:65f1469d6bfb 175 PM_RET_EX_SYNTAX = 0xEB, /**< Syntax error */
va009039 0:65f1469d6bfb 176 PM_RET_EX_SYS = 0xEC, /**< System error */
va009039 0:65f1469d6bfb 177 PM_RET_EX_TYPE = 0xED, /**< Type error */
va009039 0:65f1469d6bfb 178 PM_RET_EX_VAL = 0xEE, /**< Value error */
va009039 0:65f1469d6bfb 179 PM_RET_EX_STOP = 0xEF, /**< Stop iteration */
va009039 0:65f1469d6bfb 180 PM_RET_EX_WARN = 0xF0, /**< Warning */
va009039 0:65f1469d6bfb 181 PM_RET_EX_OFLOW = 0xF1, /**< Overflow */
va009039 0:65f1469d6bfb 182 } PmReturn_t;
va009039 0:65f1469d6bfb 183
va009039 0:65f1469d6bfb 184
va009039 0:65f1469d6bfb 185 extern volatile uint32_t pm_timerMsTicks;
va009039 0:65f1469d6bfb 186
va009039 0:65f1469d6bfb 187
va009039 0:65f1469d6bfb 188 /* WARNING: The order of the following includes is critical */
va009039 0:65f1469d6bfb 189 #include "plat.h"
va009039 0:65f1469d6bfb 190 #include "pmfeatures.h"
va009039 0:65f1469d6bfb 191 #include "pmEmptyPlatformDefs.h"
va009039 0:65f1469d6bfb 192 #include "sli.h"
va009039 0:65f1469d6bfb 193 #include "mem.h"
va009039 0:65f1469d6bfb 194 #include "obj.h"
va009039 0:65f1469d6bfb 195 #include "seq.h"
va009039 0:65f1469d6bfb 196 #include "tuple.h"
va009039 0:65f1469d6bfb 197 #include "strobj.h"
va009039 0:65f1469d6bfb 198 #include "heap.h"
va009039 0:65f1469d6bfb 199 #include "int.h"
va009039 0:65f1469d6bfb 200 #include "seglist.h"
va009039 0:65f1469d6bfb 201 #include "list.h"
va009039 0:65f1469d6bfb 202 #include "dict.h"
va009039 0:65f1469d6bfb 203 #include "codeobj.h"
va009039 0:65f1469d6bfb 204 #include "func.h"
va009039 0:65f1469d6bfb 205 #include "module.h"
va009039 0:65f1469d6bfb 206 #include "frame.h"
va009039 0:65f1469d6bfb 207 #include "class.h"
va009039 0:65f1469d6bfb 208 #include "interp.h"
va009039 0:65f1469d6bfb 209 #include "img.h"
va009039 0:65f1469d6bfb 210 #include "global.h"
va009039 0:65f1469d6bfb 211 #include "thread.h"
va009039 0:65f1469d6bfb 212 #include "float.h"
va009039 0:65f1469d6bfb 213 #include "plat_interface.h"
va009039 0:65f1469d6bfb 214 #include "bytearray.h"
va009039 0:65f1469d6bfb 215
va009039 0:65f1469d6bfb 216
va009039 0:65f1469d6bfb 217 /** Pointer to a native function used for lookup tables in interp.c */
va009039 0:65f1469d6bfb 218 typedef PmReturn_t (* pPmNativeFxn_t)(pPmFrame_t *);
va009039 0:65f1469d6bfb 219 extern pPmNativeFxn_t const std_nat_fxn_table[];
va009039 0:65f1469d6bfb 220 extern pPmNativeFxn_t const usr_nat_fxn_table[];
va009039 0:65f1469d6bfb 221
va009039 0:65f1469d6bfb 222
va009039 0:65f1469d6bfb 223 /**
va009039 0:65f1469d6bfb 224 * Initializes the PyMite virtual machine and indexes the user's application
va009039 0:65f1469d6bfb 225 * image. The VM heap and globals are reset. The argument, pusrimg, may be
va009039 0:65f1469d6bfb 226 * null for interactive sessions.
va009039 0:65f1469d6bfb 227 *
va009039 0:65f1469d6bfb 228 * @param heap_base The address where the contiguous heap begins
va009039 0:65f1469d6bfb 229 * @param heap_size The size in bytes (octets) of the given heap.
va009039 0:65f1469d6bfb 230 * Must be a multiple of four.
va009039 0:65f1469d6bfb 231 * @param memspace Memory space in which the user image is located
va009039 0:65f1469d6bfb 232 * @param pusrimg Address of the user image in the memory space
va009039 0:65f1469d6bfb 233 * @return Return status
va009039 0:65f1469d6bfb 234 */
va009039 0:65f1469d6bfb 235 PmReturn_t pm_init(uint8_t *heap_base, uint32_t heap_size,
va009039 0:65f1469d6bfb 236 PmMemSpace_t memspace, uint8_t const * const pusrimg);
va009039 0:65f1469d6bfb 237
va009039 0:65f1469d6bfb 238 /**
va009039 0:65f1469d6bfb 239 * Executes the named module
va009039 0:65f1469d6bfb 240 *
va009039 0:65f1469d6bfb 241 * @param modstr Name of module to run
va009039 0:65f1469d6bfb 242 * @return Return status
va009039 0:65f1469d6bfb 243 */
va009039 0:65f1469d6bfb 244 PmReturn_t pm_run(uint8_t const *modstr);
va009039 0:65f1469d6bfb 245
va009039 0:65f1469d6bfb 246 /**
va009039 0:65f1469d6bfb 247 * Needs to be called periodically by the host program.
va009039 0:65f1469d6bfb 248 * For the desktop target, it is periodically called using a signal.
va009039 0:65f1469d6bfb 249 * For embedded targets, it needs to be called periodically. It should
va009039 0:65f1469d6bfb 250 * be called from a timer interrupt.
va009039 0:65f1469d6bfb 251 *
va009039 0:65f1469d6bfb 252 * @param usecsSinceLastCall Microseconds (not less than those) that passed
va009039 0:65f1469d6bfb 253 * since last call. This must be <64535.
va009039 0:65f1469d6bfb 254 * @return Return status
va009039 0:65f1469d6bfb 255 */
va009039 0:65f1469d6bfb 256 PmReturn_t pm_vmPeriodic(uint16_t usecsSinceLastCall);
va009039 0:65f1469d6bfb 257
va009039 0:65f1469d6bfb 258 #ifdef __cplusplus
va009039 0:65f1469d6bfb 259 }
va009039 0:65f1469d6bfb 260 #endif
va009039 0:65f1469d6bfb 261
va009039 0:65f1469d6bfb 262 #endif /* __PM_H__ */