00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 """__NATIVE__
00027 #include "pm.h"
00028 """
00029
00030
00031 def sizeof(obj):
00032 """__NATIVE__
00033 pPmObj_t pobj;
00034 pPmObj_t psize;
00035 int32_t n;
00036 PmReturn_t retval = PM_RET_OK;
00037 int32_t static size[] = {
00038 sizeof(PmObj_t), /* None type */
00039 sizeof(PmInt_t),
00040 sizeof(PmFloat_t),
00041 sizeof(PmString_t),
00042 sizeof(PmTuple_t),
00043 sizeof(PmCo_t),
00044 sizeof(PmFunc_t), /* Module Obj uses func struct */
00045 sizeof(PmClass_t),
00046 sizeof(PmFunc_t),
00047 sizeof(PmClass_t), /* Class instance */
00048 0, /* CIM */
00049 0, /* NIM */
00050 sizeof(PmCo_t), /* NOB */
00051 sizeof(PmThread_t),
00052 sizeof(PmClass_t), /* Exception instance */
00053 sizeof(PmBoolean_t),
00054 sizeof(PmCodeImgObj_t),
00055 sizeof(PmList_t),
00056 sizeof(PmDict_t),
00057 0,
00058 0,
00059 0,
00060 0,
00061 0,
00062 0,
00063 sizeof(PmFrame_t),
00064 sizeof(PmBlock_t),
00065 sizeof(Segment_t),
00066 sizeof(Seglist_t),
00067 sizeof(PmSeqIter_t),
00068 sizeof(PmNativeFrame_t),
00069 };
00070
00071 /* If wrong number of args, raise TypeError */
00072 if (NATIVE_GET_NUM_ARGS() != 1)
00073 {
00074 PM_RAISE(retval, PM_RET_EX_TYPE);
00075 return retval;
00076 }
00077
00078 pobj = NATIVE_GET_LOCAL(0);
00079 if (OBJ_GET_TYPE(pobj) == OBJ_TYPE_INT)
00080 {
00081 n = ((pPmInt_t)pobj)->val;
00082 if ((n >= 0) && (n < 32))
00083 {
00084 /* Return the size of the type represented by the integer */
00085 retval = int_new(size[n], &psize);
00086 }
00087 else
00088 {
00089 /* Return the size of an integer object */
00090 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
00091 }
00092 }
00093 else
00094 {
00095 /* Return the size of the given non-integer object */
00096 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
00097 }
00098
00099 NATIVE_SET_TOS(psize);
00100 return retval;
00101 """
00102 pass
00103
00104
00105 def print_sizes():
00106 types = (
00107 'NON',
00108 'INT',
00109 'FLT',
00110 'STR',
00111 'TUP',
00112 'COB',
00113 'MOD',
00114 'CLO',
00115 'FXN',
00116 'CLI',
00117 'CIM',
00118 'NIM',
00119 'NOB',
00120 'THR',
00121 0,
00122 'BOL',
00123 'CIO',
00124 'LST',
00125 'DIC',
00126 0, 0, 0, 0, 0, 0,
00127 'FRM',
00128 'BLK',
00129 'SEG',
00130 'SGL',
00131 'SQI',
00132 'NFM',
00133 0,
00134 )
00135 for i in range(32):
00136 if types[i] != 0:
00137 print "sizeof(", types[i], ") = ", sizeof(i)
00138
00139