obj.h File Reference

Object Type. More...

Go to the source code of this file.

Classes

struct  PmObj_s
struct  PmBoolean_s

Defines

#define OD_MARK_SHIFT   14
#define OD_FREE_SHIFT   15
#define OD_MARK_BIT   (uint16_t)(1 << OD_MARK_SHIFT)
#define OD_FREE_BIT   (uint16_t)(1 << OD_FREE_SHIFT)
#define OD_SIZE_MASK   (uint16_t)(0x01FF)
#define OD_TYPE_MASK   (uint16_t)(0x3E00)
#define OD_TYPE_SHIFT   9
#define HD_SIZE_MASK   (uint16_t)(0x3FFF)
#define OBJ_GET_FREE(pobj)   ((((pPmObj_t)pobj)->od >> OD_FREE_SHIFT) & (uint8_t)1)
#define OBJ_SET_FREE(pobj, free)
#define OBJ_GET_SIZE(pobj)
#define OBJ_SET_SIZE(pobj, size)
#define OBJ_GET_TYPE(pobj)   (((((pPmObj_t)pobj)->od) & OD_TYPE_MASK) >> OD_TYPE_SHIFT)
#define OBJ_SET_TYPE(pobj, type)

Typedefs

typedef enum PmType_e PmType_t
typedef enum PmType_epPmType_t
typedef uint16_t PmObjDesc_t
typedef uint16_tpPmObjDesc_t
typedef struct PmObj_s PmObj_t
typedef struct PmObj_spPmObj_t
typedef struct PmBoolean_s PmBoolean_t
typedef struct PmBoolean_spPmBoolean_t

Enumerations

enum  PmType_e {
  OBJ_TYPE_HASHABLE_MIN = 0x00, OBJ_TYPE_NON = 0x00, OBJ_TYPE_INT = 0x01, OBJ_TYPE_FLT = 0x02,
  OBJ_TYPE_STR = 0x03, OBJ_TYPE_TUP = 0x04, OBJ_TYPE_COB = 0x05, OBJ_TYPE_MOD = 0x06,
  OBJ_TYPE_CLO = 0x07, OBJ_TYPE_FXN = 0x08, OBJ_TYPE_CLI = 0x09, OBJ_TYPE_CIM = 0x0A,
  OBJ_TYPE_NIM = 0x0B, OBJ_TYPE_NOB = 0x0C, OBJ_TYPE_THR = 0x0D, OBJ_TYPE_BOOL = 0x0F,
  OBJ_TYPE_CIO = 0x10, OBJ_TYPE_MTH = 0x11, OBJ_TYPE_HASHABLE_MAX = 0x11, OBJ_TYPE_LST = 0x12,
  OBJ_TYPE_DIC = 0x13, OBJ_TYPE_ACCESSIBLE_MAX = 0x18, OBJ_TYPE_FRM = 0x19, OBJ_TYPE_BLK = 0x1A,
  OBJ_TYPE_SEG = 0x1B, OBJ_TYPE_SGL = 0x1C, OBJ_TYPE_SQI = 0x1D, OBJ_TYPE_NFM = 0x1E
}

Functions

PmReturn_t obj_loadFromImg (PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pobj)
PmReturn_t obj_loadFromImgObj (pPmObj_t pimg, pPmObj_t *r_pobj)
int8_t obj_isFalse (pPmObj_t pobj)
PmReturn_t obj_isIn (pPmObj_t pobj, pPmObj_t pitem)
int8_t obj_compare (pPmObj_t pobj1, pPmObj_t pobj2)
PmReturn_t obj_print (pPmObj_t pobj, uint8_t is_expr_repr, uint8_t is_nested)


Detailed Description

Object Type.

Object type header.

Definition in file obj.h.


Define Documentation

#define HD_SIZE_MASK   (uint16_t)(0x3FFF)

Heap descriptor size mask

Definition at line 38 of file obj.h.

#define OBJ_GET_FREE ( pobj   )     ((((pPmObj_t)pobj)->od >> OD_FREE_SHIFT) & (uint8_t)1)

Gets the free bit of the given object to the given value. If the object is marked free, it is not being used by the VM.

Definition at line 45 of file obj.h.

#define OBJ_GET_SIZE ( pobj   ) 

Value:

