dict.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 def clear(d):
00020 """__NATIVE__
00021 pPmObj_t pd;
00022 PmReturn_t retval = PM_RET_OK;
00023
00024 /* Raise TypeError if it's not a dict or wrong number of args, */
00025 pd = NATIVE_GET_LOCAL(0);
00026 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
00027 {
00028 PM_RAISE(retval, PM_RET_EX_TYPE);
00029 return retval;
00030 }
00031
00032 /* Clear the contents of the dict */
00033 retval = dict_clear(pd);
00034 PM_RETURN_IF_ERROR(retval);
00035
00036 NATIVE_SET_TOS(PM_NONE);
00037
00038 return retval;
00039 """
00040 pass
00041
00042
00043 def keys(d):
00044 """__NATIVE__
00045 pPmObj_t pd;
00046 pPmObj_t pl;
00047 pPmObj_t pk;
00048 pSeglist_t psl;
00049 uint16_t i;
00050 PmReturn_t retval = PM_RET_OK;
00051 uint8_t objid;
00052
00053 /* Raise TypeError if it's not a dict or wrong number of args, */
00054 pd = NATIVE_GET_LOCAL(0);
00055 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
00056 {
00057 PM_RAISE(retval, PM_RET_EX_TYPE);
00058 return retval;
00059 }
00060
00061 /* Create empty list */
00062 retval = list_new(&pl);
00063 PM_RETURN_IF_ERROR(retval);
00064
00065 /* Iterate through the keys seglist */
00066 psl = ((pPmDict_t)pd)->d_keys;
00067 for (i = 0; i < ((pPmDict_t)pd)->length; i++)
00068 {
00069 /* Get the key and append it to the list */
00070 retval = seglist_getItem(psl, i, &pk);
00071 PM_RETURN_IF_ERROR(retval);
00072 heap_gcPushTempRoot(pl, &objid);
00073 retval = list_append(pl, pk);
00074 heap_gcPopTempRoot(objid);
00075 PM_RETURN_IF_ERROR(retval);
00076 }
00077
00078 /* Return the list of keys to the caller */
00079 NATIVE_SET_TOS(pl);
00080
00081 return retval;
00082 """
00083 pass
00084
00085
00086 def has_key(d, k):
00087 if k in keys(d):
00088 return 1
00089 else:
00090 return 0
00091
00092
00093 def values(d):
00094 """__NATIVE__
00095 pPmObj_t pd;
00096 pPmObj_t pl;
00097 pPmObj_t pv;
00098 pSeglist_t psl;
00099 uint16_t i;
00100 PmReturn_t retval = PM_RET_OK;
00101 uint8_t objid;
00102
00103 /* Raise TypeError if it's not a dict or wrong number of args, */
00104 pd = NATIVE_GET_LOCAL(0);
00105 if ((OBJ_GET_TYPE(pd) != OBJ_TYPE_DIC) || (NATIVE_GET_NUM_ARGS() != 1))
00106 {
00107 PM_RAISE(retval, PM_RET_EX_TYPE);
00108 return retval;
00109 }
00110
00111 /* Create empty list */
00112 retval = list_new(&pl);
00113 PM_RETURN_IF_ERROR(retval);
00114
00115 /* Iterate through the values seglist */
00116 psl = ((pPmDict_t)pd)->d_vals;
00117 for (i = 0; i < ((pPmDict_t)pd)->length; i++)
00118 {
00119 /* Get the value and append it to the list */
00120 retval = seglist_getItem(psl, i, &pv);
00121 PM_RETURN_IF_ERROR(retval);
00122 heap_gcPushTempRoot(pl, &objid);
00123 retval = list_append(pl, pv);
00124 heap_gcPopTempRoot(objid);
00125 PM_RETURN_IF_ERROR(retval);
00126 }
00127
00128 /* Return the list of values to the caller */
00129 NATIVE_SET_TOS(pl);
00130
00131 return retval;
00132 """
00133 pass
00134
00135
00136