interp.h File Reference

VM Interpreter. More...

#include "thread.h"

Go to the source code of this file.

Defines

#define INTERP_LOOP_FOREVER   0
#define INTERP_RETURN_ON_NO_THREADS   1
#define FP   (gVmGlobal.pthread->pframe)
#define MP   (gVmGlobal.pmod)
#define IP   (FP->fo_ip)
#define SP   (FP->fo_sp)
#define MS   (FP->fo_memspace)
#define TOS   (*(SP - 1))
#define TOS1   (*(SP - 2))
#define TOS2   (*(SP - 3))
#define TOS3   (*(SP - 4))
#define STACK(n)   (*(SP - ((n) + 1)))
#define PM_POP()   (*(--SP))
#define PM_PUSH(pobj)   (*(SP++) = (pobj))
#define GET_ARG()   mem_getWord(MS, &IP)
#define NATIVE_SET_TOS(pobj)
#define NATIVE_GET_LOCAL(n)   (gVmGlobal.nativeframe.nf_locals[n])
#define NATIVE_GET_PFRAME()   (*ppframe)
#define NATIVE_GET_NUM_ARGS()   (gVmGlobal.nativeframe.nf_numlocals)

Typedefs

typedef enum PmCompare_e PmCompare_t
typedef enum PmCompare_epPmCompare_t
typedef enum PmBcode_e PmBcode_t
typedef enum PmBcode_epPmBcode_t

Enumerations

