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.
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)
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 */
65 /** The global string "Exception" */
66 #define PM_EXCEPTION_STR (pPmObj_t)(gVmGlobal.pexnStr)
67 #endif /* HAVE_ASSERT */
70 /** The global string "bytearray" */
71 #define PM_BYTEARRAY_STR (pPmObj_t)(gVmGlobal.pbaStr)
72 #endif /* HAVE_BYTEARRAY */
75 * This struct contains ALL of PyMite's globals
77 typedef struct PmVmGlobal_s
79 /** Global none obj (none) */
82 /** Global integer 0 obj */
85 /** Global integer 1 obj */
88 /** Global integer -1 obj */
91 /** Global boolean False obj */
94 /** Global boolean True obj */
97 /** The string "code", used in interp.c RAISE_VARARGS */
100 /** Dict for 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 */
115 /** Line number for when an error occurs */
119 pPmList_t threadList
;
121 /** Ptr to current thread */
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 */
133 /** The string "next", used in interp.c FOR_ITER */
134 pPmString_t pnextStr
;
135 #endif /* HAVE_GENERATORS */
138 /** The string "Exception", used in RAISE_VARARGS */
140 #endif /* HAVE_ASSERT */
142 #ifdef HAVE_BYTEARRAY
143 /** The global string "bytearray" */
145 #endif /* HAVE_BYTEARRAY */
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 */
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
189 * @return Return status
191 PmReturn_t
global_loadBuiltins(void);
193 #endif /* __GLOBAL_H__ */