Embed:
(wiki syntax)
Show/hide line numbers
global.h
Go to the documentation of this file.
00001 /* 00002 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. 00003 # 00004 # This file is part of the PyMite VM. 00005 # The PyMite VM is free software: you can redistribute it and/or modify 00006 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. 00007 # 00008 # The PyMite VM is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 00012 # is seen in the file COPYING in this directory. 00013 */ 00014 00015 00016 #ifndef __GLOBAL_H__ 00017 #define __GLOBAL_H__ 00018 00019 00020 /** 00021 * \file 00022 * \brief VM Globals 00023 * 00024 * VM globals header. 00025 */ 00026 00027 00028 /** The global root PmGlobals Dict object */ 00029 #define PM_PBUILTINS (pPmObj_t)(gVmGlobal.builtins) 00030 00031 /** The global None object */ 00032 #define PM_NONE (pPmObj_t)(gVmGlobal.pnone) 00033 00034 /** The global False object */ 00035 #define PM_FALSE (pPmObj_t)(gVmGlobal.pfalse) 00036 00037 /** The global True object */ 00038 #define PM_TRUE (pPmObj_t)(gVmGlobal.ptrue) 00039 00040 /** The global integer 0 object */ 00041 #define PM_ZERO (pPmObj_t)(gVmGlobal.pzero) 00042 00043 /** The global integer 1 object */ 00044 #define PM_ONE (pPmObj_t)(gVmGlobal.pone) 00045 00046 /** The global integer -1 object */ 00047 #define PM_NEGONE (pPmObj_t)(gVmGlobal.pnegone) 00048 00049 /** The global string "code" */ 00050 #define PM_CODE_STR (pPmObj_t)(gVmGlobal.pcodeStr) 00051 00052 #ifdef HAVE_CLASSES 00053 /** The global string "__init__" */ 00054 #define PM_INIT_STR (pPmObj_t)(gVmGlobal.pinitStr) 00055 #endif /* HAVE_CLASSES */ 00056 00057 #ifdef HAVE_GENERATORS 00058 /** The global string "Generator" */ 00059 #define PM_GENERATOR_STR (pPmObj_t)(gVmGlobal.pgenStr) 00060 /** The global string "next" */ 00061 #define PM_NEXT_STR (pPmObj_t)(gVmGlobal.pnextStr) 00062 #endif /* HAVE_GENERATORS */ 00063 00064 #ifdef HAVE_ASSERT 00065 /** The global string "Exception" */ 00066 #define PM_EXCEPTION_STR (pPmObj_t)(gVmGlobal.pexnStr) 00067 #endif /* HAVE_ASSERT */ 00068 00069 /** 00070 * This struct contains ALL of PyMite's globals 00071 */ 00072 typedef struct PmVmGlobal_s 00073 { 00074 /** Global none obj (none) */ 00075 pPmObj_t pnone; 00076 00077 /** Global integer 0 obj */ 00078 pPmInt_t pzero; 00079 00080 /** Global integer 1 obj */ 00081 pPmInt_t pone; 00082 00083 /** Global integer -1 obj */ 00084 pPmInt_t pnegone; 00085 00086 /** Global boolean False obj */ 00087 pPmInt_t pfalse; 00088 00089 /** Global boolean True obj */ 00090 pPmInt_t ptrue; 00091 00092 /** The string "code", used in interp.c RAISE_VARARGS */ 00093 pPmString_t pcodeStr; 00094 00095 /** Dict for builtins */ 00096 pPmDict_t builtins; 00097 00098 /** Paths to available images */ 00099 PmImgPaths_t imgPaths; 00100 00101 /** The single native frame. Static alloc so it won't be GC'd */ 00102 PmNativeFrame_t nativeframe; 00103 00104 /** PyMite release value for when an error occurs */ 00105 uint8_t errVmRelease; 00106 00107 /** PyMite source file ID number for when an error occurs */ 00108 uint8_t errFileId; 00109 00110 /** Line number for when an error occurs */ 00111 uint16_t errLineNum; 00112 00113 /** Thread list */ 00114 pPmList_t threadList; 00115 00116 /** Ptr to current thread */ 00117 pPmThread_t pthread; 00118 00119 #ifdef HAVE_CLASSES 00120 /* NOTE: placing this field before the nativeframe field causes errors */ 00121 /** The string "__init__", used in interp.c CALL_FUNCTION */ 00122 pPmString_t pinitStr; 00123 #endif /* HAVE_CLASSES */ 00124 00125 #ifdef HAVE_GENERATORS 00126 /** The string "Generator", used in interp.c CALL_FUNCTION */ 00127 pPmString_t pgenStr; 00128 /** The string "next", used in interp.c FOR_ITER */ 00129 pPmString_t pnextStr; 00130 #endif /* HAVE_GENERATORS */ 00131 00132 #ifdef HAVE_ASSERT 00133 /** The string "Exception", used in RAISE_VARARGS */ 00134 pPmString_t pexnStr; 00135 #endif /* HAVE_ASSERT */ 00136 00137 /** Flag to trigger rescheduling */ 00138 uint8_t reschedule; 00139 } PmVmGlobal_t, 00140 *pPmVmGlobal_t; 00141 00142 00143 extern volatile PmVmGlobal_t gVmGlobal; 00144 00145 00146 /** 00147 * Initializes the global struct 00148 * 00149 * @return Return status 00150 */ 00151 PmReturn_t global_init(void); 00152 00153 /** 00154 * Sets the builtins dict into the given module's attrs. 00155 * 00156 * If not yet done, loads the "__bt" module via global_loadBuiltins(). 00157 * Restrictions described in that functions documentation apply. 00158 * 00159 * @param pmod Module whose attrs receive builtins 00160 * @return Return status 00161 */ 00162 PmReturn_t global_setBuiltins(pPmFunc_t pmod); 00163 00164 /** 00165 * Loads the "__bt" module and sets the builtins dict (PM_PBUILTINS) 00166 * to point to __bt's attributes dict. 00167 * Creates "None" = None entry in builtins. 00168 * 00169 * When run, there should not be any other threads in the interpreter 00170 * thread list yet. 00171 * 00172 * @return Return status 00173 */ 00174 PmReturn_t global_loadBuiltins(void); 00175 00176 #endif /* __GLOBAL_H__ */
Generated on Tue Jul 12 2022 17:07:01 by
1.7.2