enum  PmCompare_e {
  COMP_LT = 0, COMP_LE, COMP_EQ, COMP_NE,
  COMP_GT, COMP_GE, COMP_IN, COMP_NOT_IN,
  COMP_IS, COMP_IS_NOT, COMP_EXN_MATCH
}
enum  PmBcode_e {
  STOP_CODE = 0, POP_TOP, ROT_TWO, ROT_THREE,
  DUP_TOP, ROT_FOUR, UNUSED_06, UNUSED_07,
  UNUSED_08, NOP, UNARY_POSITIVE, UNARY_NEGATIVE,
  UNARY_NOT, UNARY_CONVERT, UNUSED_0E, UNARY_INVERT,
  UNUSED_10, UNUSED_11, LIST_APPEND, BINARY_POWER,
  BINARY_MULTIPLY, BINARY_DIVIDE, BINARY_MODULO, BINARY_ADD,
  BINARY_SUBTRACT, BINARY_SUBSCR, BINARY_FLOOR_DIVIDE, BINARY_TRUE_DIVIDE,
  INPLACE_FLOOR_DIVIDE, INPLACE_TRUE_DIVIDE, SLICE_0, SLICE_1,
  SLICE_2, SLICE_3, UNUSED_22, UNUSED_23,
  UNUSED_24, UNUSED_25, UNUSED_26, UNUSED_27,
  STORE_SLICE_0, STORE_SLICE_1, STORE_SLICE_2, STORE_SLICE_3,
  UNUSED_2C, UNUSED_2D, UNUSED_2E, UNUSED_2F,
  UNUSED_30, UNUSED_31, DELETE_SLICE_0, DELETE_SLICE_1,
  DELETE_SLICE_2, DELETE_SLICE_3, STORE_MAP, INPLACE_ADD,
  INPLACE_SUBTRACT, INPLACE_MULTIPLY, INPLACE_DIVIDE, INPLACE_MODULO,
  STORE_SUBSCR, DELETE_SUBSCR, BINARY_LSHIFT, BINARY_RSHIFT,
  BINARY_AND, BINARY_XOR, BINARY_OR, INPLACE_POWER,
  GET_ITER, UNUSED_45, PRINT_EXPR, PRINT_ITEM,
  PRINT_NEWLINE, PRINT_ITEM_TO, PRINT_NEWLINE_TO, INPLACE_LSHIFT,
  INPLACE_RSHIFT, INPLACE_AND, INPLACE_XOR, INPLACE_OR,
  BREAK_LOOP, WITH_CLEANUP, LOAD_LOCALS, RETURN_VALUE,
  IMPORT_STAR, EXEC_STMT, YIELD_VALUE, POP_BLOCK,
  END_FINALLY, BUILD_CLASS, HAVE_ARGUMENT = 90, STORE_NAME = 90,
  DELETE_NAME, UNPACK_SEQUENCE, FOR_ITER, UNUSED_5E,
  STORE_ATTR, DELETE_ATTR, STORE_GLOBAL, DELETE_GLOBAL,
  DUP_TOPX, LOAD_CONST, LOAD_NAME, BUILD_TUPLE,
  BUILD_LIST, BUILD_MAP, LOAD_ATTR, COMPARE_OP,
  IMPORT_NAME, IMPORT_FROM, UNUSED_6D, JUMP_FORWARD,
  JUMP_IF_FALSE, JUMP_IF_TRUE, JUMP_ABSOLUTE, UNUSED_72,
  UNUSED_73, LOAD_GLOBAL, UNUSED_75, UNUSED_76,
  CONTINUE_LOOP, SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY,
  UNUSED_7B, LOAD_FAST, STORE_FAST, DELETE_FAST,
  UNUSED_79, UNUSED_80, UNUSED_81, RAISE_VARARGS,
  CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE, MAKE_CLOSURE,
  LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF, UNUSED_8A,
  UNUSED_8B, CALL_FUNCTION_VAR, CALL_FUNCTION_KW, CALL_FUNCTION_VAR_KW,
  EXTENDED_ARG, UNUSED_90, UNUSED_91, UNUSED_92,
  UNUSED_93, UNUSED_94, UNUSED_95, UNUSED_96,
  UNUSED_97, UNUSED_98, UNUSED_99, UNUSED_9A,
  UNUSED_9B, UNUSED_9C, UNUSED_9D, UNUSED_9E,
  UNUSED_9F, UNUSED_A0, UNUSED_A1, UNUSED_A2,
  UNUSED_A3, UNUSED_A4, UNUSED_A5, UNUSED_A6,
  UNUSED_A7, UNUSED_A8, UNUSED_A9, UNUSED_AA,
  UNUSED_AB, UNUSED_AC, UNUSED_AD, UNUSED_AE,
  UNUSED_AF, UNUSED_B0, UNUSED_B1, UNUSED_B2,
  UNUSED_B3, UNUSED_B4, UNUSED_B5, UNUSED_B6,
  UNUSED_B7, UNUSED_B8, UNUSED_B9, UNUSED_BA,
  UNUSED_BB, UNUSED_BC, UNUSED_BD, UNUSED_BE,
  UNUSED_BF, UNUSED_C0, UNUSED_C1, UNUSED_C2,
  UNUSED_C3, UNUSED_C4, UNUSED_C5, UNUSED_C6,
  UNUSED_C7, UNUSED_C8, UNUSED_C9, UNUSED_CA,
  UNUSED_CB, UNUSED_CC, UNUSED_CD, UNUSED_CE,
  UNUSED_CF, UNUSED_D0, UNUSED_D1, UNUSED_D2,
  UNUSED_D3, UNUSED_D4, UNUSED_D5, UNUSED_D6,
  UNUSED_D7, UNUSED_D8, UNUSED_D9, UNUSED_DA,
  UNUSED_DB, UNUSED_DC, UNUSED_DD, UNUSED_DE,
  UNUSED_DF, UNUSED_E0, UNUSED_E1, UNUSED_E2,
  UNUSED_E3, UNUSED_E4, UNUSED_E5, UNUSED_E6,
  UNUSED_E7, UNUSED_E8, UNUSED_E9, UNUSED_EA,
  UNUSED_EB, UNUSED_EC, UNUSED_ED, UNUSED_EE,
  UNUSED_EF, UNUSED_F0, UNUSED_F1, UNUSED_F2,
  UNUSED_F3, UNUSED_F4, UNUSED_F5, UNUSED_F6,
  UNUSED_F7, UNUSED_F8, UNUSED_F9, UNUSED_FA,
  UNUSED_FB, UNUSED_FC, UNUSED_FD, UNUSED_FE,
  UNUSED_FF
}

