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 # 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 __CLASS_H__ 00017 #define __CLASS_H__ 00018 00019 /** 00020 * \file 00021 * \brief Class header. 00022 */ 00023 00024 00025 /** 00026 * Class struct 00027 * 00028 * This C struct is used for PyMite class objects 00029 * Note: Exceptions are objects. 00030 */ 00031 typedef struct PmClass_s 00032 { 00033 /** Object descriptor */ 00034 PmObjDesc_t od; 00035 00036 /** Attributes dict */ 00037 pPmDict_t cl_attrs; 00038 00039 /** Bases tuple */ 00040 pPmTuple_t cl_bases; 00041 } PmClass_t, 00042 *pPmClass_t; 00043 00044 /** Class instance struct */ 00045 typedef struct PmInstance_s 00046 { 00047 /** Object descriptor */ 00048 PmObjDesc_t od; 00049 00050 /** Class of this instance */ 00051 pPmClass_t cli_class; 00052 00053 /** Attributes dict */ 00054 pPmDict_t cli_attrs; 00055 } PmInstance_t, 00056 *pPmInstance_t; 00057 00058 /** Method struct */ 00059 typedef struct PmMethod_s 00060 { 00061 /** Object descriptor */ 00062 PmObjDesc_t od; 00063 00064 /** Class instance of this method */ 00065 pPmInstance_t m_instance; 00066 00067 /** Func of this method */ 00068 pPmFunc_t m_func; 00069 00070 /** Attributes dict */ 00071 pPmDict_t m_attrs; 00072 } PmMethod_t, 00073 *pPmMethod_t; 00074 00075 00076 /** 00077 * Creates a new Class object from the methods dict, bases tuple, 00078 * and name string. 00079 * 00080 * @param pmeths ptr to methods dict. 00081 * @param pbases ptr to bases tuple. 00082 * @param pname ptr to name string. 00083 * @param r_pclass Return by ref, ptr to new class 00084 * @return Return status 00085 */ 00086 PmReturn_t class_new(pPmObj_t pmeths, pPmObj_t pbases, pPmObj_t pname, 00087 pPmObj_t *r_pclass); 00088 00089 /** 00090 * Returns an instance of the given class 00091 * 00092 * @param pclass Pointer to class object 00093 * @param r_pobj Return by ref, instance object 00094 * @return Return status 00095 */ 00096 PmReturn_t class_instantiate(pPmObj_t pclass, pPmObj_t *r_pobj); 00097 00098 /** 00099 * Returns a method based on the given inputs 00100 * 00101 * @param pinstance ptr to instance 00102 * @param pfunc ptr to func 00103 * @param r_pmeth Return by ref, ptr to new method 00104 * @return Return status 00105 */ 00106 PmReturn_t class_method(pPmObj_t pinstance, pPmObj_t pfunc, pPmObj_t *r_pmeth); 00107 00108 /** 00109 * Returns the first attribute named __init__ in the class' inheritance tree 00110 * 00111 * @param pobj ptr to class or instance to search 00112 * @param pname ptr to name of attr to find 00113 * @param r_pobj Return by ref, ptr to attr if found, or undetermined 00114 * @return Return status 00115 */ 00116 PmReturn_t class_getAttr(pPmObj_t pobj, pPmObj_t pname, pPmObj_t *r_pobj); 00117 00118 /** 00119 * Returns a C boolean if the base class is found in the inheritance tree 00120 * of the test class. NOTE: This function is recursive. 00121 * 00122 * @param ptest_class ptr to class whose inheritance tree is searched 00123 * @param pbase_class ptr to class to look for 00124 * @return Returns C_TRUE if pbase_class is found in the inheritance tree; 00125 * C_FALSE otherwise. 00126 */ 00127 uint8_t class_isSubclass(pPmObj_t ptest_class, pPmObj_t pbase_class); 00128 00129 #endif /* __CLASS_H__ */
Generated on Tue Jul 12 2022 17:07:01 by
1.7.2