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 sizeof module.
21 # \code sizeof.sizeof(obj) \endcode
23 # Prints the size of the given object. If obj is an integer from 0..31,
24 # the size of the object type represented by that integer will be returned.
36 PmReturn_t retval = PM_RET_OK;
37 int32_t static size[] = {
38 sizeof(PmObj_t), /* None type */
44 sizeof(PmFunc_t), /* Module Obj uses func struct */
47 sizeof(PmClass_t), /* Class instance */
50 sizeof(PmCo_t), /* NOB */
52 sizeof(PmClass_t), /* Exception instance */
54 sizeof(PmCodeImgObj_t),
68 sizeof(PmNativeFrame_t),
71 /* If wrong number of args, raise TypeError */
72 if (NATIVE_GET_NUM_ARGS() != 1)
74 PM_RAISE(retval, PM_RET_EX_TYPE);
78 pobj = NATIVE_GET_LOCAL(0);
79 if (OBJ_GET_TYPE(pobj) == OBJ_TYPE_INT)
81 n = ((pPmInt_t)pobj)->val;
82 if ((n >= 0) && (n < 32))
84 /* Return the size of the type represented by the integer */
85 retval = int_new(size[n], &psize);
89 /* Return the size of an integer object */
90 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
95 /* Return the size of the given non-integer object */
96 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
99 NATIVE_SET_TOS(psize);
137 print "sizeof(", types
[i
], ") = ", sizeof(i
)