1. tuck
  2. pymite

Commits

Dean Hall  committed e2bbf90

#68: Mainlining directly

  • Participants
  • Parent commits 0279163
  • Branches default

Comments (0)

Files changed (42)

File src/lib/__bi.py

View file
  • Ignore whitespace
             return retval;
     }
 
-    /* XXX: Do a dummy map, fill func with Nones */
+    /* TODO #113: Fix the implementation of __bi.map */
+    /* Do a dummy map, fill func with Nones */
     retval = list_new(&pr);
     PM_RETURN_IF_ERROR(retval);
 

File src/vm/codeobj.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x01
+
 /**
  * CodeObj Type
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
     pPmCo_t pco = C_NULL;
     uint8_t *pchunk;
 
-    /* store ptr to top of code img (less type byte) */
+    /* Store ptr to top of code img (less type byte) */
     uint8_t const *pci = *paddr - 1;
 
-    /* get size of code img */
+    /* Get size of code img */
     uint16_t size = mem_getWord(memspace, paddr);
 
-    /* allocate a code obj */
+    /* Allocate a code obj */
     retval = heap_getChunk(sizeof(PmCo_t), &pchunk);
     PM_RETURN_IF_ERROR(retval);
     pco = (pPmCo_t)pchunk;
 
-    /* fill in the CO struct */
+    /* Fill in the CO struct */
     OBJ_SET_TYPE(*pco, OBJ_TYPE_COB);
     pco->co_memspace = memspace;
     pco->co_codeimgaddr = pci;
 
-    /* load names (tuple obj) */
+    /* Load names (tuple obj) */
     *paddr = pci + CI_NAMES_FIELD;
     retval = obj_loadFromImg(memspace, paddr, &pobj);
     PM_RETURN_IF_ERROR(retval);
     pco->co_names = (pPmTuple_t)pobj;
 
-    /* load consts (tuple obj) assume it follows names */
+    /* Load consts (tuple obj) assume it follows names */
     retval = obj_loadFromImg(memspace, paddr, &pobj);
     PM_RETURN_IF_ERROR(retval);
     pco->co_consts = (pPmTuple_t)pobj;
 
-    /* start of bcode always follows consts */
+    /* Start of bcode always follows consts */
     pco->co_codeaddr = *paddr;
 
-    /* set addr to point one past end of img */
+    /* Set addr to point one past end of img */
     *paddr = pci + size;
 
     *r_pco = (pPmObj_t)pco;
     pPmNo_t pno = C_NULL;
     uint8_t *pchunk;
 
-    /* allocate a code obj */
+    /* Allocate a code obj */
     retval = heap_getChunk(sizeof(PmNo_t), &pchunk);
     PM_RETURN_IF_ERROR(retval);
     pno = (pPmNo_t)pchunk;
 
-    /* fill in the NO struct */
+    /* Fill in the NO struct */
     OBJ_SET_TYPE(*pno, OBJ_TYPE_NOB);
     pno->no_argcount = mem_getByte(memspace, paddr);
-    /* get index into native fxn table */
+
+    /* Get index into native fxn table */
     pno->no_funcindx = (int16_t)mem_getWord(memspace, paddr);
 
     *r_pno = (pPmObj_t)pno;

File src/vm/codeobj.h

View file
  • Ignore whitespace
 
 #ifndef __CODEOBJ_H__
 #define __CODEOBJ_H__
+
 /**
  * CodeObj Type
  *
  */
 
 /***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
  * Constants
  **************************************************************/
 
-/** code image field offset consts */
+/** Code image field offset consts */
 #define CI_TYPE_FIELD       0
 #define CI_SIZE_FIELD       1
 #define CI_ARGCOUNT_FIELD   3
 #define CI_NLOCALS_FIELD    5
 #define CI_NAMES_FIELD      6
 
-/** native code image size */
+/** Native code image size */
 #define NATIVE_IMAGE_SIZE   4
 
 
 /***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
 /**
  * Code Object
  *
- * An extended object that holds only
- * the most frequently used parts
- * of the static code image.
- * Other parts can be obtained by
+ * 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 PmCo_s
 /**
  * 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
+ * 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.
  */
 typedef struct PmNo_s
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
 /**
- * Create a CodeObj by loading info from a code image in memory.
+ * 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
 co_loadFromImg(PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pco);
 
 /**
- * Create a Native code object by loading a native image.
+ * 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
 PmReturn_t no_loadFromImg(PmMemSpace_t memspace,
                           uint8_t const **paddr, pPmObj_t *r_pno);
 
-
 #endif /* __CODEOBJ_H__ */

File src/vm/dict.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x02
+
 /**
  * Dict Object Type
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
     PmReturn_t retval = PM_RET_OK;
     pPmDict_t pdict = C_NULL;
 
-    /* allocate a dict */
+    /* Allocate a dict */
     retval = heap_getChunk(sizeof(PmDict_t), (uint8_t **)r_pdict);
     PM_RETURN_IF_ERROR(retval);
 
-    /* init dict fields */
+    /* Init dict fields */
     pdict = (pPmDict_t)*r_pdict;
     OBJ_SET_TYPE(*pdict, OBJ_TYPE_DIC);
     pdict->length = 0;
         return retval;
     }
 
-    /* XXX if key is not hashable, raise TypeError */
-    /* XXX if key's hash hasn't been calculated */
+    /* TODO #112: If key is not hashable, raise TypeError */
 
     /* check for matching key */
     retval = seglist_findEqual(((pPmDict_t)pdict)->d_keys, pkey, &indx);
 
     return retval;
 }
-
-
-/***************************************************************
- * Test
- **************************************************************/
-
-/***************************************************************
- * Main
- **************************************************************/

File src/vm/dict.h

View file
  • Ignore whitespace
 
 #ifndef __DICT_H__
 #define __DICT_H__
+
 /**
  * Dict Object Type
  *
  * 2002/04/30   First.
  */
 
-/***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
 
 /***************************************************************
  * Types
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
  */
 PmReturn_t dict_clear(pPmObj_t pdict);
 
-
 /**
- * Get the value in the dict using the given key.
+ * Gets the value in the dict using the given key.
  *
  * @param   pdict ptr to dict to search
  * @param   pkey ptr to key obj
  */
 PmReturn_t dict_getItem(pPmObj_t pdict, pPmObj_t pkey, pPmObj_t *r_pobj);
 
-
 /**
- * Allocate space for a new Dict.
+ * Allocates space for a new Dict.
  * Return a pointer to the dict by reference.
  *
  * @param   r_pdict Return; Addr of ptr to dict
  */
 PmReturn_t dict_new(pPmObj_t *r_pdict);
 
