LP-500 HoTT Telemetry added device definitions
[librepilot.git] / flight / libraries / PyMite / lib / sizeof.py
blobffff3c35ca7f985387c6c5e4ab265984d056b8f4
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.
6 #
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.
13 ## @file
14 # @copybrief sizeof
16 ## @package sizeof
17 # @brief Provides PyMite's sizeof module.
19 # <b>USAGE</b>
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.
26 """__NATIVE__
27 #include "pm.h"
28 """
31 def sizeof(obj):
32 """__NATIVE__
33 pPmObj_t pobj;
34 pPmObj_t psize;
35 int32_t n;
36 PmReturn_t retval = PM_RET_OK;
37 int32_t static size[] = {
38 sizeof(PmObj_t), /* None type */
39 sizeof(PmInt_t),
40 sizeof(PmFloat_t),
41 sizeof(PmString_t),
42 sizeof(PmTuple_t),
43 sizeof(PmCo_t),
44 sizeof(PmFunc_t), /* Module Obj uses func struct */
45 sizeof(PmClass_t),
46 sizeof(PmFunc_t),
47 sizeof(PmClass_t), /* Class instance */
48 0, /* CIM */
49 0, /* NIM */
50 sizeof(PmCo_t), /* NOB */
51 sizeof(PmThread_t),
52 sizeof(PmClass_t), /* Exception instance */
53 sizeof(PmBoolean_t),
54 sizeof(PmCodeImgObj_t),
55 sizeof(PmList_t),
56 sizeof(PmDict_t),
63 sizeof(PmFrame_t),
64 sizeof(PmBlock_t),
65 sizeof(Segment_t),
66 sizeof(Seglist_t),
67 sizeof(PmSeqIter_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);
75 return retval;
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);
87 else
89 /* Return the size of an integer object */
90 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
93 else
95 /* Return the size of the given non-integer object */
96 retval = int_new(OBJ_GET_SIZE(pobj), &psize);
99 NATIVE_SET_TOS(psize);
100 return retval;
102 pass
105 def print_sizes():
106 types = (
107 'NON',
108 'INT',
109 'FLT',
110 'STR',
111 'TUP',
112 'COB',
113 'MOD',
114 'CLO',
115 'FXN',
116 'CLI',
117 'CIM',
118 'NIM',
119 'NOB',
120 'THR',
122 'BOL',
123 'CIO',
124 'LST',
125 'DIC',
126 0, 0, 0, 0, 0, 0,
127 'FRM',
128 'BLK',
129 'SEG',
130 'SGL',
131 'SQI',
132 'NFM',
135 for i in range(32):
136 if types[i] != 0:
137 print "sizeof(", types[i], ") = ", sizeof(i)
139 #:mode=c: