Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
src/vm/int.h@0:14e5e829dffe, 2010-07-21 (annotated)
- Committer:
- dadaista
- Date:
- Wed Jul 21 12:50:41 2010 +0000
- Revision:
- 0:14e5e829dffe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dadaista | 0:14e5e829dffe | 1 | /* |
dadaista | 0:14e5e829dffe | 2 | # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. |
dadaista | 0:14e5e829dffe | 3 | # |
dadaista | 0:14e5e829dffe | 4 | # This file is part of the PyMite VM. |
dadaista | 0:14e5e829dffe | 5 | # The PyMite VM is free software: you can redistribute it and/or modify |
dadaista | 0:14e5e829dffe | 6 | # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. |
dadaista | 0:14e5e829dffe | 7 | # |
dadaista | 0:14e5e829dffe | 8 | # The PyMite VM is distributed in the hope that it will be useful, |
dadaista | 0:14e5e829dffe | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
dadaista | 0:14e5e829dffe | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
dadaista | 0:14e5e829dffe | 11 | # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 |
dadaista | 0:14e5e829dffe | 12 | # is seen in the file COPYING in this directory. |
dadaista | 0:14e5e829dffe | 13 | */ |
dadaista | 0:14e5e829dffe | 14 | |
dadaista | 0:14e5e829dffe | 15 | |
dadaista | 0:14e5e829dffe | 16 | #ifndef __INT_H__ |
dadaista | 0:14e5e829dffe | 17 | #define __INT_H__ |
dadaista | 0:14e5e829dffe | 18 | |
dadaista | 0:14e5e829dffe | 19 | |
dadaista | 0:14e5e829dffe | 20 | /** |
dadaista | 0:14e5e829dffe | 21 | * \file |
dadaista | 0:14e5e829dffe | 22 | * \brief Integer Object Type |
dadaista | 0:14e5e829dffe | 23 | * |
dadaista | 0:14e5e829dffe | 24 | * Integer object type header. |
dadaista | 0:14e5e829dffe | 25 | */ |
dadaista | 0:14e5e829dffe | 26 | |
dadaista | 0:14e5e829dffe | 27 | /** |
dadaista | 0:14e5e829dffe | 28 | * Integer obj |
dadaista | 0:14e5e829dffe | 29 | * |
dadaista | 0:14e5e829dffe | 30 | * 32b signed integer |
dadaista | 0:14e5e829dffe | 31 | */ |
dadaista | 0:14e5e829dffe | 32 | typedef struct PmInt_s |
dadaista | 0:14e5e829dffe | 33 | { |
dadaista | 0:14e5e829dffe | 34 | /** Object descriptor */ |
dadaista | 0:14e5e829dffe | 35 | PmObjDesc_t od; |
dadaista | 0:14e5e829dffe | 36 | |
dadaista | 0:14e5e829dffe | 37 | /** Integer value */ |
dadaista | 0:14e5e829dffe | 38 | int32_t val; |
dadaista | 0:14e5e829dffe | 39 | } PmInt_t, |
dadaista | 0:14e5e829dffe | 40 | *pPmInt_t; |
dadaista | 0:14e5e829dffe | 41 | |
dadaista | 0:14e5e829dffe | 42 | |
dadaista | 0:14e5e829dffe | 43 | /** |
dadaista | 0:14e5e829dffe | 44 | * Creates a duplicate Integer object |
dadaista | 0:14e5e829dffe | 45 | * |
dadaista | 0:14e5e829dffe | 46 | * Created specifically for the index value in FOR_LOOP. |
dadaista | 0:14e5e829dffe | 47 | * |
dadaista | 0:14e5e829dffe | 48 | * @param pint Pointer to int obj to duplicate. |
dadaista | 0:14e5e829dffe | 49 | * @param r_pint Return by ref, ptr to new int |
dadaista | 0:14e5e829dffe | 50 | * @return Return status |
dadaista | 0:14e5e829dffe | 51 | */ |
dadaista | 0:14e5e829dffe | 52 | PmReturn_t int_dup(pPmObj_t pint, pPmObj_t *r_pint); |
dadaista | 0:14e5e829dffe | 53 | |
dadaista | 0:14e5e829dffe | 54 | /** |
dadaista | 0:14e5e829dffe | 55 | * Creates a new Integer object |
dadaista | 0:14e5e829dffe | 56 | * |
dadaista | 0:14e5e829dffe | 57 | * @param val Value to assign int (signed 32-bit). |
dadaista | 0:14e5e829dffe | 58 | * @param r_pint Return by ref, ptr to new int |
dadaista | 0:14e5e829dffe | 59 | * @return Return status |
dadaista | 0:14e5e829dffe | 60 | */ |
dadaista | 0:14e5e829dffe | 61 | PmReturn_t int_new(int32_t val, pPmObj_t *r_pint); |
dadaista | 0:14e5e829dffe | 62 | |
dadaista | 0:14e5e829dffe | 63 | /** |
dadaista | 0:14e5e829dffe | 64 | * Implements the UNARY_POSITIVE bcode. |
dadaista | 0:14e5e829dffe | 65 | * |
dadaista | 0:14e5e829dffe | 66 | * Creates a new int with the same value as the given int. |
dadaista | 0:14e5e829dffe | 67 | * |
dadaista | 0:14e5e829dffe | 68 | * @param pobj Pointer to integer object |
dadaista | 0:14e5e829dffe | 69 | * @param r_pint Return by reference, ptr to int |
dadaista | 0:14e5e829dffe | 70 | * @return Return status |
dadaista | 0:14e5e829dffe | 71 | */ |
dadaista | 0:14e5e829dffe | 72 | PmReturn_t int_positive(pPmObj_t pobj, pPmObj_t *r_pint); |
dadaista | 0:14e5e829dffe | 73 | |
dadaista | 0:14e5e829dffe | 74 | /** |
dadaista | 0:14e5e829dffe | 75 | * Implements the UNARY_NEGATIVE bcode. |
dadaista | 0:14e5e829dffe | 76 | * |
dadaista | 0:14e5e829dffe | 77 | * Creates a new int with a value that is the negative of the given int. |
dadaista | 0:14e5e829dffe | 78 | * |
dadaista | 0:14e5e829dffe | 79 | * @param pobj Pointer to target object |
dadaista | 0:14e5e829dffe | 80 | * @param r_pint Return by ref, ptr to int |
dadaista | 0:14e5e829dffe | 81 | * @return Return status |
dadaista | 0:14e5e829dffe | 82 | */ |
dadaista | 0:14e5e829dffe | 83 | PmReturn_t int_negative(pPmObj_t pobj, pPmObj_t *r_pint); |
dadaista | 0:14e5e829dffe | 84 | |
dadaista | 0:14e5e829dffe | 85 | /** |
dadaista | 0:14e5e829dffe | 86 | * Implements the UNARY_INVERT bcode. |
dadaista | 0:14e5e829dffe | 87 | * |
dadaista | 0:14e5e829dffe | 88 | * Creates a new int with a value that is |
dadaista | 0:14e5e829dffe | 89 | * the bitwise inversion of the given int. |
dadaista | 0:14e5e829dffe | 90 | * |
dadaista | 0:14e5e829dffe | 91 | * @param pobj Pointer to integer to invert |
dadaista | 0:14e5e829dffe | 92 | * @param r_pint Return by reference; new integer |
dadaista | 0:14e5e829dffe | 93 | * @return Return status |
dadaista | 0:14e5e829dffe | 94 | */ |
dadaista | 0:14e5e829dffe | 95 | PmReturn_t int_bitInvert(pPmObj_t pobj, pPmObj_t *r_pint); |
dadaista | 0:14e5e829dffe | 96 | |
dadaista | 0:14e5e829dffe | 97 | #ifdef HAVE_PRINT |
dadaista | 0:14e5e829dffe | 98 | /** |
dadaista | 0:14e5e829dffe | 99 | * Sends out an integer object in decimal notation with MSB first. |
dadaista | 0:14e5e829dffe | 100 | * The number is preceded with a "-" when necessary. |
dadaista | 0:14e5e829dffe | 101 | * |
dadaista | 0:14e5e829dffe | 102 | * @param pObj Ptr to int object |
dadaista | 0:14e5e829dffe | 103 | * @return Return status |
dadaista | 0:14e5e829dffe | 104 | */ |
dadaista | 0:14e5e829dffe | 105 | PmReturn_t int_print(pPmObj_t pint); |
dadaista | 0:14e5e829dffe | 106 | |
dadaista | 0:14e5e829dffe | 107 | /** |
dadaista | 0:14e5e829dffe | 108 | * Prints the byte in ascii-coded hexadecimal out the platform output |
dadaista | 0:14e5e829dffe | 109 | * |
dadaista | 0:14e5e829dffe | 110 | * @param b Byte to print |
dadaista | 0:14e5e829dffe | 111 | */ |
dadaista | 0:14e5e829dffe | 112 | PmReturn_t int_printHexByte(uint8_t b); |
dadaista | 0:14e5e829dffe | 113 | |
dadaista | 0:14e5e829dffe | 114 | /** |
dadaista | 0:14e5e829dffe | 115 | * Prints the integer in ascii-coded hexadecimal out the platform output |
dadaista | 0:14e5e829dffe | 116 | * |
dadaista | 0:14e5e829dffe | 117 | * @param n Integer to print |
dadaista | 0:14e5e829dffe | 118 | */ |
dadaista | 0:14e5e829dffe | 119 | PmReturn_t _int_printHex(intptr_t n); |
dadaista | 0:14e5e829dffe | 120 | |
dadaista | 0:14e5e829dffe | 121 | /** |
dadaista | 0:14e5e829dffe | 122 | * Prints the Int object in ascii-coded hexadecimal out the platform output |
dadaista | 0:14e5e829dffe | 123 | * |
dadaista | 0:14e5e829dffe | 124 | * @param pint Pointer to Int object |
dadaista | 0:14e5e829dffe | 125 | */ |
dadaista | 0:14e5e829dffe | 126 | PmReturn_t int_printHex(pPmObj_t pint); |
dadaista | 0:14e5e829dffe | 127 | #endif /* HAVE_PRINT */ |
dadaista | 0:14e5e829dffe | 128 | |
dadaista | 0:14e5e829dffe | 129 | /** |
dadaista | 0:14e5e829dffe | 130 | * Returns by reference an integer that is x raised to the power of y. |
dadaista | 0:14e5e829dffe | 131 | * |
dadaista | 0:14e5e829dffe | 132 | * @param px The integer base |
dadaista | 0:14e5e829dffe | 133 | * @param py The integer exponent |
dadaista | 0:14e5e829dffe | 134 | * @param r_pn Return by reference; New integer with value of x ** y |
dadaista | 0:14e5e829dffe | 135 | * @return Return status |
dadaista | 0:14e5e829dffe | 136 | */ |
dadaista | 0:14e5e829dffe | 137 | PmReturn_t int_pow(pPmObj_t px, pPmObj_t py, pPmObj_t *r_pn); |
dadaista | 0:14e5e829dffe | 138 | |
dadaista | 0:14e5e829dffe | 139 | #endif /* __INT_H__ */ |