-
 /**
- * Set a value in the dict using the given key.
+ * Sets a value in the dict using the given key.
  *
  * If the dict already contains a matching key, the value is
  * replaced; otherwise the new key,val pair is inserted
 
 #ifdef HAVE_PRINT
 /**
- * Print out a dict. Uses obj_print() to print elements.
- * 
+ * Prints out a dict. Uses obj_print() to print elements.
+ *
  * @param pobj Object to print.
  * @return Return status
  */
  */
 PmReturn_t dict_update(pPmObj_t pdestdict, pPmObj_t psourcedict);
 
-#if 0
-/* TBD */
-pPmObj_t dict_copy(pPmObj_t pdict);
-U8 dict_hasKey(pPmObj_t pdict, pPmObj_t pkey);
-pPmObj_t dict_items(pPmObj_t pdict);    /* list of (keys,vals) */
-pPmObj_t dict_keys(pPmObj_t pdict);
-pPmObj_t dict_popItem(pPmObj_t pdict);
-void dict_setDefault(pPmObj_t pdict, /*HERE*/);
-pPmObj_t dict_values(pPmObj_t pdict);
-#endif
-
 #endif /* __DICT_H__ */

File src/vm/frame.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x03
+
 /**
  * VM Frame
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
     uint8_t const *paddr = C_NULL;
     uint8_t *pchunk;
 
-    /* get fxn's code obj */
+    /* Get fxn's code obj */
     pco = ((pPmFunc_t)pfunc)->f_co;
 
     /* TypeError if passed func's CO is not a true COB */
         return retval;
     }
 
-    /* get sizes needed to calc frame size */
+    /* Get sizes needed to calc frame size */
     paddr = pco->co_codeimgaddr + CI_STACKSIZE_FIELD;
     stacksz = mem_getByte(pco->co_memspace, &paddr);
-    /* now paddr points to CI_NLOCALS_FIELD */
+
+    /* Now paddr points to CI_NLOCALS_FIELD */
     nlocals = mem_getByte(pco->co_memspace, &paddr);
-    fsize = sizeof(PmFrame_t) + (stacksz + nlocals) * sizeof(pPmObj_t);
-    /* allocate a frame */
+    fsize = sizeof(PmFrame_t) + (stacksz + nlocals - 1) * sizeof(pPmObj_t);
+
+    /* Allocate a frame */
     retval = heap_getChunk(fsize, &pchunk);
     PM_RETURN_IF_ERROR(retval);
     pframe = (pPmFrame_t)pchunk;
 
-    /* set frame fields */
+    /* Set frame fields */
     OBJ_SET_TYPE(*pframe, OBJ_TYPE_FRM);
     pframe->fo_back = C_NULL;
     pframe->fo_func = (pPmFunc_t)pfunc;
     pframe->fo_memspace = pco->co_memspace;
-    /* init instruction pointer, line number and block stack */
+
+    /* Init instruction pointer, line number and block stack */
     pframe->fo_ip = pco->co_codeaddr;
     pframe->fo_line = 0;
     pframe->fo_blockstack = C_NULL;
+
     /* Get globals and attrs from the function object */
     pframe->fo_globals = ((pPmFunc_t)pfunc)->f_globals;
     pframe->fo_attrs = ((pPmFunc_t)pfunc)->f_attrs;
-    /* empty stack points to one past locals */
+
+    /* Empty stack points to one past locals */
     pframe->fo_sp = &(pframe->fo_locals[nlocals]);
-    /* by default, this is a normal frame, not an import call one */
+
+    /* By default, this is a normal frame, not an import call one */
     pframe->fo_isImport = 0;
 
-    /* return ptr to frame */
+    /* Return ptr to frame */
     *r_pobj = (pPmObj_t)pframe;
     return retval;
 }
-
-
-/***************************************************************
- * Test
- **************************************************************/
-
-/***************************************************************
- * Main
- **************************************************************/

File src/vm/frame.h

View file
  • Ignore whitespace
 
 #ifndef __FRAME_H__
 #define __FRAME_H__
