2 # This file is Copyright 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.
21 * \brief Class header.
28 * This C struct is used for PyMite class objects
29 * Note: Exceptions are objects.
31 typedef struct PmClass_s
33 /** Object descriptor */
36 /** Attributes dict */
44 /** Class instance struct */
45 typedef struct PmInstance_s
47 /** Object descriptor */
50 /** Class of this instance */
53 /** Attributes dict */
59 typedef struct PmMethod_s
61 /** Object descriptor */
64 /** Class instance of this method */
65 pPmInstance_t m_instance
;
67 /** Func of this method */
70 /** Attributes dict */
77 * Creates a new Class object from the methods dict, bases tuple,
80 * @param pmeths ptr to methods dict.
81 * @param pbases ptr to bases tuple.
82 * @param pname ptr to name string.
83 * @param r_pclass Return by ref, ptr to new class
84 * @return Return status
86 PmReturn_t
class_new(pPmObj_t pmeths
, pPmObj_t pbases
, pPmObj_t pname
,
90 * Returns an instance of the given class
92 * @param pclass Pointer to class object
93 * @param r_pobj Return by ref, instance object
94 * @return Return status
96 PmReturn_t
class_instantiate(pPmObj_t pclass
, pPmObj_t
*r_pobj
);
99 * Returns a method based on the given inputs
101 * @param pinstance ptr to instance
102 * @param pfunc ptr to func
103 * @param r_pmeth Return by ref, ptr to new method
104 * @return Return status
106 PmReturn_t
class_method(pPmObj_t pinstance
, pPmObj_t pfunc
, pPmObj_t
*r_pmeth
);
109 * Returns the first attribute named __init__ in the class' inheritance tree
111 * @param pobj ptr to class or instance to search
112 * @param pname ptr to name of attr to find
113 * @param r_pobj Return by ref, ptr to attr if found, or undetermined
114 * @return Return status
116 PmReturn_t
class_getAttr(pPmObj_t pobj
, pPmObj_t pname
, pPmObj_t
*r_pobj
);
119 * Returns a C boolean if the base class is found in the inheritance tree
120 * of the test class. NOTE: This function is recursive.
122 * @param ptest_class ptr to class whose inheritance tree is searched
123 * @param pbase_class ptr to class to look for
124 * @return Returns C_TRUE if pbase_class is found in the inheritance tree;
127 uint8_t class_isSubclass(pPmObj_t ptest_class
, pPmObj_t pbase_class
);
129 #endif /* __CLASS_H__ */