Norimasa Okamoto
/
pymite
python-on-a-chip online compiler
Embed:
(wiki syntax)
Show/hide line numbers
class.h
Go to the documentation of this file.
00001 /* 00002 # This file is Copyright 2009 Dean Hall. 00003 # This file is part of the PyMite VM. 00004 # This file is licensed under the MIT License. 00005 # See the LICENSE file for details. 00006 */ 00007 00008 00009 #ifndef __CLASS_H__ 00010 #define __CLASS_H__ 00011 00012 /** 00013 * \file 00014 * \brief Class header. 00015 */ 00016 00017 00018 /** 00019 * Class struct 00020 * 00021 * This C struct is used for PyMite class objects 00022 * Note: Exceptions are objects. 00023 */ 00024 typedef struct PmClass_s 00025 { 00026 /** Object descriptor */ 00027 PmObjDesc_t od; 00028 00029 /** Attributes dict */ 00030 pPmDict_t cl_attrs; 00031 00032 /** Bases tuple */ 00033 pPmTuple_t cl_bases; 00034 } PmClass_t, 00035 *pPmClass_t; 00036 00037 /** Class instance struct */ 00038 typedef struct PmInstance_s 00039 { 00040 /** Object descriptor */ 00041 PmObjDesc_t od; 00042 00043 /** Class of this instance */ 00044 pPmClass_t cli_class; 00045 00046 /** Attributes dict */ 00047 pPmDict_t cli_attrs; 00048 } PmInstance_t, 00049 *pPmInstance_t; 00050 00051 /** Method struct */ 00052 typedef struct PmMethod_s 00053 { 00054 /** Object descriptor */ 00055 PmObjDesc_t od; 00056 00057 /** Class instance of this method */ 00058 pPmInstance_t m_instance; 00059 00060 /** Func of this method */ 00061 pPmFunc_t m_func; 00062 00063 /** Attributes dict */ 00064 pPmDict_t m_attrs; 00065 } PmMethod_t, 00066 *pPmMethod_t; 00067 00068 00069 /** 00070 * Creates a new Class object from the methods dict, bases tuple, 00071 * and name string. 00072 * 00073 * @param pmeths ptr to methods dict. 00074 * @param pbases ptr to bases tuple. 00075 * @param pname ptr to name string. 00076 * @param r_pclass Return by ref, ptr to new class 00077 * @return Return status 00078 */ 00079 PmReturn_t class_new(pPmObj_t pmeths, pPmObj_t pbases, pPmObj_t pname, 00080 pPmObj_t *r_pclass); 00081 00082 /** 00083 * Returns an instance of the given class 00084 * 00085 * @param pclass Pointer to class object 00086 * @param r_pobj Return by ref, instance object 00087 * @return Return status 00088 */ 00089 PmReturn_t class_instantiate(pPmObj_t pclass, pPmObj_t *r_pobj); 00090 00091 #ifdef HAVE_AUTOBOX 00092 /** 00093 * Autoboxes an object in place 00094 * 00095 * @param pclass Pointer to object 00096 * @return Return status 00097 */ 00098 PmReturn_t class_autobox(pPmObj_t *pobj); 00099 #endif 00100 00101 /** 00102 * Returns a method based on the given inputs 00103 * 00104 * @param pinstance ptr to instance 00105 * @param pfunc ptr to func 00106 * @param r_pmeth Return by ref, ptr to new method 00107 * @return Return status 00108 */ 00109 PmReturn_t class_method(pPmObj_t pinstance, pPmObj_t pfunc, pPmObj_t *r_pmeth); 00110 00111 /** 00112 * Returns the first attribute named __init__ in the class' inheritance tree 00113 * 00114 * @param pobj ptr to class or instance to search 00115 * @param pname ptr to name of attr to find 00116 * @param r_pobj Return by ref, ptr to attr if found, or undetermined 00117 * @return Return status 00118 */ 00119 PmReturn_t class_getAttr(pPmObj_t pobj, pPmObj_t pname, pPmObj_t *r_pobj); 00120 00121 /** 00122 * Returns a C boolean if the base class is found in the inheritance tree 00123 * of the test class. NOTE: This function is recursive. 00124 * 00125 * @param ptest_class ptr to class whose inheritance tree is searched 00126 * @param pbase_class ptr to class to look for 00127 * @return Returns C_TRUE if pbase_class is found in the inheritance tree; 00128 * C_FALSE otherwise. 00129 */ 00130 uint8_t class_isSubclass(pPmObj_t ptest_class, pPmObj_t pbase_class); 00131 00132 #endif /* __CLASS_H__ */
Generated on Tue Jul 12 2022 23:13:47 by 1.7.2