+
 /**
  * VM Frame
  *
  */
 
 /***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
  * Constants
  **************************************************************/
 
 /**
- * the maximum number of local variables
- * a native function can have.
- * This defines the length of the locals array
- * in the native frame struct.
+ * The maximum number of local variables a native function can have.
+ * This defines the length of the locals array in the native frame struct.
  */
 #define NATIVE_NUM_LOCALS   8
 
 
 /***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
 /**
  * Block Type
  *
- * Numerical values to put in the 'b_type' field
- * of the tPmBlockType struct.
+ * Numerical values to put in the 'b_type' field of the tPmBlockType struct.
  */
 typedef enum PmBlockType_e
 {
-    /** invalide block type */
+    /** Invalid block type */
     B_INVALID = 0,
-    /** loop type */
+
+    /** Loop type */
     B_LOOP,
-    /** try type */
+
+    /** Try type */
     B_TRY
 } PmBlockType_t, *pPmBlockType_t;
 
  */
 typedef struct PmBlock_s
 {
-    /** obligatory obj descriptor */
+    /** Obligatory obj descriptor */
     PmObjDesc_t od;
-    /** ptr to backup stack ptr */
+
+    /** Ptr to backup stack ptr */
     pPmObj_t *b_sp;
-    /** handler fxn obj */
+
+    /** Handler fxn obj */
     uint8_t const *b_handler;
-    /** block type */
+
+    /** Block type */
     PmBlockType_t b_type:8;
-    /** next block in stack */
+
+    /** Next block in stack */
     struct PmBlock_s *next;
 } PmBlock_t,
  *pPmBlock_t;
 /**
  * Frame
  *
- * A struct that holds the execution frame
- * of a function, including the stack, local vars
- * and pointer to the code object.
+ * A struct that holds the execution frame of a function, including the stack,
+ * local vars and pointer to the code object.
  *
  * This struct doesn't declare the stack.
  * frame_new() is responsible for allocating the extra memory
  */
 typedef struct PmFrame_s
 {
-    /** obligatory obj descriptor */
+    /** Obligatory obj descriptor */
     PmObjDesc_t od;
-    /** ptr to previous frame obj */
+
+    /** Ptr to previous frame obj */
     struct PmFrame_s *fo_back;
-    /** ptr to fxn obj */
+
+    /** Ptr to fxn obj */
     pPmFunc_t fo_func;
-    /** mem space where func's CO comes from */
+
+    /** Mem space where func's CO comes from */
     PmMemSpace_t fo_memspace:8;
-    /** instrxn ptr (pts into memspace) */
+
+    /** Instrxn ptr (pts into memspace) */
     uint8_t const *fo_ip;
-    /** current source line num */
+
+    /** Current source line num */
     uint16_t fo_line;
-    /** linked list of blocks */
+
+    /** Linked list of blocks */
     pPmBlock_t fo_blockstack;
-    /** local attributes dict (non-fast locals) */
+
+    /** Local attributes dict (non-fast locals) */
     pPmDict_t fo_attrs;
-    /** global attributes dict (pts to root frame's globals */
+
+    /** Global attributes dict (pts to root frame's globals */
     pPmDict_t fo_globals;
-    /** points to next empty slot in fo_locals (1 past TOS) */
+
+    /** Points to next empty slot in fo_locals (1 past TOS) */
     pPmObj_t *fo_sp;
-    /** frame can be an import-frame that handles RETURN differently */
+
+    /** Frame can be an import-frame that handles RETURN differently */
     uint8_t fo_isImport:1;
-    /** array of local vars and stack (space appended at alloc) */
-    pPmObj_t fo_locals[0];
+
+    /** Array of local vars and stack (space appended at alloc) */
+    pPmObj_t fo_locals[1];
+    /* WARNING: Do not put new fields below fo_locals */
 } PmFrame_t,
  *pPmFrame_t;
 
 /**
  * Native Frame
  *
- * A struct that holds the execution frame
- * of a native function, including the args and
- * single stack slot, and pointer to the code object.
+ * A struct that holds the execution frame of a native function,
+ * including the args and single stack slot, and pointer to the code object.
  *
- * This struct doesn't need an OD because it is only
- * used statically in the globals struct.
- * There's only one native frame, the global one.
+ * This struct doesn't need an OD because it is only used statically in the
+ * globals struct.  There's only one native frame, the global one.
  * This happens because a native function is a leaf node
  * in the call tree (a native func can't call python funcs).
  */
 typedef struct PmNativeFrame_s
 {
-    /** ptr to previous frame obj */
+    /** Ptr to previous frame obj */
     struct PmFrame_s *nf_back;
-    /** ptr to fxn obj */
+
+    /** Ptr to fxn obj */
     pPmFunc_t nf_func;
-    /** single stack slot */
+
+    /** Single stack slot */
     pPmObj_t nf_stack;
-    /** local vars */
+
+    /** Local vars */
     pPmObj_t nf_locals[NATIVE_NUM_LOCALS];
 } PmNativeFrame_t,
  *pPmNativeFrame_t;
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
  */
 PmReturn_t frame_new(pPmObj_t pfunc, pPmObj_t *r_pobj);
 
-/**
- * TODO
- * #define PM_FRAME_GET_CONST(pfo, indx)
- * #define PM_FRAME_GET_LOCAL(pfo, indx)
- * #define PM_FRAME_SET_LOCAL(pfo, indx, pod)
- * #define PM_FRAME_GET_ATTR(pfo, namei)
- * #define PM_FRAME_SET_ATTR(pfo, namei, pod)
- */
-
 #endif /* __FRAME_H__ */

File src/vm/func.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x04
+
 /**
  * Function Object Type
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
              || OBJ_GET_TYPE(*pco) != OBJ_TYPE_NOB);
     C_ASSERT(OBJ_GET_TYPE(*pglobals) == OBJ_TYPE_DIC);
 
-    /* allocate a func obj */
+    /* Allocate a func obj */
     retval = heap_getChunk(sizeof(PmFunc_t), &pchunk);
     PM_RETURN_IF_ERROR(retval);
     pfunc = (pPmFunc_t)pchunk;
 
-    /* init func */
+    /* Init func */
     OBJ_SET_TYPE(*pfunc, OBJ_TYPE_FXN);
     pfunc->f_co = (pPmCo_t)pco;
-    /* create attrs dict for regular func (not native) */
+
+    /* Create attrs dict for regular func (not native) */
     if (OBJ_GET_TYPE(*pco) == OBJ_TYPE_COB)
     {
         retval = dict_new(&pobj);
     {
         pfunc->f_attrs = C_NULL;
     }
-    /* clear default args (will be set later, if at all) */
+
+    /* Clear default args (will be set later, if at all) */
     pfunc->f_defaultargs = C_NULL;
 
     *r_pfunc = (pPmObj_t)pfunc;
     return PM_RET_OK;
 }
 
+
 /*
  * This function requires that all parameters have their
  * expected type.  (parm types already checked).
     uint8_t const *btstr = (uint8_t const *)"__bt";
     uint8_t const *nmstr = (uint8_t const *)"__nm";
 
-    /* ensure types */
+    /* Ensure types */
     if ((OBJ_GET_TYPE(*pmeths) != OBJ_TYPE_DIC) ||
         (OBJ_GET_TYPE(*pbases) != OBJ_TYPE_TUP) ||
         (OBJ_GET_TYPE(*pname) != OBJ_TYPE_STR))
         return retval;
     }
 
-    /* allocate a class obj */
+    /* Allocate a class obj */
     retval = heap_getChunk(sizeof(PmFunc_t), (uint8_t **)r_pclass);
     PM_RETURN_IF_ERROR(retval);
     OBJ_SET_TYPE(**r_pclass, OBJ_TYPE_CLO);
-    /* class has no access to its CO */
+
+    /* Class has no access to its CO */
     ((pPmFunc_t)*r_pclass)->f_co = C_NULL;
     ((pPmFunc_t)*r_pclass)->f_attrs = (pPmDict_t)pmeths;
-    /* store base tuple in __bt slot */
+
+    /* Store base tuple in __bt slot */
     retval = string_new(&btstr, &pkey);
     PM_RETURN_IF_ERROR(retval);
     retval = dict_setItem((pPmObj_t)((pPmFunc_t)*r_pclass)->f_attrs,
                           pkey, (pPmObj_t)pbases);
     PM_RETURN_IF_ERROR(retval);
-    /* store the name of the class in the __nm slot */
+
+    /* Store the name of the class in the __nm slot */
     retval = string_new(&nmstr, &pkey);
     PM_RETURN_IF_ERROR(retval);
     retval = dict_setItem((pPmObj_t)((pPmFunc_t)*r_pclass)->f_attrs,
                           pkey, (pPmObj_t)pname);
     return retval;
 }
-
-
-/***************************************************************
- * Test
- **************************************************************/
-
-/***************************************************************
- * Main
- **************************************************************/

File src/vm/func.h

View file
  • Ignore whitespace
 
 #ifndef __FUNC_H__
 #define __FUNC_H__
+
 /**
  * Function Object Type
  *
  */
 
 /***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
  * Function obj
  *
  * A function is like an instance of a code obj.
- * Contains ptr to its code obj and
- * has its own attributes dict.
+ * Contains ptr to its code obj and has its own attributes dict.
  *
- * The first (__main__) module that is executed
- * has a function obj created for it to execute
- * the bytecode which builds the module.
+ * The first (__main__) module that is executed has a function obj
+ * created for it to execute the bytecode which builds the module.
  */
 typedef struct PmFunc_s
 {
-    /** object descriptor */
+    /** Object descriptor */
     PmObjDesc_t od;
-    /** ptr to code obj */
+
+    /** Ptr to code obj */
     pPmCo_t f_co;
-    /** ptr to attribute dict */
+
+    /** Ptr to attribute dict */
     pPmDict_t f_attrs;
-    /** ptr to globals dict */
+
+    /** Ptr to globals dict */
     pPmDict_t f_globals;
-    /** ptr to tuple holding default args */
+
+    /** Ptr to tuple holding default args */
     pPmTuple_t f_defaultargs;
 } PmFunc_t,
  *pPmFunc_t;
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
 /**
- * Create a Function Obj for the given Code Obj.
+ * Creates a Function Obj for the given Code Obj.
  * Allocate space for a Func obj and fill the fields.
  *
  * @param   pco ptr to code obj
 PmReturn_t func_new(pPmObj_t pco, pPmObj_t pglobals, pPmObj_t *r_pfunc);
 
 /**
- * Create a new Class object from the methods dict, bases tuple,
+ * Creates a new Class object from the methods dict, bases tuple,
  * and name string.
  *
  * @param   pmeths ptr to methods dict.
 PmReturn_t class_new(pPmObj_t pmeths,
                      pPmObj_t pbases, pPmObj_t pname, pPmObj_t *r_pclass);
 
-
-#endif /* __TEMPLATE_H__ */
+#endif /* __FUNC_H__ */

File src/vm/global.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x05
+
 /**
  * VM Globals
  *
 
 uint8_t const *global_bistr = (uint8_t const *)"__bi";
 
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
 
 /***************************************************************
  * Globals
     uint8_t *codestr = (uint8_t *)"code";
     pPmObj_t pobj;
 
-    /* clear the global struct */
+    /* Clear the global struct */
     sli_memset((uint8_t *)&gVmGlobal, '\0', sizeof(PmVmGlobal_t));
 
-    /* set the PyMite release num (for debug and post mortem) */
+    /* Set the PyMite release num (for debug and post mortem) */
     gVmGlobal.errVmRelease = PM_RELEASE;
 
-    /* init zero */
+    /* Init zero */
     OBJ_SET_TYPE(gVmGlobal.zero, OBJ_TYPE_INT);
     OBJ_SET_SIZE(gVmGlobal.zero, sizeof(PmInt_t));
     gVmGlobal.zero.val = (int32_t)0;
 
-    /* init one */
+    /* Init one */
     OBJ_SET_TYPE(gVmGlobal.one, OBJ_TYPE_INT);
     OBJ_SET_SIZE(gVmGlobal.one, sizeof(PmInt_t));
     gVmGlobal.one.val = (int32_t)1;
 
-    /* init negone */
+    /* Init negone */
     OBJ_SET_TYPE(gVmGlobal.negone, OBJ_TYPE_INT);
     OBJ_SET_SIZE(gVmGlobal.negone, sizeof(PmInt_t));
     gVmGlobal.negone.val = (int32_t)-1;
 
-    /* init None */
+    /* Init None */
     OBJ_SET_TYPE(gVmGlobal.none, OBJ_TYPE_NON);
     OBJ_SET_SIZE(gVmGlobal.none, sizeof(PmObj_t));
 
     retval = string_new((uint8_t const **)&codestr, &pobj);
     gVmGlobal.pcodeStr = (pPmString_t)pobj;
 
-    /* init empty builtins */
+    /* Init empty builtins */
     gVmGlobal.builtins = C_NULL;
 
-    /* empty img info list */
+    /* Empty img info list */
     gVmGlobal.pimglist = C_NULL;
 
-    /* clear ptrs */
+    /* Clear ptrs */
     /*FP = C_NULL; *//* fp is local to interp, until thread struct is made */
 
-    /* create empty threadList */
+    /* Create empty threadList */
     list_new((pPmObj_t *)&(gVmGlobal.threadList));
 
     return retval;
 
     if (PM_PBUILTINS == C_NULL)
     {
-        /* need to load builtins first */
+        /* Need to load builtins first */
         global_loadBuiltins();
     }
-    /* put builtins module in the module's attrs dict */
+
+    /* Put builtins module in the module's attrs dict */
     retval = string_new(&global_bistr, &pkey);
     PM_RETURN_IF_ERROR(retval);
+
     return dict_setItem((pPmObj_t)pmod->f_attrs, pkey, PM_PBUILTINS);
 }
 
     pPmObj_t pstr = C_NULL;
     pPmObj_t pbimod;
 
-    /* import the builtins */
+    /* Import the builtins */
     retval = string_new(&global_bistr, &pstr);
     PM_RETURN_IF_ERROR(retval);
     retval = mod_import(pstr, &pbimod);
     PM_RETURN_IF_ERROR(retval);
 
-    /* must interpret builtins' root code to set the attrs */
+    /* Must interpret builtins' root code to set the attrs */
     C_ASSERT(gVmGlobal.threadList->length == 0);
     interp_addThread((pPmFunc_t)pbimod);
     retval = interpret(INTERP_RETURN_ON_NO_THREADS);
     PM_RETURN_IF_ERROR(retval);
 
-    /* builtins points to the builtins module's attrs dict */
+    /* Builtins points to the builtins module's attrs dict */
     gVmGlobal.builtins = ((pPmFunc_t)pbimod)->f_attrs;
 
-    /* set None manually */
+    /* Set None manually */
     retval = string_new(&nonestr, &pkey);
     PM_RETURN_IF_ERROR(retval);
     retval = dict_setItem(PM_PBUILTINS, pkey, PM_NONE);
     PM_RETURN_IF_ERROR(retval);
 
-    /* deallocate builtins module */
+    /* Deallocate builtins module */
     retval = heap_freeChunk((pPmObj_t)pbimod);
 
     return retval;

File src/vm/global.h

