PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/testing/bene/pymite-05/src/vm/list.h

http://octopususb.googlecode.com/
C Header | 175 lines | 22 code | 20 blank | 133 comment | 0 complexity | fb7151557915ed9b4dbb54b4f8654e37 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.1, LGPL-2.0, CC-BY-SA-3.0
  1. /*
  2. * PyMite - A flyweight Python interpreter for 8-bit microcontrollers and more.
  3. * Copyright 2002 Dean Hall
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __LIST_H__
  20. #define __LIST_H__
  21. /**
  22. * List Object Type
  23. *
  24. * List object type header.
  25. *
  26. * Log:
  27. *
  28. * 2007/01/09 #75: Printing support (P.Adelt)
  29. * 2007/01/09 #75: implemented list_remove() and list_index() (P.Adelt)
  30. * 2003/02/11 Refactored to pobj/return status model.
  31. * 2002/04/22 First.
  32. */
  33. /***************************************************************
  34. * Types
  35. **************************************************************/
  36. /**
  37. * List obj
  38. *
  39. * Mutable ordered sequence of objects. Contains ptr to linked list of nodes.
  40. */
  41. typedef struct PmList_s
  42. {
  43. /** Object descriptor */
  44. PmObjDesc_t od;
  45. /** List length; number of objs linked */
  46. int16_t length;
  47. /** Ptr to linked list of nodes */
  48. pSeglist_t val;
  49. } PmList_t,
  50. *pPmList_t;
  51. /***************************************************************
  52. * Prototypes
  53. **************************************************************/
  54. /**
  55. * Allocates a new List object.
  56. *
  57. * If there is not enough memory to allocate the List,
  58. * the return status will indicate an OutOfMemoryError
  59. * that must be passed up to the interpreter.
  60. * Otherwise, a ptr to the list is returned by reference
  61. * and the return status is OK.
  62. *
  63. * @param r_pobj Return; addr of ptr to obj
  64. * @return Return status
  65. */
  66. PmReturn_t list_new(pPmObj_t *r_pobj);
  67. /**
  68. * Gets the object in the list at the index.
  69. *
  70. * @param pobj Ptr to list obj
  71. * @param index Index into list
  72. * @param r_pobj Return; ptr to return obj
  73. * @return Return status
  74. */
  75. PmReturn_t list_getItem(pPmObj_t plist, int16_t index, pPmObj_t *r_pobj);
  76. /**
  77. * Sets the item in the list at the index.
  78. *
  79. * @param pobj1 Ptr to list
  80. * @param index Index int
  81. * @param pobj2 Ptr to obj
  82. * @return Return status
  83. */
  84. PmReturn_t list_setItem(pPmObj_t plist, int16_t index, pPmObj_t pobj);
  85. /**
  86. * Makes a copy of the given list.
  87. *
  88. * Allocate the necessary memory for root and nodes.
  89. * Duplicate ptrs to objs.
  90. *
  91. * @param pobj Ptr to source list
  92. * @param r_pobj Return; Addr of ptr to return obj
  93. * @return Return status
  94. */
  95. PmReturn_t list_copy(pPmObj_t pobj, pPmObj_t *r_pobj);
  96. /**
  97. * Appends the given obj to the end of the given list.
  98. *
  99. * Allocate the memory for the node.
  100. * Do not copy obj, just reuse ptr.
  101. *
  102. * @param plist Ptr to list
  103. * @param pobj Ptr to item to append
  104. * @return Return status
  105. */
  106. PmReturn_t list_append(pPmObj_t plist, pPmObj_t pobj);
  107. /**
  108. * Creates a new list with the contents of psrclist
  109. * copied pint number of times.
  110. * This implements the python code "[0,...] * N"
  111. * where the list can be any list and N is an integer.
  112. *
  113. * @param psrclist The source list to replicate
  114. * @param n The integer number of times to replicate it
  115. * @param r_pnewlist Return; new list with its contents set.
  116. * @return Return status
  117. */
  118. PmReturn_t list_replicate(pPmObj_t psrclist, int16_t n, pPmObj_t *r_pnewlist);
  119. /**
  120. * Inserts the object into the list at the desired index.
  121. *
  122. * @param plist Ptr to list obj
  123. * @param pobj Ptr to obj to insert
  124. * @param index Index of where to insert obj
  125. * @return Return status
  126. */
  127. PmReturn_t list_insert(pPmObj_t plist, int16_t index, pPmObj_t pobj);
  128. /**
  129. * Removes a given object from the list.
  130. *
  131. * @param plist Ptr to list obj
  132. * @param item Ptr to object to be removed
  133. * @return Return status
  134. */
  135. PmReturn_t list_remove(pPmObj_t plist, pPmObj_t item);
  136. /**
  137. * Finds the first index of the item that matches pitem.
  138. * Returns an ValueError Exception if the item is not found.
  139. *
  140. * @param plist Ptr to list obj
  141. * @param item Ptr to object to be removed
  142. * @param r_index Addr of the variable for index
  143. * @return Return status
  144. */
  145. PmReturn_t list_index(pPmObj_t plist, pPmObj_t pitem, uint16_t *r_index);
  146. #ifdef HAVE_PRINT
  147. /**
  148. * Prints out a list. Uses obj_print() to print elements.
  149. *
  150. * @param pobj Object to print.
  151. * @return Return status
  152. */
  153. PmReturn_t list_print(pPmObj_t pobj);
  154. #endif /* HAVE_PRINT */
  155. #endif /* __LIST_H__ */