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 __GLOBAL_H__
va009039 0:65f1469d6bfb 10 #define __GLOBAL_H__
va009039 0:65f1469d6bfb 11
va009039 0:65f1469d6bfb 12
va009039 0:65f1469d6bfb 13 /**
va009039 0:65f1469d6bfb 14 * \file
va009039 0:65f1469d6bfb 15 * \brief VM Globals
va009039 0:65f1469d6bfb 16 *
va009039 0:65f1469d6bfb 17 * VM globals header.
va009039 0:65f1469d6bfb 18 */
va009039 0:65f1469d6bfb 19
va009039 0:65f1469d6bfb 20
va009039 0:65f1469d6bfb 21 /** The global root PmGlobals Dict object */
va009039 0:65f1469d6bfb 22 #define PM_PBUILTINS (pPmObj_t)(gVmGlobal.builtins)
va009039 0:65f1469d6bfb 23
va009039 0:65f1469d6bfb 24 /** The global None object */
va009039 0:65f1469d6bfb 25 #define PM_NONE (pPmObj_t)(gVmGlobal.pnone)
va009039 0:65f1469d6bfb 26
va009039 0:65f1469d6bfb 27 /** The global False object */
va009039 0:65f1469d6bfb 28 #define PM_FALSE (pPmObj_t)(gVmGlobal.pfalse)
va009039 0:65f1469d6bfb 29
va009039 0:65f1469d6bfb 30 /** The global True object */
va009039 0:65f1469d6bfb 31 #define PM_TRUE (pPmObj_t)(gVmGlobal.ptrue)
va009039 0:65f1469d6bfb 32
va009039 0:65f1469d6bfb 33 /** The global integer 0 object */
va009039 0:65f1469d6bfb 34 #define PM_ZERO (pPmObj_t)(gVmGlobal.pzero)
va009039 0:65f1469d6bfb 35
va009039 0:65f1469d6bfb 36 /** The global integer 1 object */
va009039 0:65f1469d6bfb 37 #define PM_ONE (pPmObj_t)(gVmGlobal.pone)
va009039 0:65f1469d6bfb 38
va009039 0:65f1469d6bfb 39 /** The global integer -1 object */
va009039 0:65f1469d6bfb 40 #define PM_NEGONE (pPmObj_t)(gVmGlobal.pnegone)
va009039 0:65f1469d6bfb 41
va009039 0:65f1469d6bfb 42 /** The global string "code" */
va009039 0:65f1469d6bfb 43 #define PM_CODE_STR (pPmObj_t)(gVmGlobal.pcodeStr)
va009039 0:65f1469d6bfb 44
va009039 0:65f1469d6bfb 45 #ifdef HAVE_CLASSES
va009039 0:65f1469d6bfb 46 /** The global string "__init__" */
va009039 0:65f1469d6bfb 47 #define PM_INIT_STR (pPmObj_t)(gVmGlobal.pinitStr)
va009039 0:65f1469d6bfb 48 #endif /* HAVE_CLASSES */
va009039 0:65f1469d6bfb 49
va009039 0:65f1469d6bfb 50 #ifdef HAVE_GENERATORS
va009039 0:65f1469d6bfb 51 /** The global string "Generator" */
va009039 0:65f1469d6bfb 52 #define PM_GENERATOR_STR (pPmObj_t)(gVmGlobal.pgenStr)
va009039 0:65f1469d6bfb 53 /** The global string "next" */
va009039 0:65f1469d6bfb 54 #define PM_NEXT_STR (pPmObj_t)(gVmGlobal.pnextStr)
va009039 0:65f1469d6bfb 55 #endif /* HAVE_GENERATORS */
va009039 0:65f1469d6bfb 56
va009039 0:65f1469d6bfb 57 #ifdef HAVE_ASSERT
va009039 0:65f1469d6bfb 58 /** The global string "Exception" */
va009039 0:65f1469d6bfb 59 #define PM_EXCEPTION_STR (pPmObj_t)(gVmGlobal.pexnStr)
va009039 0:65f1469d6bfb 60 #endif /* HAVE_ASSERT */
va009039 0:65f1469d6bfb 61
va009039 0:65f1469d6bfb 62 #ifdef HAVE_BYTEARRAY
va009039 0:65f1469d6bfb 63 /** The global string "bytearray" */
va009039 0:65f1469d6bfb 64 #define PM_BYTEARRAY_STR (pPmObj_t)(gVmGlobal.pbaStr)
va009039 0:65f1469d6bfb 65 #endif /* HAVE_BYTEARRAY */
va009039 0:65f1469d6bfb 66
va009039 0:65f1469d6bfb 67 /** The global string "__md" */
va009039 0:65f1469d6bfb 68 #define PM_MD_STR (pPmObj_t)(gVmGlobal.pmdStr)
va009039 0:65f1469d6bfb 69
va009039 0:65f1469d6bfb 70
va009039 0:65f1469d6bfb 71 /**
va009039 0:65f1469d6bfb 72 * This struct contains ALL of PyMite's globals
va009039 0:65f1469d6bfb 73 */
va009039 0:65f1469d6bfb 74 typedef struct PmVmGlobal_s
va009039 0:65f1469d6bfb 75 {
va009039 0:65f1469d6bfb 76 /** Global none obj (none) */
va009039 0:65f1469d6bfb 77 pPmObj_t pnone;
va009039 0:65f1469d6bfb 78
va009039 0:65f1469d6bfb 79 /** Global integer 0 obj */
va009039 0:65f1469d6bfb 80 pPmInt_t pzero;
va009039 0:65f1469d6bfb 81
va009039 0:65f1469d6bfb 82 /** Global integer 1 obj */
va009039 0:65f1469d6bfb 83 pPmInt_t pone;
va009039 0:65f1469d6bfb 84
va009039 0:65f1469d6bfb 85 /** Global integer -1 obj */
va009039 0:65f1469d6bfb 86 pPmInt_t pnegone;
va009039 0:65f1469d6bfb 87
va009039 0:65f1469d6bfb 88 /** Global boolean False obj */
va009039 0:65f1469d6bfb 89 pPmInt_t pfalse;
va009039 0:65f1469d6bfb 90
va009039 0:65f1469d6bfb 91 /** Global boolean True obj */
va009039 0:65f1469d6bfb 92 pPmInt_t ptrue;
va009039 0:65f1469d6bfb 93
va009039 0:65f1469d6bfb 94 /** The string "code", used in interp.c RAISE_VARARGS */
va009039 0:65f1469d6bfb 95 pPmString_t pcodeStr;
va009039 0:65f1469d6bfb 96
va009039 0:65f1469d6bfb 97 /** Dict for builtins */
va009039 0:65f1469d6bfb 98 pPmDict_t builtins;
va009039 0:65f1469d6bfb 99
va009039 0:65f1469d6bfb 100 /** Paths to available images */
va009039 0:65f1469d6bfb 101 PmImgPaths_t imgPaths;
va009039 0:65f1469d6bfb 102
va009039 0:65f1469d6bfb 103 /** The single native frame. Static alloc so it won't be GC'd */
va009039 0:65f1469d6bfb 104 PmNativeFrame_t nativeframe;
va009039 0:65f1469d6bfb 105
va009039 0:65f1469d6bfb 106 /** PyMite release value for when an error occurs */
va009039 0:65f1469d6bfb 107 uint8_t errVmRelease;
va009039 0:65f1469d6bfb 108
va009039 0:65f1469d6bfb 109 /** PyMite source file ID number for when an error occurs */
va009039 0:65f1469d6bfb 110 uint8_t errFileId;
va009039 0:65f1469d6bfb 111
va009039 0:65f1469d6bfb 112 /** Line number for when an error occurs */
va009039 0:65f1469d6bfb 113 uint16_t errLineNum;
va009039 0:65f1469d6bfb 114
va009039 0:65f1469d6bfb 115 /** Thread list */
va009039 0:65f1469d6bfb 116 pPmList_t threadList;
va009039 0:65f1469d6bfb 117
va009039 0:65f1469d6bfb 118 /** Ptr to current thread */
va009039 0:65f1469d6bfb 119 pPmThread_t pthread;
va009039 0:65f1469d6bfb 120
va009039 0:65f1469d6bfb 121 #ifdef HAVE_CLASSES
va009039 0:65f1469d6bfb 122 /* NOTE: placing this field before the nativeframe field causes errors */
va009039 0:65f1469d6bfb 123 /** The string "__init__", used in interp.c CALL_FUNCTION */
va009039 0:65f1469d6bfb 124 pPmString_t pinitStr;
va009039 0:65f1469d6bfb 125 #endif /* HAVE_CLASSES */
va009039 0:65f1469d6bfb 126
va009039 0:65f1469d6bfb 127 #ifdef HAVE_GENERATORS
va009039 0:65f1469d6bfb 128 /** The string "Generator", used in interp.c CALL_FUNCTION */
va009039 0:65f1469d6bfb 129 pPmString_t pgenStr;
va009039 0:65f1469d6bfb 130 /** The string "next", used in interp.c FOR_ITER */
va009039 0:65f1469d6bfb 131 pPmString_t pnextStr;
va009039 0:65f1469d6bfb 132 #endif /* HAVE_GENERATORS */
va009039 0:65f1469d6bfb 133
va009039 0:65f1469d6bfb 134 #ifdef HAVE_ASSERT
va009039 0:65f1469d6bfb 135 /** The string "Exception", used in RAISE_VARARGS */
va009039 0:65f1469d6bfb 136 pPmString_t pexnStr;
va009039 0:65f1469d6bfb 137 #endif /* HAVE_ASSERT */
va009039 0:65f1469d6bfb 138
va009039 0:65f1469d6bfb 139 #ifdef HAVE_BYTEARRAY
va009039 0:65f1469d6bfb 140 /** The global string "bytearray" */
va009039 0:65f1469d6bfb 141 pPmString_t pbaStr;
va009039 0:65f1469d6bfb 142 #endif /* HAVE_BYTEARRAY */
va009039 0:65f1469d6bfb 143
va009039 0:65f1469d6bfb 144 /** The global string "__md" */
va009039 0:65f1469d6bfb 145 pPmString_t pmdStr;
va009039 0:65f1469d6bfb 146
va009039 0:65f1469d6bfb 147 #ifdef HAVE_PRINT
va009039 0:65f1469d6bfb 148 /** Remembers when a space is needed before printing the next object */
va009039 0:65f1469d6bfb 149 uint8_t needSoftSpace;
va009039 0:65f1469d6bfb 150 /** Remembers when something has printed since the last newline */
va009039 0:65f1469d6bfb 151 uint8_t somethingPrinted;
va009039 0:65f1469d6bfb 152 #endif /* HAVE_PRINT */
va009039 0:65f1469d6bfb 153
va009039 0:65f1469d6bfb 154 /** Flag to trigger rescheduling */
va009039 0:65f1469d6bfb 155 uint8_t reschedule;
va009039 0:65f1469d6bfb 156 } PmVmGlobal_t,
va009039 0:65f1469d6bfb 157 *pPmVmGlobal_t;
va009039 0:65f1469d6bfb 158
va009039 0:65f1469d6bfb 159
va009039 0:65f1469d6bfb 160 extern volatile PmVmGlobal_t gVmGlobal;
va009039 0:65f1469d6bfb 161
va009039 0:65f1469d6bfb 162
va009039 0:65f1469d6bfb 163 /**
va009039 0:65f1469d6bfb 164 * Initializes the global struct
va009039 0:65f1469d6bfb 165 *
va009039 0:65f1469d6bfb 166 * @return Return status
va009039 0:65f1469d6bfb 167 */
va009039 0:65f1469d6bfb 168 PmReturn_t global_init(void);
va009039 0:65f1469d6bfb 169
va009039 0:65f1469d6bfb 170 /**
va009039 0:65f1469d6bfb 171 * Sets the builtins dict into the given module's attrs.
va009039 0:65f1469d6bfb 172 *
va009039 0:65f1469d6bfb 173 * If not yet done, loads the "__bt" module via global_loadBuiltins().
va009039 0:65f1469d6bfb 174 * Restrictions described in that functions documentation apply.
va009039 0:65f1469d6bfb 175 *
va009039 0:65f1469d6bfb 176 * @param pmod Module whose attrs receive builtins
va009039 0:65f1469d6bfb 177 * @return Return status
va009039 0:65f1469d6bfb 178 */
va009039 0:65f1469d6bfb 179 PmReturn_t global_setBuiltins(pPmFunc_t pmod);
va009039 0:65f1469d6bfb 180
va009039 0:65f1469d6bfb 181 /**
va009039 0:65f1469d6bfb 182 * Loads the "__bt" module and sets the builtins dict (PM_PBUILTINS)
va009039 0:65f1469d6bfb 183 * to point to __bt's attributes dict.
va009039 0:65f1469d6bfb 184 * Creates "None" = None entry in builtins.
va009039 0:65f1469d6bfb 185 *
va009039 0:65f1469d6bfb 186 * When run, there should not be any other threads in the interpreter
va009039 0:65f1469d6bfb 187 * thread list yet.
va009039 0:65f1469d6bfb 188 *
va009039 0:65f1469d6bfb 189 * @return Return status
va009039 0:65f1469d6bfb 190 */
va009039 0:65f1469d6bfb 191 PmReturn_t global_loadBuiltins(void);
va009039 0:65f1469d6bfb 192
va009039 0:65f1469d6bfb 193 #endif /* __GLOBAL_H__ */