View file
  • Ignore whitespace
 
 #ifndef __GLOBAL_H__
 #define __GLOBAL_H__
+
 /**
  * VM Globals
  *
  * 2002/04/22   First.
  */
 
-/***************************************************************
- * Includes
- **************************************************************/
 
 /***************************************************************
  * Constants
 /** The global string "code" */
 #define PM_CODE_STR     (pPmObj_t)(gVmGlobal.pcodeStr)
 
-/***************************************************************
- * Macros
- **************************************************************/
 
 /***************************************************************
  * Types
     /** Ptr to current thread */
     pPmThread_t pthread;
 
-    /** flag to trigger rescheduling */
-    uint8_t reschedule:1;
-
+    /** Flag to trigger rescheduling */
+    uint8_t reschedule;
 } PmVmGlobal_t,
  *pPmVmGlobal_t;
 
 
 /**
  * Sets the builtins dict into the given module's attrs.
- * 
+ *
  * If not yet done, loads the "__bt" module via global_loadBuiltins().
  * Restrictions described in that functions documentation apply.
- * 
+ *
  * @param pmod Module whose attrs receive builtins
  * @return Return status
  */
  * Loads the "__bt" module and sets the builtins dict (PM_PBUILTINS)
  * to point to __bt's attributes dict.
  * Creates "None" = None entry in builtins.
- * 
+ *
  * When run, there should not be any other threads in the interpreter
  * thread list yet.
  *

File src/vm/heap.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x06
+
 /**
  * VM Heap
  *
 
 
 /***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
 
 
 /***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
         /* Move the cleanheap remnant to the freelist if it is small enough */
         if (pmHeap.cleanheapavail <= HEAP_MAX_CHUNK_SIZE)
         {
-            /* TODO */
+            /*
+             * TODO: this is optional since cleanheap will be whittled away
+             * to a size the prevents the containing "if" to never be true
+             */
         }
 
         return PM_RET_OK;

File src/vm/heap.h

View file
  • Ignore whitespace
 
 #ifndef __HEAP_H__
 #define __HEAP_H__
+
 /**
  * VM Heap
  *
  * 2002/04/30   First.
  */
 
-/***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
- * Constants
- **************************************************************/
 
 /***************************************************************
  * Macros
 
 typedef struct PmHeapDesc_s
 {
-    /** object descriptor (only the size field is relevant */
+    /** Object descriptor (only the size field is relevant */
     PmObjDesc_t od;
-    /** ptr to next chunk */
+
+    /** Ptr to next chunk */
     struct PmHeapDesc_s *next;
 } PmHeapDesc_t,
  *pPmHeapDesc_t;
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
 /**
- * Initialize the heap for use.
- *
- * Set the heap as one big chunk.
+ * Initializes the heap for use.
  *
  * @return  nothing.
  */
  * Returns a free chunk from the heap.
  *
  * The chunk will be at least the requested size.
- * The actual size can be found in the return
- * chunk's od.od_size.
- * Garbage will be collected if necessary.
+ * The actual size can be found in the return chunk's od.od_size.
  *
  * @param   requestedsize Requested size of the chunk in bytes.
  * @param   r_pchunk Addr of ptr to chunk (return).
 PmReturn_t heap_getChunk(uint16_t requestedsize, uint8_t **r_pchunk);
 
 /**
- * Place the chunk back in the heap.
+ * Places the chunk back in the heap.
  *
  * @param   ptr Pointer to object to free.
  */

File src/vm/img.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x07
+
 /**
  * Image routines
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
 /*
- * An image identified by its first byte, the type OBJ_TYPE_CIM.
+ * An image is identified by its first byte, the type OBJ_TYPE_CIM.
  * If the given address does not point to a byte with the
  * same value as OBJ_TYPE_CIM, the starting address is bogus
  * and the function returns.
  * no longer identifies a code image, or some other error
  * occurs.
  *
- * XXX Images with same module name will be blindly inserted
- * into list.  Need to support calling import twice on an obj
- * without filling memory.
+ * WARNING: Images with the same module name will be blindly inserted
+ * into the image list, but only the first image found will be used.
  */
 PmReturn_t
 img_findInMem(PmMemSpace_t memspace, uint8_t const **paddr)
     pPmObj_t pnamestr = C_NULL;
     uint8_t *pchunk;
 
-    /* addr is top of img */
+    /* Addr is top of img */
     imgtop = *paddr;
-    /* get img's type byte */
+
+    /* Get img's type byte */
     type = (PmType_t)mem_getByte(memspace, paddr);
 
-    /* get all sequential images */
+    /* Get all sequential images */
     while (type == OBJ_TYPE_CIM)
     {
-        /* use size field to calc addr of next potential img */
+        /* Use size field to calc addr of next potential img */
         size = mem_getWord(memspace, paddr);
 
-        /* get name of img */
-        /* point to names tuple */
+        /* Get name of img */
+        /* Point to names tuple */
         *paddr = imgtop + CI_NAMES_FIELD;
-        /* ensure it's a tuple */
+
+        /* Ensure it's a tuple */
         type = mem_getByte(memspace, paddr);
         if (type != OBJ_TYPE_TUP)
         {
             PM_RAISE(retval, PM_RET_EX_TYPE);
             return retval;
         }
-        /* get index of last obj in tuple */
+
+        /* Get index of last obj in tuple */
         n = mem_getByte(memspace, paddr) - (uint8_t)1;
-        /* point to names tuple */
+
+        /* Point to names tuple */
         *paddr = imgtop + CI_NAMES_FIELD;
-        /* load name at index */
+
+        /* Load name at index */
         retval = img_getName(memspace, paddr, n, &pnamestr);
         PM_RETURN_IF_ERROR(retval);
 
-        /* alloc and fill imginfo struct */
+        /* Alloc and fill imginfo struct */
         retval = heap_getChunk(sizeof(PmImgInfo_t), &pchunk);
         PM_RETURN_IF_ERROR(retval);
         pii = (pPmImgInfo_t)pchunk;
         pii->ii_name = (pPmString_t)pnamestr;
         pii->ii_memspace = memspace;
         pii->ii_addr = imgtop;
-        /* push struct into img stack */
+
+        /* Push struct into img stack */
         pii->next = gVmGlobal.pimglist;
         gVmGlobal.pimglist = pii;
 
-        /* setup for next iteration */
-        /* calc next imgtop */
+        /* Setup for next iteration */
+        /* Calc next imgtop */
         imgtop += size;
-        /* point to next potential img */
+
+        /* Point to next potential img */
         *paddr = imgtop;
-        /* check if next is img */
+
+        /* Check if another img follows this one */
         type = mem_getByte(memspace, paddr);
     }
     return retval;
 {
     PmType_t type;
     uint16_t len;
-    PmReturn_t retval;
 
-    /* XXX ensure it's a tuple */
-    /* skip past type and size bytes */
-    *paddr += 2;
+    /* Ensure it's a tuple */
+    type = mem_getByte(memspace, paddr);
+    C_ASSERT(type == OBJ_TYPE_TUP);
+    
+    /* Skip past length byte */
+    *paddr += 1;
 
-    /* scan to last name */
+    /* Scan to last name */
     for (; n > 0; n--)
     {
-        /* skip type byte, assuming string */
-        (*paddr)++;
-        /* skip the length of the string */
+        /* Ensure obj is a string */
+        type = mem_getByte(memspace, paddr);
+        C_ASSERT(type == OBJ_TYPE_STR);
+        
+        /* Skip the length of the string */
         len = mem_getWord(memspace, paddr);
         (*paddr) += len;
     }
 
-    /* ensure it's a string */
+    /* Ensure it's a string */
     type = mem_getByte(memspace, paddr);
-    if (type != OBJ_TYPE_STR)
-    {
-        PM_RAISE(retval, PM_RET_EX_TYPE);
-        return retval;
-    }
+    C_ASSERT(type == OBJ_TYPE_STR);
 
-    /* backtrack paddr to point to top of string img */
+    /* Backtrack paddr to point to top of string img */
     (*paddr)--;
-    /* return name string obj */
+    
+    /* Return name string obj */
     return obj_loadFromImg(memspace, paddr, r_pname);
 }

