interp.h

Go to the documentation of this file.
00001 /*
00002 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
00003 #
00004 # This file is part of the PyMite VM.
00005 # The PyMite VM is free software: you can redistribute it and/or modify
00006 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
00007 #
00008 # The PyMite VM is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00011 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
00012 # is seen in the file COPYING in this directory.
00013 */
00014 
00015 
00016 #ifndef __INTERP_H__
00017 #define __INTERP_H__
00018 
00019 
00028 #include "thread.h"
00029 
00030 
00031 #define INTERP_LOOP_FOREVER          0
00032 #define INTERP_RETURN_ON_NO_THREADS  1
00033 
00034 
00036 #define PM_FP (gVmGlobal.pthread->pframe)
00037 
00038 #define PM_IP (PM_FP->fo_ip)
00039 
00040 #define PM_SP (PM_FP->fo_sp)
00041 
00043 #define TOS             (*(PM_SP - 1))
00044 
00045 #define TOS1            (*(PM_SP - 2))
00046 
00047 #define TOS2            (*(PM_SP - 3))
00048 
00049 #define TOS3            (*(PM_SP - 4))
00050 
00051 #define STACK(n)        (*(PM_SP - ((n) + 1)))
00052 
00053 #define PM_POP()        (*(--PM_SP))
00054 
00055 #define PM_PUSH(pobj)   (*(PM_SP++) = (pobj))
00056 
00057 #define GET_ARG()       mem_getWord(PM_FP->fo_memspace, &PM_IP)
00058 
00060 #define NATIVE_SET_TOS(pobj) (gVmGlobal.nativeframe.nf_stack = \
00061                         (pobj))
00062 
00063 #define NATIVE_GET_LOCAL(n) (gVmGlobal.nativeframe.nf_locals[n])
00064 
00065 #define NATIVE_GET_PFRAME()   (*ppframe)
00066 
00067 #define NATIVE_GET_NUM_ARGS() (gVmGlobal.nativeframe.nf_numlocals)
00068 
00069 
00076 typedef enum PmCompare_e
00077 {
00078     COMP_LT = 0,            
00079     COMP_LE,                
00080     COMP_EQ,                
00081     COMP_NE,                
00082     COMP_GT,                
00083     COMP_GE,                
00084     COMP_IN,                
00085     COMP_NOT_IN,            
00086     COMP_IS,                
00087     COMP_IS_NOT,            
00088     COMP_EXN_MATCH          
00089 } PmCompare_t, *pPmCompare_t;
00090 
00094 typedef enum PmBcode_e
00095 {
00096     /*
00097      * Python source to create this list:
00098      * import dis
00099      * o = dis.opname
00100      * for i in range(256):
00101      *     if o[i][0] != '<':
00102      *         print "\t%s," % o[i]
00103      *     else:
00104      *         print "\tUNUSED_%02X," % i
00105      */
00106     STOP_CODE = 0,              /* 0x00 */
00107     POP_TOP,
00108     ROT_TWO,
00109     ROT_THREE,
00110     DUP_TOP,
00111     ROT_FOUR,
00112     UNUSED_06,
00113     UNUSED_07,
00114     UNUSED_08,
00115     NOP,
00116     UNARY_POSITIVE,             /* d010 */
00117     UNARY_NEGATIVE,
00118     UNARY_NOT,
00119     UNARY_CONVERT,
00120     UNUSED_0E,
00121     UNARY_INVERT,
00122     UNUSED_10,                  /* 0x10 */
00123     UNUSED_11,
00124     LIST_APPEND,
00125     BINARY_POWER,
00126     BINARY_MULTIPLY,            /* d020 */
00127     BINARY_DIVIDE,
00128     BINARY_MODULO,
00129     BINARY_ADD,
00130     BINARY_SUBTRACT,
00131     BINARY_SUBSCR,
00132     BINARY_FLOOR_DIVIDE,
00133     BINARY_TRUE_DIVIDE,
00134     INPLACE_FLOOR_DIVIDE,
00135     INPLACE_TRUE_DIVIDE,
00136     SLICE_0,                    /* d030 */
00137     SLICE_1,
00138     SLICE_2,                    /* 0x20 */
00139     SLICE_3,
00140     UNUSED_22,
00141     UNUSED_23,
00142     UNUSED_24,
00143     UNUSED_25,
00144     UNUSED_26,
00145     UNUSED_27,
00146     STORE_SLICE_0,              /* d040 */
00147     STORE_SLICE_1,
00148     STORE_SLICE_2,
00149     STORE_SLICE_3,
00150     UNUSED_2C,
00151     UNUSED_2D,
00152     UNUSED_2E,
00153     UNUSED_2F,
00154     UNUSED_30,                  /* 0x30 */
00155     UNUSED_31,
00156     DELETE_SLICE_0,             /* d050 */
00157     DELETE_SLICE_1,
00158     DELETE_SLICE_2,
00159     DELETE_SLICE_3,
00160     STORE_MAP,
00161     INPLACE_ADD,
00162     INPLACE_SUBTRACT,
00163     INPLACE_MULTIPLY,
00164     INPLACE_DIVIDE,
00165     INPLACE_MODULO,
00166     STORE_SUBSCR,               /* d060 */
00167     DELETE_SUBSCR,
00168     BINARY_LSHIFT,
00169     BINARY_RSHIFT,
00170     BINARY_AND,                 /* 0x40 */
00171     BINARY_XOR,
00172     BINARY_OR,
00173     INPLACE_POWER,
00174     GET_ITER,
00175     UNUSED_45,
00176     PRINT_EXPR,                 /* d070 */
00177     PRINT_ITEM,
00178     PRINT_NEWLINE,
00179     PRINT_ITEM_TO,
00180     PRINT_NEWLINE_TO,
00181     INPLACE_LSHIFT,
00182     INPLACE_RSHIFT,
00183     INPLACE_AND,
00184     INPLACE_XOR,
00185     INPLACE_OR,
00186     BREAK_LOOP,                 /* 0x50 *//* d080 */
00187     WITH_CLEANUP,
00188     LOAD_LOCALS,
00189     RETURN_VALUE,
00190     IMPORT_STAR,
00191     EXEC_STMT,
00192     YIELD_VALUE,
00193     POP_BLOCK,
00194     END_FINALLY,
00195     BUILD_CLASS,
00196 
00197     /* Opcodes from here have an argument */
00198     HAVE_ARGUMENT = 90,         /* d090 */
00199     STORE_NAME = 90,
00200     DELETE_NAME,
00201     UNPACK_SEQUENCE,
00202     FOR_ITER,
00203     UNUSED_5E,
00204     STORE_ATTR,
00205     DELETE_ATTR,                /* 0x60 */
00206     STORE_GLOBAL,
00207     DELETE_GLOBAL,
00208     DUP_TOPX,
00209     LOAD_CONST,                 /* d100 */
00210     LOAD_NAME,
00211     BUILD_TUPLE,
00212     BUILD_LIST,
00213     BUILD_MAP,
00214     LOAD_ATTR,
00215     COMPARE_OP,
00216     IMPORT_NAME,
00217     IMPORT_FROM,
00218     UNUSED_6D,
00219     JUMP_FORWARD,               /* d110 */
00220     JUMP_IF_FALSE,
00221     JUMP_IF_TRUE,               /* 0x70 */
00222     JUMP_ABSOLUTE,
00223     UNUSED_72,
00224     UNUSED_73,
00225     LOAD_GLOBAL,
00226     UNUSED_75,
00227     UNUSED_76,
00228     CONTINUE_LOOP,
00229     SETUP_LOOP,                 /* d120 */
00230     SETUP_EXCEPT,
00231     SETUP_FINALLY,
00232     UNUSED_7B,
00233     LOAD_FAST,
00234     STORE_FAST,
00235     DELETE_FAST,
00236     UNUSED_79,
00237     UNUSED_80,                  /* 0x80 */
00238     UNUSED_81,
00239     RAISE_VARARGS,              /* d130 */
00240     CALL_FUNCTION,
00241     MAKE_FUNCTION,
00242     BUILD_SLICE,
00243     MAKE_CLOSURE,
00244     LOAD_CLOSURE,
00245     LOAD_DEREF,
00246     STORE_DEREF,
00247     UNUSED_8A,
00248     UNUSED_8B,
00249     CALL_FUNCTION_VAR,          /* d140 */
00250     CALL_FUNCTION_KW,
00251     CALL_FUNCTION_VAR_KW,
00252     EXTENDED_ARG,
00253 
00254     UNUSED_90, UNUSED_91, UNUSED_92, UNUSED_93,
00255     UNUSED_94, UNUSED_95, UNUSED_96, UNUSED_97,
00256     UNUSED_98, UNUSED_99, UNUSED_9A, UNUSED_9B,
00257     UNUSED_9C, UNUSED_9D, UNUSED_9E, UNUSED_9F,
00258     UNUSED_A0, UNUSED_A1, UNUSED_A2, UNUSED_A3,
00259     UNUSED_A4, UNUSED_A5, UNUSED_A6, UNUSED_A7,
00260     UNUSED_A8, UNUSED_A9, UNUSED_AA, UNUSED_AB,
00261     UNUSED_AC, UNUSED_AD, UNUSED_AE, UNUSED_AF,
00262     UNUSED_B0, UNUSED_B1, UNUSED_B2, UNUSED_B3,
00263     UNUSED_B4, UNUSED_B5, UNUSED_B6, UNUSED_B7,
00264     UNUSED_B8, UNUSED_B9, UNUSED_BA, UNUSED_BB,
00265     UNUSED_BC, UNUSED_BD, UNUSED_BE, UNUSED_BF,
00266     UNUSED_C0, UNUSED_C1, UNUSED_C2, UNUSED_C3,
00267     UNUSED_C4, UNUSED_C5, UNUSED_C6, UNUSED_C7,
00268     UNUSED_C8, UNUSED_C9, UNUSED_CA, UNUSED_CB,
00269     UNUSED_CC, UNUSED_CD, UNUSED_CE, UNUSED_CF,
00270     UNUSED_D0, UNUSED_D1, UNUSED_D2, UNUSED_D3,
00271     UNUSED_D4, UNUSED_D5, UNUSED_D6, UNUSED_D7,
00272     UNUSED_D8, UNUSED_D9, UNUSED_DA, UNUSED_DB,
00273     UNUSED_DC, UNUSED_DD, UNUSED_DE, UNUSED_DF,
00274     UNUSED_E0, UNUSED_E1, UNUSED_E2, UNUSED_E3,
00275     UNUSED_E4, UNUSED_E5, UNUSED_E6, UNUSED_E7,
00276     UNUSED_E8, UNUSED_E9, UNUSED_EA, UNUSED_EB,
00277     UNUSED_EC, UNUSED_ED, UNUSED_EE, UNUSED_EF,
00278     UNUSED_F0, UNUSED_F1, UNUSED_F2, UNUSED_F3,
00279     UNUSED_F4, UNUSED_F5, UNUSED_F6, UNUSED_F7,
00280     UNUSED_F8, UNUSED_F9, UNUSED_FA, UNUSED_FB,
00281     UNUSED_FC, UNUSED_FD, UNUSED_FE, UNUSED_FF
00282 } PmBcode_t, *pPmBcode_t;
00283 
00284 
00293 PmReturn_t interpret(const uint8_t returnOnNoThreads);
00294 
00301 PmReturn_t interp_reschedule(void);
00302 
00313 PmReturn_t interp_addThread(pPmFunc_t pfunc);
00314 
00321 void interp_setRescheduleFlag(uint8_t boolean);
00322 
00323 #endif /* __INTERP_H__ */

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