((((pPmObj_t)pobj)->od & OD_FREE_BIT) \
     ? ((((pPmObj_t)pobj)->od & HD_SIZE_MASK) << 2) \
     : ((((pPmObj_t)pobj)->od & OD_SIZE_MASK) << 2))
Gets the size of the chunk in bytes. Tests whether the object is free as that determines whether the chunk is using an object descriptor or a heap descriptor. Heap descriptors have a larger size field and use a different bit mask than object descriptors.

Definition at line 73 of file obj.h.

#define OBJ_GET_TYPE ( pobj   )     (((((pPmObj_t)pobj)->od) & OD_TYPE_MASK) >> OD_TYPE_SHIFT)

Gets the type of the object This MUST NOT be called on objects that are free.

Definition at line 104 of file obj.h.

#define OBJ_SET_FREE ( pobj,
free   ) 

Value:

do \
    { \
        ((pPmObj_t)pobj)->od = ((uint8_t)free) \
                               ? ((pPmObj_t)pobj)->od | OD_FREE_BIT \
                               : ((pPmObj_t)pobj)->od & ~OD_FREE_BIT;\
    } \
    while (0)
Sets the free bit of the given object to the given value. Setting the free bit means that the object will use the heap descriptor structure instead of the object descriptor structure.

Definition at line 53 of file obj.h.

#define OBJ_SET_SIZE ( pobj,
size   ) 

Value:

do \
    { \
        if (((pPmObj_t)pobj)->od & OD_FREE_BIT) \
        { \
            ((pPmObj_t)pobj)->od &= ~HD_SIZE_MASK; \
            ((pPmObj_t)pobj)->od |= (((size) >> 2) & HD_SIZE_MASK); \
        } \
        else \
        { \
            ((pPmObj_t)pobj)->od &= ~OD_SIZE_MASK; \
            ((pPmObj_t)pobj)->od |= (((size) >> 2) & OD_SIZE_MASK); \
        } \
    } \
    while (0)
Sets the size of the chunk in bytes. Tests whether the object is free as that determines whether the chunk is using an object descriptor or a heap descriptor. Heap descriptors have a larger size field and use a different bit mask than object descriptors.

Definition at line 84 of file obj.h.

#define OBJ_SET_TYPE ( pobj,
type   ) 

Value:

do \
    { \
        ((pPmObj_t)pobj)->od &= ~OD_TYPE_MASK; \
        ((pPmObj_t)pobj)->od |= (((type) << OD_TYPE_SHIFT) & OD_TYPE_MASK); \
    } \
    while (0)
Sets the type of the object This MUST NOT be called on objects that are free.

Definition at line 111 of file obj.h.

#define OD_MARK_SHIFT   14

Object descriptor field constants

Definition at line 29 of file obj.h.


Typedef Documentation

typedef struct PmBoolean_s PmBoolean_t

Boolean object

typedef struct PmObj_s PmObj_t

Object

The abstract empty object type for PyMite.

Object Descriptor

All active PyMite "objects" must have this at the top of their struct. (CodeObj, Frame, Dict, List, Tuple, etc.).

The following is a diagram of the object descriptor:

 *              MSb           LSb
 *               7 6 5 4 3 2 1 0
 *     pchunk-> +-+-+-+-+-+-+-+-+     S := Size of the chunk (2 LSbs dropped)
 *              |     S[9:2]    |     F := Free bit
 *              +-+-+---------+-+     M := GC Mark bit
 *              |F|M|    T    |S|     T := Object type (PyMite specific)
 *              +-+-+---------+-+
 *              | object data   |
 *              ...           ...
 *              | end data      |     Theoretical min size == 2
 *              +---------------+     Effective min size == 8
 *                                    (due to pmHeapDesc_t)
 * 
Macros are used to get and set field values. Using macros eliminates declaring bit fields which fails on some compilers.

Definition at line 251 of file obj.h.

typedef enum PmType_e PmType_t

Object type enum

These values go in the od_type fields of the obj descriptor. Be sure these values correspond to those in the image creator tool. The hashable types are grouped together for convenience.

WARNING: od_type must be at most 5 bits! (must be < 0x20)


Enumeration Type Documentation

enum PmType_e

Object type enum

These values go in the od_type fields of the obj descriptor. Be sure these values correspond to those in the image creator tool. The hashable types are grouped together for convenience.

