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/int.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 2002 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 __INT_H__ |
va009039 | 0:65f1469d6bfb | 10 | #define __INT_H__ |
va009039 | 0:65f1469d6bfb | 11 | |
va009039 | 0:65f1469d6bfb | 12 | |
va009039 | 0:65f1469d6bfb | 13 | /** |
va009039 | 0:65f1469d6bfb | 14 | * \file |
va009039 | 0:65f1469d6bfb | 15 | * \brief Integer Object Type |
va009039 | 0:65f1469d6bfb | 16 | * |
va009039 | 0:65f1469d6bfb | 17 | * Integer object type header. |
va009039 | 0:65f1469d6bfb | 18 | */ |
va009039 | 0:65f1469d6bfb | 19 | |
va009039 | 0:65f1469d6bfb | 20 | /** |
va009039 | 0:65f1469d6bfb | 21 | * Integer obj |
va009039 | 0:65f1469d6bfb | 22 | * |
va009039 | 0:65f1469d6bfb | 23 | * 32b signed integer |
va009039 | 0:65f1469d6bfb | 24 | */ |
va009039 | 0:65f1469d6bfb | 25 | typedef struct PmInt_s |
va009039 | 0:65f1469d6bfb | 26 | { |
va009039 | 0:65f1469d6bfb | 27 | /** Object descriptor */ |
va009039 | 0:65f1469d6bfb | 28 | PmObjDesc_t od; |
va009039 | 0:65f1469d6bfb | 29 | |
va009039 | 0:65f1469d6bfb | 30 | /** Integer value */ |
va009039 | 0:65f1469d6bfb | 31 | int32_t val; |
va009039 | 0:65f1469d6bfb | 32 | } PmInt_t, |
va009039 | 0:65f1469d6bfb | 33 | *pPmInt_t; |
va009039 | 0:65f1469d6bfb | 34 | |
va009039 | 0:65f1469d6bfb | 35 | |
va009039 | 0:65f1469d6bfb | 36 | /** |
va009039 | 0:65f1469d6bfb | 37 | * Creates a duplicate Integer object |
va009039 | 0:65f1469d6bfb | 38 | * |
va009039 | 0:65f1469d6bfb | 39 | * Created specifically for the index value in FOR_LOOP. |
va009039 | 0:65f1469d6bfb | 40 | * |
va009039 | 0:65f1469d6bfb | 41 | * @param pint Pointer to int obj to duplicate. |
va009039 | 0:65f1469d6bfb | 42 | * @param r_pint Return by ref, ptr to new int |
va009039 | 0:65f1469d6bfb | 43 | * @return Return status |
va009039 | 0:65f1469d6bfb | 44 | */ |
va009039 | 0:65f1469d6bfb | 45 | PmReturn_t int_dup(pPmObj_t pint, pPmObj_t *r_pint); |
va009039 | 0:65f1469d6bfb | 46 | |
va009039 | 0:65f1469d6bfb | 47 | /** |
va009039 | 0:65f1469d6bfb | 48 | * Creates a new Integer object |
va009039 | 0:65f1469d6bfb | 49 | * |
va009039 | 0:65f1469d6bfb | 50 | * @param val Value to assign int (signed 32-bit). |
va009039 | 0:65f1469d6bfb | 51 | * @param r_pint Return by ref, ptr to new int |
va009039 | 0:65f1469d6bfb | 52 | * @return Return status |
va009039 | 0:65f1469d6bfb | 53 | */ |
va009039 | 0:65f1469d6bfb | 54 | PmReturn_t int_new(int32_t val, pPmObj_t *r_pint); |
va009039 | 0:65f1469d6bfb | 55 | |
va009039 | 0:65f1469d6bfb | 56 | /** |
va009039 | 0:65f1469d6bfb | 57 | * Implements the UNARY_POSITIVE bcode. |
va009039 | 0:65f1469d6bfb | 58 | * |
va009039 | 0:65f1469d6bfb | 59 | * Creates a new int with the same value as the given int. |
va009039 | 0:65f1469d6bfb | 60 | * |
va009039 | 0:65f1469d6bfb | 61 | * @param pobj Pointer to integer object |
va009039 | 0:65f1469d6bfb | 62 | * @param r_pint Return by reference, ptr to int |
va009039 | 0:65f1469d6bfb | 63 | * @return Return status |
va009039 | 0:65f1469d6bfb | 64 | */ |
va009039 | 0:65f1469d6bfb | 65 | PmReturn_t int_positive(pPmObj_t pobj, pPmObj_t *r_pint); |
va009039 | 0:65f1469d6bfb | 66 | |
va009039 | 0:65f1469d6bfb | 67 | /** |
va009039 | 0:65f1469d6bfb | 68 | * Implements the UNARY_NEGATIVE bcode. |
va009039 | 0:65f1469d6bfb | 69 | * |
va009039 | 0:65f1469d6bfb | 70 | * Creates a new int with a value that is the negative of the given int. |
va009039 | 0:65f1469d6bfb | 71 | * |
va009039 | 0:65f1469d6bfb | 72 | * @param pobj Pointer to target object |
va009039 | 0:65f1469d6bfb | 73 | * @param r_pint Return by ref, ptr to int |
va009039 | 0:65f1469d6bfb | 74 | * @return Return status |
va009039 | 0:65f1469d6bfb | 75 | */ |
va009039 | 0:65f1469d6bfb | 76 | PmReturn_t int_negative(pPmObj_t pobj, pPmObj_t *r_pint); |
va009039 | 0:65f1469d6bfb | 77 | |
va009039 | 0:65f1469d6bfb | 78 | /** |
va009039 | 0:65f1469d6bfb | 79 | * Implements the UNARY_INVERT bcode. |
va009039 | 0:65f1469d6bfb | 80 | * |
va009039 | 0:65f1469d6bfb | 81 | * Creates a new int with a value that is |
va009039 | 0:65f1469d6bfb | 82 | * the bitwise inversion of the given int. |
va009039 | 0:65f1469d6bfb | 83 | * |
va009039 | 0:65f1469d6bfb | 84 | * @param pobj Pointer to integer to invert |
va009039 | 0:65f1469d6bfb | 85 | * @param r_pint Return by reference; new integer |
va009039 | 0:65f1469d6bfb | 86 | * @return Return status |
va009039 | 0:65f1469d6bfb | 87 | */ |
va009039 | 0:65f1469d6bfb | 88 | PmReturn_t int_bitInvert(pPmObj_t pobj, pPmObj_t *r_pint); |
va009039 | 0:65f1469d6bfb | 89 | |
va009039 | 0:65f1469d6bfb | 90 | #ifdef HAVE_PRINT |
va009039 | 0:65f1469d6bfb | 91 | /** |
va009039 | 0:65f1469d6bfb | 92 | * Sends out an integer object in decimal notation with MSB first. |
va009039 | 0:65f1469d6bfb | 93 | * The number is preceded with a "-" when necessary. |
va009039 | 0:65f1469d6bfb | 94 | * |
va009039 | 0:65f1469d6bfb | 95 | * @param pObj Ptr to int object |
va009039 | 0:65f1469d6bfb | 96 | * @return Return status |
va009039 | 0:65f1469d6bfb | 97 | */ |
va009039 | 0:65f1469d6bfb | 98 | PmReturn_t int_print(pPmObj_t pint); |
va009039 | 0:65f1469d6bfb | 99 | |
va009039 | 0:65f1469d6bfb | 100 | /** |
va009039 | 0:65f1469d6bfb | 101 | * Prints the Int object in ascii-coded hexadecimal out the platform output |
va009039 | 0:65f1469d6bfb | 102 | * |
va009039 | 0:65f1469d6bfb | 103 | * @param pint Pointer to Int object |
va009039 | 0:65f1469d6bfb | 104 | */ |
va009039 | 0:65f1469d6bfb | 105 | PmReturn_t int_printHex(pPmObj_t pint); |
va009039 | 0:65f1469d6bfb | 106 | #endif /* HAVE_PRINT */ |
va009039 | 0:65f1469d6bfb | 107 | |
va009039 | 0:65f1469d6bfb | 108 | /** |
va009039 | 0:65f1469d6bfb | 109 | * Returns by reference an integer that is x raised to the power of y. |
va009039 | 0:65f1469d6bfb | 110 | * |
va009039 | 0:65f1469d6bfb | 111 | * @param px The integer base |
va009039 | 0:65f1469d6bfb | 112 | * @param py The integer exponent |
va009039 | 0:65f1469d6bfb | 113 | * @param r_pn Return by reference; New integer with value of x ** y |
va009039 | 0:65f1469d6bfb | 114 | * @return Return status |
va009039 | 0:65f1469d6bfb | 115 | */ |
va009039 | 0:65f1469d6bfb | 116 | PmReturn_t int_pow(pPmObj_t px, pPmObj_t py, pPmObj_t *r_pn); |
va009039 | 0:65f1469d6bfb | 117 | |
va009039 | 0:65f1469d6bfb | 118 | /** |
va009039 | 0:65f1469d6bfb | 119 | * Returns by reference the result of the selected operation. |
va009039 | 0:65f1469d6bfb | 120 | * |
va009039 | 0:65f1469d6bfb | 121 | * @param px The integer numerator |
va009039 | 0:65f1469d6bfb | 122 | * @param py The integer denominator |
va009039 | 0:65f1469d6bfb | 123 | * @param op The operator selector. '/' selects division, all else is modulus. |
va009039 | 0:65f1469d6bfb | 124 | * @param r_pn Return by reference; New integer with value of x / y or x % y. |
va009039 | 0:65f1469d6bfb | 125 | * @return Return status |
va009039 | 0:65f1469d6bfb | 126 | */ |
va009039 | 0:65f1469d6bfb | 127 | PmReturn_t int_divmod(pPmObj_t px, pPmObj_t py, uint8_t op, pPmObj_t *r_pxopy); |
va009039 | 0:65f1469d6bfb | 128 | |
va009039 | 0:65f1469d6bfb | 129 | #endif /* __INT_H__ */ |