File src/vm/img.h

View file
  • Ignore whitespace
 
 #ifndef __IMG_H__
 #define __IMG_H__
+
 /**
  * Image header
  *
  */
 
 /***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
  */
 typedef struct PmImgInfo_s
 {
-    /** the image's name as a String obj */
+    /** The image's name as a String obj */
     pPmString_t ii_name;
-    /** the memory space in which the image is located */
+    
+    /** The memory space in which the image is located */
     PmMemSpace_t ii_memspace:8;
-    /** the starting address of the image */
+    
+    /** The starting address of the image */
     uint8_t const *ii_addr;
-    /** ptr to next image ID struct */
+    
+    /** Ptr to next image ID struct */
     struct PmImgInfo_s *next;
 } PmImgInfo_t,
  *pPmImgInfo_t;
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
 /**
- * Scan code images in memory.
+ * Scans code images in memory.
  *
  * Find consecutive code images in the given memory space
  * starting at the given address.  Store (name, address)
 PmReturn_t img_findInMem(PmMemSpace_t memspace, uint8_t const **paddr);
 
 /**
- * Load a string obj from the names tuple at the given index.
+ * Loads a string obj from the names tuple at the given index.
  *
  * @param   memspace Memory space to use.
  * @param   paddr Ptr to address of names tuple image.
 PmReturn_t img_getName(PmMemSpace_t memspace,
                        uint8_t const **paddr, uint8_t n, pPmObj_t *r_pname);
 
-
-#endif /* __TEMPLATE_H__ */
+#endif /* __IMG_H__ */

