1 # This file is Copyright 2009, 2010 Dean Hall.
3 # This file is part of the Python-on-a-Chip program.
4 # Python-on-a-Chip is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
7 # Python-on-a-Chip is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
11 # is seen in the file COPYING in this directory.
17 # @brief Provides PyMite's dict module.
22 PmReturn_t retval = PM_RET_OK;
24 /* Raise TypeError if it's not a dict or wrong number of args, */
25 pd = NATIVE_GET_LOCAL(0);
26 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
28 PM_RAISE(retval, PM_RET_EX_TYPE);
32 /* Clear the contents of the dict */
33 retval = dict_clear(pd);
34 PM_RETURN_IF_ERROR(retval);
36 NATIVE_SET_TOS(PM_NONE);
50 PmReturn_t retval = PM_RET_OK;
53 /* Raise TypeError if it's not a dict or wrong number of args, */
54 pd = NATIVE_GET_LOCAL(0);
55 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
57 PM_RAISE(retval, PM_RET_EX_TYPE);
61 /* Create empty list */
62 retval = list_new(&pl);
63 PM_RETURN_IF_ERROR(retval);
65 /* Iterate through the keys seglist */
66 psl = ((pPmDict_t)pd)->d_keys;
67 for (i = 0; i < ((pPmDict_t)pd)->length; i++)
69 /* Get the key and append it to the list */
70 retval = seglist_getItem(psl, i, &pk);
71 PM_RETURN_IF_ERROR(retval);
72 heap_gcPushTempRoot(pl, &objid);
73 retval = list_append(pl, pk);
74 heap_gcPopTempRoot(objid);
75 PM_RETURN_IF_ERROR(retval);
78 /* Return the list of keys to the caller */
100 PmReturn_t retval = PM_RET_OK;
103 /* Raise TypeError if it's not a dict or wrong number of args, */
104 pd = NATIVE_GET_LOCAL(0);
105 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
107 PM_RAISE(retval, PM_RET_EX_TYPE);
111 /* Create empty list */
112 retval = list_new(&pl);
113 PM_RETURN_IF_ERROR(retval);
115 /* Iterate through the values seglist */
116 psl = ((pPmDict_t)pd)->d_vals;
117 for (i = 0; i < ((pPmDict_t)pd)->length; i++)
119 /* Get the value and append it to the list */
120 retval = seglist_getItem(psl, i, &pv);
121 PM_RETURN_IF_ERROR(retval);
122 heap_gcPushTempRoot(pl, &objid);
123 retval = list_append(pl, pv);
124 heap_gcPopTempRoot(objid);
125 PM_RETURN_IF_ERROR(retval);
128 /* Return the list of values to the caller */