WARNING: od_type must be at most 5 bits! (must be < 0x20)

Enumerator:
OBJ_TYPE_NON  None
OBJ_TYPE_INT  Signed integer
OBJ_TYPE_FLT  Floating point 32b
OBJ_TYPE_STR  String
OBJ_TYPE_TUP  Tuple (immutable sequence)
OBJ_TYPE_COB  Code obj
OBJ_TYPE_MOD  Module obj
OBJ_TYPE_CLO  Class obj
OBJ_TYPE_FXN  Function obj (callable)
OBJ_TYPE_CLI  Class instance
OBJ_TYPE_CIM  Code image in static memory
OBJ_TYPE_NIM  Native function image
OBJ_TYPE_NOB  Native function object
OBJ_TYPE_THR  Thread
OBJ_TYPE_BOOL  Boolean object
OBJ_TYPE_CIO  Code image object
OBJ_TYPE_MTH  Method object
OBJ_TYPE_LST  List (mutable sequence)
OBJ_TYPE_DIC  Dictionary (hash table)
OBJ_TYPE_FRM  Frame type
OBJ_TYPE_BLK  Block type (for,while,try,etc)
OBJ_TYPE_SEG  Segment (within a seglist)
OBJ_TYPE_SGL  Seglist
OBJ_TYPE_SQI  Sequence iterator
OBJ_TYPE_NFM  Native frame (there is only one)

Definition at line 130 of file obj.h.


Function Documentation

int8_t obj_compare ( pPmObj_t  pobj1,
pPmObj_t  pobj2 
)

Compares two objects for equality.

Parameters:
pobj1 Ptr to first object.
pobj2 Ptr to second object.
Returns:
C_SAME if the items are equivalent, C_DIFFER otherwise.

Definition at line 254 of file obj.c.

int8_t obj_isFalse ( pPmObj_t  pobj  ) 

Finds the boolean value of the given object.

Parameters:
pobj Ptr to object to test.
Returns:
Nonzero value if object is False.

Definition at line 111 of file obj.c.

PmReturn_t obj_isIn ( pPmObj_t  pobj,
pPmObj_t  pitem 
)

Returns the boolean true if the item is in the object

Parameters:
pobj Ptr to container object
pitem Ptr to item

Definition at line 164 of file obj.c.

PmReturn_t obj_loadFromImg ( PmMemSpace_t  memspace,
uint8_t const **  paddr,
pPmObj_t r_pobj 
)

Loads an object from an image in memory. Return pointer to object. Leave add pointing one byte past end of obj.

The following lists the simple object types and their image structures: -None: -type: int8_t - OBJ_TYPE_NON

-Int: -type: int8_t - OBJ_TYPE_INT -value: int32_t - signed integer value

-Float: -type: int8_t - OBJ_TYPE_FLOAT -value: float32_t - 32-bit floating point value

-Slice (is this allowed in img?): -type: int8_t - OBJ_TYPE_SLICE -index1: int16_t - first index. -index2: int16_t - second index.

Parameters:
memspace memory space/type
paddr ptr to ptr to obj return by reference: paddr pts to first byte after obj
r_pobj Return arg, the loaded object.
Returns:
Return status

Definition at line 32 of file obj.c.

PmReturn_t obj_loadFromImgObj ( pPmObj_t  pimg,
pPmObj_t r_pobj 
)

Loads a code object from a code image object

Parameters:
pimg Ptr to a code image object
r_pobj Return arg, the loaded object
Returns:
Returns status

Definition at line 90 of file obj.c.

PmReturn_t obj_print ( pPmObj_t  pobj,
uint8_t  is_expr_repr,
uint8_t  is_nested 
)

Print an object, thereby using objects helpers.

Parameters:
pobj Ptr to object for printing.
is_expr_repr Influences the way None and strings are printed. If 0, None is printed, strings are printed. If 1, None is not printed and strings are printed surrounded with single quotes and unprintable characters are escaped.
is_nested Influences the way None and strings are printed. If 1, None will be printed and strings will be surrounded with single quotes and escaped. This argument overrides the is_expr_repr argument.
Returns:
Return status


Generated on Mon Oct 18 07:40:49 2010 for Python-on-a-chip by  doxygen 1.5.9