python-on-a-chip online compiler

Dependencies:   mbed TSI

Embed: (wiki syntax)

« Back to documentation index

codeobj.h File Reference

codeobj.h File Reference

CodeObj Type. More...

Go to the source code of this file.

Data Structures

struct  PmCo_s
 Code Object. More...
struct  PmNo_s
 Native Code Object. More...

Typedefs

typedef struct PmCo_s PmCo_t
 Code Object.
typedef struct PmNo_s PmNo_t
 Native Code Object.

Functions

PmReturn_t co_loadFromImg (PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pco)
 Creates a CodeObj by loading info from a code image in memory.
void co_rSetCodeImgAddr (pPmCo_t pco, uint8_t const *pimg)
 Recursively sets image address of the CO and all its nested COs in its constant pool.
PmReturn_t no_loadFromImg (PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pno)
 Creates a Native code object by loading a native image.

Detailed Description

CodeObj Type.

CodeObj type header.

Definition in file codeobj.h.


Typedef Documentation

typedef struct PmCo_s PmCo_t

Code Object.

An extended object that holds only the most frequently used parts of the static code image. Other parts can be obtained by inspecting the code image itself.

typedef struct PmNo_s PmNo_t

Native Code Object.

An extended object that holds only the most frequently used parts of the static native image. Other parts can be obtained by inspecting the native image itself.


Function Documentation

PmReturn_t co_loadFromImg ( PmMemSpace_t  memspace,
uint8_t const **  paddr,
pPmObj_t r_pco 
)

Creates a CodeObj by loading info from a code image in memory.

An image is a static representation of a Python object. The process of converting an object to and from an image is also called marshalling. In PyMite, code images are the equivalent of .pyc files. Code images can only contain a select subset of object types (None, Int, Float, String, Slice?, Tuple, and CodeImg). All other types (Lists, Dicts, CodeObjs, Modules, Classes, Functions, ClassInstances) are built at runtime.

All multibyte values are in Little Endian order (least significant byte comes first in the byte stream).

memspace and *paddr determine the start of the code image. Load the code object with values from the code image, including the names and consts tuples. Leave contents of paddr pointing one byte past end of code img.

The code image has the following structure: -type: 8b - OBJ_TYPE_CIM -size: 16b - number of bytes the code image occupies. -argcount: 8b - number of arguments to this code obj. -stacksz: 8b - the maximum arg-stack size needed. -nlocals: 8b - number of local vars in the code obj. -names: Tuple - tuple of string objs. -consts: Tuple - tuple of objs. -code: 8b[] - bytecode array.

Parameters:
memspacememory space containing image
paddrptr to ptr to code img in memspace return by reference: paddr points one byte past end of code img
r_pcoReturn arg. New code object with fields filled in.
Returns:
Return status

Definition at line 26 of file codeobj.c.

void co_rSetCodeImgAddr ( pPmCo_t  pco,
uint8_t const *  pimg 
)

Recursively sets image address of the CO and all its nested COs in its constant pool.

This is done so that an image that was received during an interactive session will persist as long as any of its COs/funcs/objects is still alive.

Parameters:
pcoPointer to root code object whose images are set
pimgPointer to very top of code image (PmodeImgObj)

Definition at line 136 of file codeobj.c.

PmReturn_t no_loadFromImg ( PmMemSpace_t  memspace,
uint8_t const **  paddr,
pPmObj_t r_pno 
)

Creates a Native code object by loading a native image.

An image is a static representation of a Python object. A native image is much smaller than a regular image because only two items of data are needed after the type: the number of args the func expects and the index into the native function table. A reference to the image is not needed since it is just as efficient to store the info in RAM as it is to store a pointer and memspace value.

memspace and *paddr determine the start of the native image. Loads the argcount and the func index from the native object. Leaves contents of paddr pointing one byte past end of code img.

The native image has the following structure: -type: 8b - OBJ_TYPE_CIM -argcount: 8b - number of arguments to this code obj. -code: 16b - index into native function table.

Parameters:
memspacememory space containing image
paddrptr to ptr to code img in memspace (return)
r_pnoReturn by reference, new code object
Returns:
Return status

Definition at line 156 of file codeobj.c.