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/tuple.h@0:65f1469d6bfb, 2013-03-02 (annotated)
- Committer:
- va009039
- Date:
- Sat Mar 02 11:54:20 2013 +0000
- Revision:
- 0:65f1469d6bfb
first commit
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 __TUPLE_H__ |
va009039 | 0:65f1469d6bfb | 10 | #define __TUPLE_H__ |
va009039 | 0:65f1469d6bfb | 11 | |
va009039 | 0:65f1469d6bfb | 12 | |
va009039 | 0:65f1469d6bfb | 13 | /** |
va009039 | 0:65f1469d6bfb | 14 | * \file |
va009039 | 0:65f1469d6bfb | 15 | * \brief Tuple Object Type |
va009039 | 0:65f1469d6bfb | 16 | * |
va009039 | 0:65f1469d6bfb | 17 | * Tuple object type header. |
va009039 | 0:65f1469d6bfb | 18 | */ |
va009039 | 0:65f1469d6bfb | 19 | |
va009039 | 0:65f1469d6bfb | 20 | /** |
va009039 | 0:65f1469d6bfb | 21 | * Tuple obj |
va009039 | 0:65f1469d6bfb | 22 | * |
va009039 | 0:65f1469d6bfb | 23 | * Immutable ordered sequence. Contains array of ptrs to objs. |
va009039 | 0:65f1469d6bfb | 24 | */ |
va009039 | 0:65f1469d6bfb | 25 | typedef struct PmTuple_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 | /** |
va009039 | 0:65f1469d6bfb | 31 | * Length of tuple |
va009039 | 0:65f1469d6bfb | 32 | * I don't expect a tuple to ever exceed 255 elements, |
va009039 | 0:65f1469d6bfb | 33 | * but if I set this type to int8_t, a 0-element tuple |
va009039 | 0:65f1469d6bfb | 34 | * is too small to be allocated. |
va009039 | 0:65f1469d6bfb | 35 | */ |
va009039 | 0:65f1469d6bfb | 36 | uint16_t length; |
va009039 | 0:65f1469d6bfb | 37 | |
va009039 | 0:65f1469d6bfb | 38 | /** Array of ptrs to objs */ |
va009039 | 0:65f1469d6bfb | 39 | pPmObj_t val[1]; |
va009039 | 0:65f1469d6bfb | 40 | } PmTuple_t, |
va009039 | 0:65f1469d6bfb | 41 | *pPmTuple_t; |
va009039 | 0:65f1469d6bfb | 42 | |
va009039 | 0:65f1469d6bfb | 43 | |
va009039 | 0:65f1469d6bfb | 44 | #define tuple_copy(src, dest) tuple_replicate((src), 1, (dest)) |
va009039 | 0:65f1469d6bfb | 45 | |
va009039 | 0:65f1469d6bfb | 46 | |
va009039 | 0:65f1469d6bfb | 47 | /** |
va009039 | 0:65f1469d6bfb | 48 | * Creates a Tuple by loading a tuple image from memory. |
va009039 | 0:65f1469d6bfb | 49 | * |
va009039 | 0:65f1469d6bfb | 50 | * Obtain space for tuple from the heap. |
va009039 | 0:65f1469d6bfb | 51 | * Load all objs within the tuple img. |
va009039 | 0:65f1469d6bfb | 52 | * Leave contents of paddr pointing one byte past end of |
va009039 | 0:65f1469d6bfb | 53 | * last obj in tuple. |
va009039 | 0:65f1469d6bfb | 54 | * |
va009039 | 0:65f1469d6bfb | 55 | * The tuple image has the following structure: |
va009039 | 0:65f1469d6bfb | 56 | * -type: S8 - OBJ_TYPE_TUPLE |
va009039 | 0:65f1469d6bfb | 57 | * -length U8 - N number of objects in the tuple. |
va009039 | 0:65f1469d6bfb | 58 | * N objects follow in the stream. |
va009039 | 0:65f1469d6bfb | 59 | * |
va009039 | 0:65f1469d6bfb | 60 | * @param memspace Memory space. |
va009039 | 0:65f1469d6bfb | 61 | * @param paddr Ptr to ptr to tuple in memspace |
va009039 | 0:65f1469d6bfb | 62 | * @param r_ptuple Return by reference; new filled tuple |
va009039 | 0:65f1469d6bfb | 63 | * @return Return status |
va009039 | 0:65f1469d6bfb | 64 | */ |
va009039 | 0:65f1469d6bfb | 65 | PmReturn_t tuple_loadFromImg(PmMemSpace_t memspace, |
va009039 | 0:65f1469d6bfb | 66 | uint8_t const **paddr, pPmObj_t *r_ptuple); |
va009039 | 0:65f1469d6bfb | 67 | |
va009039 | 0:65f1469d6bfb | 68 | /** |
va009039 | 0:65f1469d6bfb | 69 | * Allocates space for a new Tuple. Returns a pointer to the tuple. |
va009039 | 0:65f1469d6bfb | 70 | * |
va009039 | 0:65f1469d6bfb | 71 | * @param n the number of elements the tuple will contain |
va009039 | 0:65f1469d6bfb | 72 | * @param r_ptuple Return by ref, ptr to new tuple |
va009039 | 0:65f1469d6bfb | 73 | * @return Return status |
va009039 | 0:65f1469d6bfb | 74 | */ |
va009039 | 0:65f1469d6bfb | 75 | PmReturn_t tuple_new(uint16_t n, pPmObj_t *r_ptuple); |
va009039 | 0:65f1469d6bfb | 76 | |
va009039 | 0:65f1469d6bfb | 77 | /** |
va009039 | 0:65f1469d6bfb | 78 | * Replicates a tuple, n number of times to create a new tuple |
va009039 | 0:65f1469d6bfb | 79 | * |
va009039 | 0:65f1469d6bfb | 80 | * Copies the pointers (not the objects). |
va009039 | 0:65f1469d6bfb | 81 | * |
va009039 | 0:65f1469d6bfb | 82 | * @param ptup Ptr to source tuple. |
va009039 | 0:65f1469d6bfb | 83 | * @param n Number of times to replicate the tuple. |
va009039 | 0:65f1469d6bfb | 84 | * @param r_ptuple Return arg; Ptr to new tuple. |
va009039 | 0:65f1469d6bfb | 85 | * @return Return status |
va009039 | 0:65f1469d6bfb | 86 | */ |
va009039 | 0:65f1469d6bfb | 87 | PmReturn_t tuple_replicate(pPmObj_t ptup, int16_t n, pPmObj_t *r_ptuple); |
va009039 | 0:65f1469d6bfb | 88 | |
va009039 | 0:65f1469d6bfb | 89 | /** |
va009039 | 0:65f1469d6bfb | 90 | * Gets the object in the tuple at the index. |
va009039 | 0:65f1469d6bfb | 91 | * |
va009039 | 0:65f1469d6bfb | 92 | * @param ptup Ptr to tuple obj |
va009039 | 0:65f1469d6bfb | 93 | * @param index Index into tuple |
va009039 | 0:65f1469d6bfb | 94 | * @param r_pobj Return by reference; ptr to item |
va009039 | 0:65f1469d6bfb | 95 | * @return Return status |
va009039 | 0:65f1469d6bfb | 96 | */ |
va009039 | 0:65f1469d6bfb | 97 | PmReturn_t tuple_getItem(pPmObj_t ptup, int16_t index, pPmObj_t *r_pobj); |
va009039 | 0:65f1469d6bfb | 98 | |
va009039 | 0:65f1469d6bfb | 99 | #ifdef HAVE_PRINT |
va009039 | 0:65f1469d6bfb | 100 | /** |
va009039 | 0:65f1469d6bfb | 101 | * Prints out a tuple. Uses obj_print() to print elements. |
va009039 | 0:65f1469d6bfb | 102 | * |
va009039 | 0:65f1469d6bfb | 103 | * @param pobj Object to print. |
va009039 | 0:65f1469d6bfb | 104 | * @return Return status |
va009039 | 0:65f1469d6bfb | 105 | */ |
va009039 | 0:65f1469d6bfb | 106 | PmReturn_t tuple_print(pPmObj_t pobj); |
va009039 | 0:65f1469d6bfb | 107 | #endif /* HAVE_PRINT */ |
va009039 | 0:65f1469d6bfb | 108 | |
va009039 | 0:65f1469d6bfb | 109 | #endif /* __TUPLE_H__ */ |