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