Functions

PmReturn_t interpret (const uint8_t returnOnNoThreads)
PmReturn_t interp_reschedule (void)
PmReturn_t interp_addThread (pPmFunc_t pfunc)
void interp_setRescheduleFlag (uint8_t boolean)


Detailed Description

VM Interpreter.

VM interpreter header.


Define Documentation

#define FP   (gVmGlobal.pthread->pframe)

frame pointer ; currently for single thread

 
#define GET_ARG (  )     mem_getWord(MS, &IP)

gets the argument (S16) from the instruction stream

#define IP   (FP->fo_ip)

instruction pointer

#define MP   (gVmGlobal.pmod)

main module pointer (referred to by root frame)

#define MS   (FP->fo_memspace)

memspace where the frame's func's CO came from

#define NATIVE_GET_LOCAL (  )     (gVmGlobal.nativeframe.nf_locals[n])

gets the nth local var from the native frame locals

 
#define NATIVE_GET_NUM_ARGS (  )     (gVmGlobal.nativeframe.nf_numlocals)

gets the number of args passed to the native fxn

 
#define NATIVE_GET_PFRAME (  )     (*ppframe)

gets a pointer to the frame that called this native fxn

#define NATIVE_SET_TOS ( pobj   ) 

Value:

pushes an obj in the only stack slot of the native frame

 
#define PM_POP (  )     (*(--SP))

pops an obj from the stack

#define PM_PUSH ( pobj   )     (*(SP++) = (pobj))

pushes an obj on the stack

#define SP   (FP->fo_sp)

argument stack pointer

#define STACK (  )     (*(SP - ((n) + 1)))

index into stack; 0 is top, 1 is next

#define TOS   (*(SP - 1))

top of stack

#define TOS1   (*(SP - 2))

one under TOS

#define TOS2   (*(SP - 3))

two under TOS

#define TOS3   (*(SP - 4))

three under TOS


Typedef Documentation

typedef enum PmBcode_e PmBcode_t

Byte code enumeration

typedef enum PmCompare_e PmCompare_t

COMPARE_OP enum. Used by the COMPARE_OP bytecode to determine which type of compare to perform. Must match those defined in Python.


Enumeration Type Documentation

enum PmBcode_e

Byte code enumeration

COMPARE_OP enum. Used by the COMPARE_OP bytecode to determine which type of compare to perform. Must match those defined in Python.

Enumerator:
COMP_LT  less than
COMP_LE  less than or equal
COMP_EQ  equal
COMP_NE  not equal
COMP_GT  greater than
COMP_GE  greater than or equal
COMP_IN  is in
COMP_NOT_IN  is not in
COMP_IS  is
COMP_IS_NOT  is not
COMP_EXN_MATCH  do exceptions match


Function Documentation

PmReturn_t interp_addThread ( pPmFunc_t  pfunc  ) 

Creates a thread object and adds it to the queue of threads to be executed while interpret() is running.

The given obj may be a function, module, or class. Creates a frame for the given function.

Parameters:
pfunc Ptr to function to be executed as a thread.
Returns:
Return status

PmReturn_t interp_reschedule ( void   ) 

Selects a thread to run and changes the VM internal variables to let the switch-loop execute the chosen one in the next iteration. For the moment the algorithm is primitive and will change the thread each time it is called in a round-robin fashion.

void interp_setRescheduleFlag ( uint8_t  boolean  ) 

Sets the reschedule flag.

Parameters:
boolean Reschedule on next occasion if boolean is true; clear the flag otherwise.

PmReturn_t interpret ( const uint8_t  returnOnNoThreads  ) 

Interprets the available threads. Does not return.

Parameters:
returnOnNoThreads Loop forever if 0, exit with status if no more threads left.
Returns:
Return status if called with returnOnNoThreads != 0, will not return otherwise.


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