File src/vm/int.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x08
+
 /**
  * Integer Object Type
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
  * Functions
  **************************************************************/
 
 {
     PmReturn_t retval = PM_RET_OK;
 
-    /* allocate new int */
+    /* Allocate new int */
     retval = heap_getChunk(sizeof(PmInt_t), (uint8_t **)r_pint);
     PM_RETURN_IF_ERROR(retval);
 
-    /* copy value */
+    /* Copy value */
     OBJ_SET_TYPE(**r_pint, OBJ_TYPE_INT);
     ((pPmInt_t)*r_pint)->val = ((pPmInt_t)pint)->val;
     return retval;
 {
     PmReturn_t retval = PM_RET_OK;
 
-    /* if n is 0,1,-1, return global int */
+    /* If n is 0,1,-1, return static int objects from global struct */
     if (n == 0)
     {
         *r_pint = PM_ZERO;
         return PM_RET_OK;
     }
 
-    /* XXX search for int in pool? */
-
-    /* else create and return new int obj */
+    /* Else create and return new int obj */
     retval = heap_getChunk(sizeof(PmInt_t), (uint8_t **)r_pint);
     PM_RETURN_IF_ERROR(retval);
     OBJ_SET_TYPE(**r_pint, OBJ_TYPE_INT);
 {
     PmReturn_t retval;
 
-    /* ensure it's an int */
+    /* Raise TypeError if obj is not an int */
     if (OBJ_GET_TYPE(*pobj) != OBJ_TYPE_INT)
     {
         PM_RAISE(retval, PM_RET_EX_TYPE);
         return retval;
     }
 
-    /* create new int obj */
+    /* Create new int obj */
     return int_new(((pPmInt_t)pobj)->val, r_pint);
 }
 
 {
     PmReturn_t retval;
 
-    /* ensure it's an int */
+    /* Raise TypeError if obj is not an int */
     if (OBJ_GET_TYPE(*pobj) != OBJ_TYPE_INT)
     {
         PM_RAISE(retval, PM_RET_EX_TYPE);
         return retval;
     }
 
-    /* create new int obj */
+    /* Create new int obj */
     return int_new(-((pPmInt_t)pobj)->val, r_pint);
 }
 
 {
     PmReturn_t retval;
 
-    /* ensure it's an int */
+    /* Raise TypeError if obj is not an int */
     if (OBJ_GET_TYPE(*pobj) != OBJ_TYPE_INT)
     {
         PM_RAISE(retval, PM_RET_EX_TYPE);
         return retval;
     }
 
-    /* create new int obj */
+    /* Create new int obj */
     return int_new(~((pPmInt_t)pobj)->val, r_pint);
 }
 
 {
     /* 2^31-1 has 10 decimal digits, plus sign and zero byte */
     uint8_t tBuffer[10 + 1 + 1];
-    uint8_t bytesWritten,
-      k;
+    uint8_t bytesWritten;
+    uint8_t k;
     PmReturn_t retval = PM_RET_OK;
 
     C_ASSERT(pint != C_NULL);
 
-    /* ensure string obj */
+    /* Raise TypeError if obj is not an int */
     if (OBJ_GET_TYPE(*pint) != OBJ_TYPE_INT)
     {
         PM_RAISE(retval, PM_RET_EX_TYPE);
     return _int_printHex(((pPmInt_t)pint)->val);
 }
 #endif /* HAVE_PRINT */
-
-
-/***************************************************************
- * Test
- **************************************************************/
-
-/***************************************************************
- * Main
- **************************************************************/

File src/vm/int.h

View file
  • Ignore whitespace
 
 #ifndef __INT_H__
 #define __INT_H__
+
 /**
  * Integer Object Type
  *
  */
 
 /***************************************************************
- * Includes
- **************************************************************/
-
-/***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
  * Types
  **************************************************************/
 
  */
 typedef struct PmInt_s
 {
-    /** object descriptor */
+    /** Object descriptor */
     PmObjDesc_t od;
-    /** integer value */
+    
+    /** Integer value */
     int32_t val;
 } PmInt_t,
  *pPmInt_t;
 
 
 /***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
 /**
- * Create a duplicate Integer object
+ * Creates a duplicate Integer object
  *
- * but let it be dynamic.
  * Created specifically for the index value in FOR_LOOP.
  *
  * @param   pint Pointer to int obj to duplicate.
 PmReturn_t int_dup(pPmObj_t pint, pPmObj_t *r_pint);
 
 /**
- * Create a new Integer object
+ * Creates a new Integer object
  *
  * @param   n Value to assign int (signed 32-bit).
  * @param   r_pint Return by ref, ptr to new int
 PmReturn_t int_new(int32_t val, pPmObj_t *r_pint);
 
 /**
- * Implement the UNARY_POSITIVE bcode.
+ * Implements the UNARY_POSITIVE bcode.
  *
- * Create a new int with the same value as the given int.
+ * Creates a new int with the same value as the given int.
  *
  * @param   pobj Pointer to target object
  * @param   r_pint Return by ref, ptr to int
 PmReturn_t int_positive(pPmObj_t, pPmObj_t *r_pint);
 
 /**
- * Implement the UNARY_NEGATIVE bcode.
+ * Implements the UNARY_NEGATIVE bcode.
  *
- * Create a new int with a value that is
- * the negative of the given int.
+ * Creates a new int with a value that is the negative of the given int.
  *
  * @param   pobj Pointer to target object
  * @param   r_pint Return by ref, ptr to int
 PmReturn_t int_negative(pPmObj_t pobj, pPmObj_t *r_pint);
 
 /**
- * Implement the UNARY_INVERT bcode.
+ * Implements the UNARY_INVERT bcode.
  *
- * Create a new int with a value that is
+ * Creates a new int with a value that is
  * the bitwise inversion of the given int.
  *
  * @param   pobj Pointer to target object

File src/vm/interp.c

View file
  • Ignore whitespace
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x09
+
 /**
  * VM Interpreter
  *
 
 
 /***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
  * Macros
  **************************************************************/
 
 
 
 /***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
  * Prototypes
  **************************************************************/
 
     int8_t t8 = 0;
     uint8_t bc;
 
-    /* activate a thread the first time */
+    /* Activate a thread the first time */
     retval = interp_reschedule();
     PM_RETURN_IF_ERROR(retval);
 
-    /* interpret loop */
+    /* Interpret loop */
     while (1)
     {
         if (gVmGlobal.pthread == C_NULL)
         {
             if (returnOnNoThreads)
             {
-                /* user chose to return on no threads left */
+                /* User chose to return on no threads left */
                 return retval;
             }
-            /* without a frame there is nothing to execute, so reschedule
-             * (possibly activating a recently added thread). */
+
+            /*
+             * Without a frame there is nothing to execute, so reschedule
+             * (possibly activating a recently added thread).
+             */
             retval = interp_reschedule();
             PM_BREAK_IF_ERROR(retval);
             continue;
         }
 
-        /* Time for switching threads? */
+        /* Reschedule threads if flag is true?*/
         if (gVmGlobal.reschedule)
         {
             retval = interp_reschedule();
             PM_BREAK_IF_ERROR(retval);
         }
 
-        /* get byte; the func post-incrs IP */
+        /* Get byte; the func post-incrs IP */
         bc = mem_getByte(MS, &IP);
         switch (bc)
         {
-            case STOP_CODE:
-                /* SystemError, unknown opcode */
-                PM_RAISE(retval, PM_RET_EX_SYS);
-                break;
-
             case POP_TOP:
                 pobj1 = PM_POP();
                 continue;
                 TOS1 = TOS2;
                 TOS2 = TOS3;
                 TOS3 = pobj1;
-                /* Fallthrough */
+                continue;
 
             case NOP:
                 continue;
 
             case UNARY_POSITIVE:
-                /* TypeError if TOS is not an int */
+                /* Raise TypeError if TOS is not an int */
                 if (OBJ_GET_TYPE(*TOS) != OBJ_TYPE_INT)
                 {
                     PM_RAISE(retval, PM_RET_EX_TYPE);
                     break;
                 }
-                /* when TOS is an int, this is a no-op */
+
+                /* When TOS is an int, this is a no-op */
                 continue;
 
             case UNARY_NEGATIVE:
                 }
                 continue;
 
-            case UNARY_CONVERT:
-                /* SystemError, unknown opcode */
-                PM_RAISE(retval, PM_RET_EX_SYS);
-                break;
-
             case UNARY_INVERT:
-                /* TypeError if it's not an int */
+                /* Raise TypeError if it's not an int */
                 if (OBJ_GET_TYPE(*TOS) != OBJ_TYPE_INT)
                 {
                     PM_RAISE(retval, PM_RET_EX_TYPE);
                     break;
                 }
-                /* else perform bit-wise complement */
+
+                /* Otherwise perform bit-wise complement */
                 pobj1 = PM_POP();
                 retval = int_bitInvert(pobj1, &pobj2);
                 PM_BREAK_IF_ERROR(retval);
                 else if ((OBJ_GET_TYPE(*TOS) == OBJ_TYPE_INT)
                          && (OBJ_GET_TYPE(*TOS1) == OBJ_TYPE_LST))
                 {
-                    /* int number of times to duplicate */
+                    /* Int number of times to duplicate */
                     pobj1 = PM_POP();
                     if (OBJ_GET_TYPE(*pobj1) != OBJ_TYPE_INT)
                     {
                     }
                     t16 = (int16_t)((pPmInt_t)pobj1)->val;
 
-                    /* list that is copied */
+                    /* List that is copied */
                     pobj2 = PM_POP();
                     retval = list_replicate(pobj2, t16, &pobj3);
                     PM_BREAK_IF_ERROR(retval);
             case BINARY_SUBSCR:
                 /* Implements TOS = TOS1[TOS]. */
 
-                /* get index */
+                /* Get index */
                 pobj1 = PM_POP();
-                /* get sequence */
+
+                /* Get sequence */
                 pobj2 = PM_POP();
 
                 if (OBJ_GET_TYPE(*pobj2) == OBJ_TYPE_DIC)
                         break;
                     }
 
+                    /* Ensure the index doesn't overflow */
                     C_ASSERT(((pPmInt_t)pobj1)->val <= 0x0000FFFF);
                     t16 = (int16_t)((pPmInt_t)pobj1)->val;
+
                     retval = seq_getSubscript(pobj2, t16, &pobj3);
                 }
                 PM_BREAK_IF_ERROR(retval);
                 continue;
 
             case SLICE_0:
-                /*
-                 * Implements TOS = TOS[:],
-                 * push a copy of the sequence
-                 */
+                /* Implements TOS = TOS[:], push a copy of the sequence */
 
-                /* get sequence */
+                /* Get sequence */
                 pobj1 = PM_POP();
 
-                /* if it's a string */
+                /* If it's a string */
                 if (OBJ_GET_TYPE(*pobj1) == OBJ_TYPE_STR)
                 {
                     /* Just copy the pointer, since Strings are immutable */
                     pobj2 = pobj1;
                 }
 
-                /* if it's a tuple */
+                /* If it's a tuple */
                 else if (OBJ_GET_TYPE(*pobj1) == OBJ_TYPE_TUP)
                 {
                     retval = tuple_copy(pobj1, &pobj2);
                     PM_BREAK_IF_ERROR(retval);
                 }
 
-                /* if it's a list */
+                /* If it's a list */
                 else if (OBJ_GET_TYPE(*pobj1) == OBJ_TYPE_LST)
                 {
                     retval = list_copy(pobj1, &pobj2);
                 PM_PUSH(pobj2);
                 continue;
 
-            case SLICE_1:
-            case SLICE_2:
-            case SLICE_3:
-            case STORE_SLICE_0:
-            case STORE_SLICE_1:
-            case STORE_SLICE_2:
-            case STORE_SLICE_3:
-            case DELETE_SLICE_0:
-            case DELETE_SLICE_1:
-            case DELETE_SLICE_2:
-            case DELETE_SLICE_3:
-                /* SystemError, unknown opcode */
-                PM_RAISE(retval, PM_RET_EX_SYS);
-                break;
-
             case STORE_SUBSCR:
-                /* implements TOS1[TOS] = TOS2 */
+                /* Implements TOS1[TOS] = TOS2 */
                 pobj1 = PM_POP();
                 pobj2 = PM_POP();
                 pobj3 = PM_POP();
 
-                /* if it's a list */
+                /* If it's a list */
                 if (OBJ_GET_TYPE(*pobj2) == OBJ_TYPE_LST)
                 {
-                    /* ensure subscr is an int */
+                    /* Ensure subscr is an int */
                     if (OBJ_GET_TYPE(*pobj1) != OBJ_TYPE_INT)
                     {
                         PM_RAISE(retval, PM_RET_EX_TYPE);
                         break;
                     }
-                    /* set the list item */
+                    /* Set the list item */
                     retval = list_setItem(pobj2,
                                           (int16_t)(((pPmInt_t)pobj1)->val),
                                           pobj3);
                     continue;
                 }
 
-                /* if it's a dict */
+                /* If it's a dict */
                 if (OBJ_GET_TYPE(*pobj2) == OBJ_TYPE_DIC)
                 {
-                    /* set the dict item */
+                    /* Set the dict item */
                     retval = dict_setItem(pobj2, pobj1, pobj3);
                     PM_BREAK_IF_ERROR(retval);
                     continue;
                 PM_RAISE(retval, PM_RET_EX_TYPE);
                 break;
 
-            case DELETE_SUBSCR:
-                /* SystemError, unknown opcode */
-                PM_RAISE(retval, PM_RET_EX_SYS);
-                break;
-
             case BINARY_LSHIFT:
             case INPLACE_LSHIFT:
                 /* If both objs are ints, perform the op */
                 {
                     continue;
                 }
-                /* If bytecode is PRINT_EXPR, fallthrough to print a newline */
+                /* If PRINT_EXPR, Fallthrough to print a newline */
 
             case PRINT_NEWLINE:
                 retval = plat_putByte('\n');
                 PM_BREAK_IF_ERROR(retval);
                 continue;
-
-            case PRINT_ITEM_TO:
-            case PRINT_NEWLINE_TO:
-                /* SystemError, unknown opcode */
-                PM_RAISE(retval, PM_RET_EX_SYS);
-                break;
 #endif /* HAVE_PRINT */
 
             case BREAK_LOOP:
             {
                 pPmBlock_t pb1 = FP->fo_blockstack;
 
-                /* ensure there's a block */
+                /* Ensure there's a block */
                 C_ASSERT(pb1 != C_NULL);
 
-                /* delete blocks until first loop block */
+                /* Delete blocks until first loop block */
                 while ((pb1->b_type != B_LOOP) && (pb1->next != C_NULL))
                 {
                     pobj2 = (pPmObj_t)pb1;
                     retval = heap_freeChunk(pobj2);
                     PM_BREAK_IF_ERROR(retval);
                 }
+
                 /* Test again outside while loop */
                 PM_BREAK_IF_ERROR(retval);
 
-                /* restore SP */
+                /* Restore SP */
                 SP = pb1->b_sp;
-                /* goto handler */
+
+                /* Goto handler */
                 IP = pb1->b_handler;
-                /* pop and delete this block */
+
+                /* Pop and delete this block */
                 FP->fo_blockstack = pb1->next;
                 retval = heap_freeChunk((pPmObj_t)pb1);
                 PM_BREAK_IF_ERROR(retval);
                 continue;
 
             case LOAD_LOCALS:
-                /* pushes local attrs dict of current frame */
-                /* XXX does not copy fo_locals to attrs */
+                /* Pushes local attrs dict of current frame */
+                /* WARNING: does not copy fo_locals to attrs */
                 PM_PUSH((pPmObj_t)FP->fo_attrs);
                 continue;
 
             case RETURN_VALUE:
-                /* XXX error check: stack should be empty */
-                /* get expiring frame's TOS */
+                /* TODO #109: Check that stack should have only 1 item */
+                /* Get expiring frame's TOS */
                 pobj2 = PM_POP();
-                /* keep ref of expiring frame */
+
+                /* Keep ref of expiring frame */
                 pobj1 = (pPmObj_t)FP;
-                /* if no previous frame, quit thread */