sys Namespace Reference

Provides PyMite's system module, sys. More...


Functions

def exit
def getb
def heap
def putb
def runInThread
def time

Variables

int maxint = 0x7FFFFFFF


Detailed Description

Provides PyMite's system module, sys.

USAGE -----

import sys


Function Documentation

def sys::exit (   val  ) 

__NATIVE__
pPmObj_t pval = C_NULL;
PmReturn_t retval;

/* If no arg given, assume return 0 */
if (NATIVE_GET_NUM_ARGS() == 0)
{
    NATIVE_SET_TOS(PM_ZERO);
}

/* If 1 arg given, put it on stack */
else if (NATIVE_GET_NUM_ARGS() == 1)
{
    pval = NATIVE_GET_LOCAL(0);
    NATIVE_SET_TOS(pval);
}

/* If wrong number of args, raise TypeError */
else
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

/* Raise the SystemExit exception */
PM_RAISE(retval, PM_RET_EX_EXIT);
return retval;

def sys::getb (  ) 

__NATIVE__
uint8_t b;
pPmObj_t pb;
PmReturn_t retval;

/* If wrong number of args, raise TypeError */
if (NATIVE_GET_NUM_ARGS() != 0)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

retval = plat_getByte(&b);
PM_RETURN_IF_ERROR(retval);

retval = int_new((int32_t)b, &pb);
NATIVE_SET_TOS(pb);
return retval;

def sys::heap (  ) 

__NATIVE__
PmReturn_t retval;
pPmObj_t pavail;
pPmObj_t pmax;
pPmObj_t ptup;

/* If wrong number of args, raise TypeError */
if (NATIVE_GET_NUM_ARGS() != 0)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

/* Allocate a tuple to store the return values */
retval = tuple_new(2, &ptup);
PM_RETURN_IF_ERROR(retval);

/* Get the maximum heap size */
retval = int_new(PM_HEAP_SIZE, &pmax);
PM_RETURN_IF_ERROR(retval);

/* Allocate an int to hold the amount of heap available */
retval = int_new(heap_getAvail() - sizeof(PmInt_t), &pavail);
PM_RETURN_IF_ERROR(retval);

/* Put the two heap values in the tuple */
((pPmTuple_t)ptup)->val[0] = pavail;
((pPmTuple_t)ptup)->val[1] = pmax;

/* Return the tuple on the stack */
NATIVE_SET_TOS(ptup);

return retval;

def sys::putb (   b  ) 

__NATIVE__
uint8_t b;
pPmObj_t pb;
PmReturn_t retval;

pb = NATIVE_GET_LOCAL(0);

/* If wrong number of args, raise TypeError */
if (NATIVE_GET_NUM_ARGS() != 1)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

/* If arg is not an int, raise TypeError */
if (OBJ_GET_TYPE(pb) != OBJ_TYPE_INT)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

b = ((pPmInt_t)pb)->val & 0xFF;
retval = plat_putByte(b);
NATIVE_SET_TOS(PM_NONE);
return retval;

def sys::runInThread (   f  ) 

__NATIVE__
PmReturn_t retval;
pPmObj_t pf;

/* If wrong number of args, raise TypeError */
if (NATIVE_GET_NUM_ARGS() != 1)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

/* If arg is not a function, raise TypeError */
pf = NATIVE_GET_LOCAL(0);
if (OBJ_GET_TYPE(pf) != OBJ_TYPE_FXN)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

retval = interp_addThread((pPmFunc_t)pf);
NATIVE_SET_TOS(PM_NONE);
return retval;

def sys::time (  ) 

__NATIVE__
uint32_t t;
pPmObj_t pt;
PmReturn_t retval;

/* If wrong number of args, raise TypeError */
if (NATIVE_GET_NUM_ARGS() != 0)
{
    PM_RAISE(retval, PM_RET_EX_TYPE);
    return retval;
}

/* Get the system time (milliseconds since init) */
retval = plat_getMsTicks(&t);
PM_RETURN_IF_ERROR(retval);

/*
 * Raise ValueError if there is an overflow
 * (plat_getMsTicks is unsigned; int is signed)
 */
if ((int32_t)t < 0)
{
    PM_RAISE(retval, PM_RET_EX_VAL);
    return retval;
}

/* Return an int object with the time value */
retval = int_new((int32_t)t, &pt);
NATIVE_SET_TOS(pt);
return retval;


Generated on Wed Feb 24 13:37:03 2010 for Python-on-a-chip by  doxygen 1.5.9