Norimasa Okamoto
/
pymite
python-on-a-chip online compiler
- http://pymbed.appspot.com/
- https://code.google.com/p/python-on-a-chip/
- http://www.youtube.com/watch?v=Oyqc2bFRW9I
- https://bitbucket.org/va009039/pymbed/
more info: python-on-a-chip
vm/class.h@15:94ca5c8003e5, 2016-04-14 (annotated)
- Committer:
- va009039
- Date:
- Thu Apr 14 22:32:57 2016 +0000
- Revision:
- 15:94ca5c8003e5
- Parent:
- 0:65f1469d6bfb
update Nucleo-F401RE.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:65f1469d6bfb | 1 | /* |
va009039 | 0:65f1469d6bfb | 2 | # This file is Copyright 2009 Dean Hall. |
va009039 | 0:65f1469d6bfb | 3 | # This file is part of the PyMite VM. |
va009039 | 0:65f1469d6bfb | 4 | # This file is licensed under the MIT License. |
va009039 | 0:65f1469d6bfb | 5 | # See the LICENSE file for details. |
va009039 | 0:65f1469d6bfb | 6 | */ |
va009039 | 0:65f1469d6bfb | 7 | |
va009039 | 0:65f1469d6bfb | 8 | |
va009039 | 0:65f1469d6bfb | 9 | #ifndef __CLASS_H__ |
va009039 | 0:65f1469d6bfb | 10 | #define __CLASS_H__ |
va009039 | 0:65f1469d6bfb | 11 | |
va009039 | 0:65f1469d6bfb | 12 | /** |
va009039 | 0:65f1469d6bfb | 13 | * \file |
va009039 | 0:65f1469d6bfb | 14 | * \brief Class header. |
va009039 | 0:65f1469d6bfb | 15 | */ |
va009039 | 0:65f1469d6bfb | 16 | |
va009039 | 0:65f1469d6bfb | 17 | |
va009039 | 0:65f1469d6bfb | 18 | /** |
va009039 | 0:65f1469d6bfb | 19 | * Class struct |
va009039 | 0:65f1469d6bfb | 20 | * |
va009039 | 0:65f1469d6bfb | 21 | * This C struct is used for PyMite class objects |
va009039 | 0:65f1469d6bfb | 22 | * Note: Exceptions are objects. |
va009039 | 0:65f1469d6bfb | 23 | */ |
va009039 | 0:65f1469d6bfb | 24 | typedef struct PmClass_s |
va009039 | 0:65f1469d6bfb | 25 | { |
va009039 | 0:65f1469d6bfb | 26 | /** Object descriptor */ |
va009039 | 0:65f1469d6bfb | 27 | PmObjDesc_t od; |
va009039 | 0:65f1469d6bfb | 28 | |
va009039 | 0:65f1469d6bfb | 29 | /** Attributes dict */ |
va009039 | 0:65f1469d6bfb | 30 | pPmDict_t cl_attrs; |
va009039 | 0:65f1469d6bfb | 31 | |
va009039 | 0:65f1469d6bfb | 32 | /** Bases tuple */ |
va009039 | 0:65f1469d6bfb | 33 | pPmTuple_t cl_bases; |
va009039 | 0:65f1469d6bfb | 34 | } PmClass_t, |
va009039 | 0:65f1469d6bfb | 35 | *pPmClass_t; |
va009039 | 0:65f1469d6bfb | 36 | |
va009039 | 0:65f1469d6bfb | 37 | /** Class instance struct */ |
va009039 | 0:65f1469d6bfb | 38 | typedef struct PmInstance_s |
va009039 | 0:65f1469d6bfb | 39 | { |
va009039 | 0:65f1469d6bfb | 40 | /** Object descriptor */ |
va009039 | 0:65f1469d6bfb | 41 | PmObjDesc_t od; |
va009039 | 0:65f1469d6bfb | 42 | |
va009039 | 0:65f1469d6bfb | 43 | /** Class of this instance */ |
va009039 | 0:65f1469d6bfb | 44 | pPmClass_t cli_class; |
va009039 | 0:65f1469d6bfb | 45 | |
va009039 | 0:65f1469d6bfb | 46 | /** Attributes dict */ |
va009039 | 0:65f1469d6bfb | 47 | pPmDict_t cli_attrs; |
va009039 | 0:65f1469d6bfb | 48 | } PmInstance_t, |
va009039 | 0:65f1469d6bfb | 49 | *pPmInstance_t; |
va009039 | 0:65f1469d6bfb | 50 | |
va009039 | 0:65f1469d6bfb | 51 | /** Method struct */ |
va009039 | 0:65f1469d6bfb | 52 | typedef struct PmMethod_s |
va009039 | 0:65f1469d6bfb | 53 | { |
va009039 | 0:65f1469d6bfb | 54 | /** Object descriptor */ |
va009039 | 0:65f1469d6bfb | 55 | PmObjDesc_t od; |
va009039 | 0:65f1469d6bfb | 56 | |
va009039 | 0:65f1469d6bfb | 57 | /** Class instance of this method */ |
va009039 | 0:65f1469d6bfb | 58 | pPmInstance_t m_instance; |
va009039 | 0:65f1469d6bfb | 59 | |
va009039 | 0:65f1469d6bfb | 60 | /** Func of this method */ |
va009039 | 0:65f1469d6bfb | 61 | pPmFunc_t m_func; |
va009039 | 0:65f1469d6bfb | 62 | |
va009039 | 0:65f1469d6bfb | 63 | /** Attributes dict */ |
va009039 | 0:65f1469d6bfb | 64 | pPmDict_t m_attrs; |
va009039 | 0:65f1469d6bfb | 65 | } PmMethod_t, |
va009039 | 0:65f1469d6bfb | 66 | *pPmMethod_t; |
va009039 | 0:65f1469d6bfb | 67 | |
va009039 | 0:65f1469d6bfb | 68 | |
va009039 | 0:65f1469d6bfb | 69 | /** |
va009039 | 0:65f1469d6bfb | 70 | * Creates a new Class object from the methods dict, bases tuple, |
va009039 | 0:65f1469d6bfb | 71 | * and name string. |
va009039 | 0:65f1469d6bfb | 72 | * |
va009039 | 0:65f1469d6bfb | 73 | * @param pmeths ptr to methods dict. |
va009039 | 0:65f1469d6bfb | 74 | * @param pbases ptr to bases tuple. |
va009039 | 0:65f1469d6bfb | 75 | * @param pname ptr to name string. |
va009039 | 0:65f1469d6bfb | 76 | * @param r_pclass Return by ref, ptr to new class |
va009039 | 0:65f1469d6bfb | 77 | * @return Return status |
va009039 | 0:65f1469d6bfb | 78 | */ |
va009039 | 0:65f1469d6bfb | 79 | PmReturn_t class_new(pPmObj_t pmeths, pPmObj_t pbases, pPmObj_t pname, |
va009039 | 0:65f1469d6bfb | 80 | pPmObj_t *r_pclass); |
va009039 | 0:65f1469d6bfb | 81 | |
va009039 | 0:65f1469d6bfb | 82 | /** |
va009039 | 0:65f1469d6bfb | 83 | * Returns an instance of the given class |
va009039 | 0:65f1469d6bfb | 84 | * |
va009039 | 0:65f1469d6bfb | 85 | * @param pclass Pointer to class object |
va009039 | 0:65f1469d6bfb | 86 | * @param r_pobj Return by ref, instance object |
va009039 | 0:65f1469d6bfb | 87 | * @return Return status |
va009039 | 0:65f1469d6bfb | 88 | */ |
va009039 | 0:65f1469d6bfb | 89 | PmReturn_t class_instantiate(pPmObj_t pclass, pPmObj_t *r_pobj); |
va009039 | 0:65f1469d6bfb | 90 | |
va009039 | 0:65f1469d6bfb | 91 | #ifdef HAVE_AUTOBOX |
va009039 | 0:65f1469d6bfb | 92 | /** |
va009039 | 0:65f1469d6bfb | 93 | * Autoboxes an object in place |
va009039 | 0:65f1469d6bfb | 94 | * |
va009039 | 0:65f1469d6bfb | 95 | * @param pclass Pointer to object |
va009039 | 0:65f1469d6bfb | 96 | * @return Return status |
va009039 | 0:65f1469d6bfb | 97 | */ |
va009039 | 0:65f1469d6bfb | 98 | PmReturn_t class_autobox(pPmObj_t *pobj); |
va009039 | 0:65f1469d6bfb | 99 | #endif |
va009039 | 0:65f1469d6bfb | 100 | |
va009039 | 0:65f1469d6bfb | 101 | /** |
va009039 | 0:65f1469d6bfb | 102 | * Returns a method based on the given inputs |
va009039 | 0:65f1469d6bfb | 103 | * |
va009039 | 0:65f1469d6bfb | 104 | * @param pinstance ptr to instance |
va009039 | 0:65f1469d6bfb | 105 | * @param pfunc ptr to func |
va009039 | 0:65f1469d6bfb | 106 | * @param r_pmeth Return by ref, ptr to new method |
va009039 | 0:65f1469d6bfb | 107 | * @return Return status |
va009039 | 0:65f1469d6bfb | 108 | */ |
va009039 | 0:65f1469d6bfb | 109 | PmReturn_t class_method(pPmObj_t pinstance, pPmObj_t pfunc, pPmObj_t *r_pmeth); |
va009039 | 0:65f1469d6bfb | 110 | |
va009039 | 0:65f1469d6bfb | 111 | /** |
va009039 | 0:65f1469d6bfb | 112 | * Returns the first attribute named __init__ in the class' inheritance tree |
va009039 | 0:65f1469d6bfb | 113 | * |
va009039 | 0:65f1469d6bfb | 114 | * @param pobj ptr to class or instance to search |
va009039 | 0:65f1469d6bfb | 115 | * @param pname ptr to name of attr to find |
va009039 | 0:65f1469d6bfb | 116 | * @param r_pobj Return by ref, ptr to attr if found, or undetermined |
va009039 | 0:65f1469d6bfb | 117 | * @return Return status |
va009039 | 0:65f1469d6bfb | 118 | */ |
va009039 | 0:65f1469d6bfb | 119 | PmReturn_t class_getAttr(pPmObj_t pobj, pPmObj_t pname, pPmObj_t *r_pobj); |
va009039 | 0:65f1469d6bfb | 120 | |
va009039 | 0:65f1469d6bfb | 121 | /** |
va009039 | 0:65f1469d6bfb | 122 | * Returns a C boolean if the base class is found in the inheritance tree |
va009039 | 0:65f1469d6bfb | 123 | * of the test class. NOTE: This function is recursive. |
va009039 | 0:65f1469d6bfb | 124 | * |
va009039 | 0:65f1469d6bfb | 125 | * @param ptest_class ptr to class whose inheritance tree is searched |
va009039 | 0:65f1469d6bfb | 126 | * @param pbase_class ptr to class to look for |
va009039 | 0:65f1469d6bfb | 127 | * @return Returns C_TRUE if pbase_class is found in the inheritance tree; |
va009039 | 0:65f1469d6bfb | 128 | * C_FALSE otherwise. |
va009039 | 0:65f1469d6bfb | 129 | */ |
va009039 | 0:65f1469d6bfb | 130 | uint8_t class_isSubclass(pPmObj_t ptest_class, pPmObj_t pbase_class); |
va009039 | 0:65f1469d6bfb | 131 | |
va009039 | 0:65f1469d6bfb | 132 | #endif /* __CLASS_H__ */ |