@@ -7,11 +7,12 @@
 
 namespace IronPython.Runtime {
     internal class PythonByteCode {
-        public const int CO_MAXBLOCKS = 20; // same as in CPython
+        public const int CO_MAXBLOCKS = 20; // same as in CPython (Include/code.h)
         private const int CALL_FLAG_VAR = 1;
         private const int CALL_FLAG_KW = 2;
 
         enum Opcode {
+            STOP_CODE = 0,
             POP_TOP = 1,
             ROT_TWO = 2,
             ROT_THREE = 3,
@@ -23,7 +24,7 @@ enum Opcode {
             UNARY_NOT = 12,
             UNARY_CONVERT = 13,
             UNARY_INVERT = 15,
-            LIST_APPEND = 18,
+
             BINARY_POWER = 19,
             BINARY_MULTIPLY = 20,
             BINARY_DIVIDE = 21,
@@ -35,12 +36,10 @@ enum Opcode {
             BINARY_TRUE_DIVIDE = 27,
             INPLACE_FLOOR_DIVIDE = 28,
             INPLACE_TRUE_DIVIDE = 29,
-            SLICE = 30,
-            /* Also uses 31-33 */
-            STORE_SLICE = 40,
-            /* Also uses 41-43 */
-            DELETE_SLICE = 50,
-            /* Also uses 51-53 */
+            SLICE = 30, /* Also uses 31-33 */
+            STORE_SLICE = 40, /* Also uses 41-43 */
+            DELETE_SLICE = 50, /* Also uses 51-53 */
+            STORE_MAP = 54,             
             INPLACE_ADD = 55,
             INPLACE_SUBTRACT = 56,
             INPLACE_MULTIPLY = 57,
@@ -84,6 +83,9 @@ enum Opcode {
             UNPACK_SEQUENCE = 92,	/* Number of sequence items */
 
             FOR_ITER = 93,
+
+            LIST_APPEND	= 94,
+
             STORE_ATTR = 95,	/* Index in name list */
 
             DELETE_ATTR = 96,	/* "" */
@@ -102,23 +104,28 @@ enum Opcode {
 
             BUILD_LIST = 103,	/* Number of list items */
 
-            BUILD_MAP = 104,	/* Always zero for now */
+            BUILD_SET = 104, /* Number of set items */
 
-            LOAD_ATTR = 105,	/* Index in name list */
+            BUILD_MAP = 105,	/* Always zero for now */
 
-            COMPARE_OP = 106,	/* Comparison operator */
+            LOAD_ATTR = 106,	/* Index in name list */
 
-            IMPORT_NAME = 107,	/* Index in name list */
+            COMPARE_OP = 107,	/* Comparison operator */
 
-            IMPORT_FROM = 108,	/* Index in name list */
+            IMPORT_NAME = 108,	/* Index in name list */
+
+            IMPORT_FROM = 109,	/* Index in name list */
 
             JUMP_FORWARD = 110,	/* Number of bytes to skip */
 
-            JUMP_IF_FALSE = 111,	/* "" */
+            JUMP_IF_FALSE_OR_POP = 111,	/* "" */
+
+            JUMP_IF_TRUE_OR_POP = 112,	/* "" */
 
-            JUMP_IF_TRUE = 112,	/* "" */
+            JUMP_ABSOLUTE = 113,    /* Target byte offset from beginning of code */
 
-            JUMP_ABSOLUTE = 113,	/* Target byte offset from beginning of code */
+            POP_JUMP_IF_FALSE = 114,	/* "" */
+            POP_JUMP_IF_TRUE = 115,	/* "" */
 
             LOAD_GLOBAL = 116,	/* Index in name list */
 
@@ -161,8 +168,29 @@ enum Opcode {
 
             CALL_FUNCTION_VAR_KW = 142,	/* #args + (#kwargs<<8) */
 
+            SETUP_WITH = 143, 
+            
             /* Support for opargs more than 16 bits long */
-            EXTENDED_ARG = 143,
+            EXTENDED_ARG = 145,
+
+            SET_ADD = 146,
+            MAP_ADD = 147,
+        }
+
+        /* Rich comparison opcodes */
+        enum cmp_op {
+            PyCmp_LT = 0, // Py_LT
+            PyCmp_LE = 1, // Py_LE
+            PyCmp_EQ = 2, // Py_EQ
+            PyCmp_NE = 3, // Py_NE
+            PyCmp_GT = 4, // Py_GT
+            PyCmp_GE = 5, // Py_GE
+            PyCmp_IN,
+            PyCmp_NOT_IN,
+            PyCmp_IS,
+            PyCmp_IS_NOT,
+            PyCmp_EXC_MATCH,
+            PyCmp_BAD
         }
 
         public PythonByteCode (int argcount, int nlocals, int stacksize, int flags,
@@ -172,6 +200,7 @@ enum Opcode {
 
             co_code = PythonAsciiEncoding.ASCII.GetBytes (code);
             co_consts = constants;
+            co_varnames = varnames;
         }
 
         public object Interpret (ModuleContext context) {
@@ -189,412 +218,519 @@ enum Opcode {
                 next_instr += 1;
 
                 switch ((Opcode)opcode) {
-                    case Opcode.NOP:
+                    case Opcode.STOP_CODE: // Indicates end-of-code to the compiler, not used by the interpreter.
                         break;
 
-                    case Opcode.LOAD_FAST:
+                    case Opcode.NOP: // Do nothing code. Used as a placeholder by the bytecode optimizer
                         break;
 
-                    case Opcode.LOAD_CONST:
+                    case Opcode.LOAD_FAST:  // Pushes a reference to the local co_varnames[var_num] onto the stack.
+                        throw new NotImplementedException("LOAD_FAST");
+                        break;
+
+                    case Opcode.LOAD_CONST: // Pushes co_consts[consti] onto the stack.
                         stack.Push (co_consts[oparg]);
                         break;
 
-                    case Opcode.STORE_FAST:
+                    case Opcode.STORE_FAST: // Stores TOS into the local co_varnames[var_num]
+                        throw new NotImplementedException("STORE_FAST");
                         break;
 
-                    case Opcode.POP_TOP:
+                    case Opcode.POP_TOP: // Removes the top-of-stack (TOS) item.
                         stack.Pop ();
                         break;
 
-                    case Opcode.ROT_TWO:
+                    case Opcode.ROT_TWO: // Swaps the two top-most stack items.
+                        {
+                            object a = stack.Pop();
+                            object b = stack.Pop();
+                            stack.Push(a);
+                            stack.Push(b);
+                        } 
                         break;
 
-                    case Opcode.ROT_THREE:
+                    case Opcode.ROT_THREE: // Lifts second and third stack item one position up, moves top down to position three.
+                        {
+                            object v = stack.Pop();
+                            object w = stack.Pop();
+                            object x = stack.Pop();
+                            stack.Push(w);
+                            stack.Push(x);
+                            stack.Push(v);                            
+                        }
                         break;
 
-                    case Opcode.ROT_FOUR:
+                    case Opcode.ROT_FOUR: // Lifts second, third and forth stack item one position up, moves top down to position four.
+                        {
+                            object u = stack.Pop();
+                            object v = stack.Pop();
+                            object w = stack.Pop();
+                            object x = stack.Pop();
+                            stack.Push(u);
+                            stack.Push(x);
+                            stack.Push(w);
+                            stack.Push(v);
+                        }
                         break;
 
-                    case Opcode.DUP_TOP:
+                    case Opcode.DUP_TOP: // Duplicates the reference on top of the stack.
+                        stack.Push(stack.Peek());
                         break;
 
-                    case Opcode.DUP_TOPX:
+                    case Opcode.DUP_TOPX/*(count)*/: // Duplicate count items, keeping them in the same order.Due to implementation limits, count should be between 1 and 5 inclusive.
                         if (oparg == 2 || oparg == 3) {
-
+                            for(int i = 0; i < oparg; i++) {
+                                stack.Push(stack.Peek());
+                            }    
                         } else {
                             throw PythonOps.RuntimeError ("invalid argument to DUP_TOPX (bytecode corruption?)");
                         }
                         break;
 
-                    case Opcode.UNARY_POSITIVE:
-
+                    // Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.
+                    case Opcode.UNARY_POSITIVE: // Implements TOS = +TOS.
+                        throw new NotImplementedException("UNARY_POSITIVE");
                         break;
 
-                    case Opcode.UNARY_NEGATIVE:
+                    case Opcode.UNARY_NEGATIVE: // Implements TOS = -TOS.
+                        throw new NotImplementedException("UNARY_NEGATIVE");
                         break;
 
-                    case Opcode.UNARY_NOT:
+                    case Opcode.UNARY_NOT: // Implements TOS = not TOS.
+                        throw new NotImplementedException("UNARY_NOT");
                         break;
 
-                    case Opcode.UNARY_CONVERT:
+                    case Opcode.UNARY_CONVERT: // Implements TOS = `TOS`.
+                        throw new NotImplementedException("UNARY_CONVERT");
                         break;
 
-                    case Opcode.UNARY_INVERT:
+                    case Opcode.UNARY_INVERT: // Implements TOS = ~TOS.
+                        throw new NotImplementedException("UNARY_INVERT");
                         break;
 
-                    case Opcode.BINARY_POWER:
+                    // Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.
+                    case Opcode.BINARY_POWER: // Implements TOS = TOS1 ** TOS.
+                        throw new NotImplementedException("BINARY_POWER");
                         break;
 
-                    case Opcode.BINARY_MULTIPLY:
+                    case Opcode.BINARY_MULTIPLY: // Implements TOS = TOS1 * TOS.
+                        throw new NotImplementedException("BINARY_MULTIPLE");
                         break;
 
-                    case Opcode.BINARY_DIVIDE:
+                    case Opcode.BINARY_DIVIDE: // Implements TOS = TOS1 / TOS when from __future__ import division is not in effect.
+                        throw new NotImplementedException("BINARY_DIVIDE");
                         break;
 
-                    case Opcode.BINARY_TRUE_DIVIDE:
+                    case Opcode.BINARY_TRUE_DIVIDE: // Implements TOS = TOS1 / TOS when from __future__ import division is in effect.
+                        throw new NotImplementedException("BINARY_TRUE_DIVIDE");
                         break;
 
-                    case Opcode.BINARY_FLOOR_DIVIDE:
+                    case Opcode.BINARY_FLOOR_DIVIDE: // Implements TOS = TOS1 // TOS.
+                        throw new NotImplementedException("BINARY_FLOOR_DIVIDE");
                         break;
 
-                    case Opcode.BINARY_MODULO:
+                    case Opcode.BINARY_MODULO: // Implements TOS = TOS1 % TOS.
+                        throw new NotImplementedException("BINARY_MODULO");
                         break;
 
-                    case Opcode.BINARY_ADD:
+                    case Opcode.BINARY_ADD: // Implements TOS = TOS1 + TOS.
+                        throw new NotImplementedException("BINARY_ADD");
                         break;
 
-                    case Opcode.BINARY_SUBTRACT:
+                    case Opcode.BINARY_SUBTRACT: // Implements TOS = TOS1 - TOS.
+                        throw new NotImplementedException("BINARY_SUBTRACT");
                         break;
 
-                    case Opcode.BINARY_SUBSCR:
+                    case Opcode.BINARY_SUBSCR: // Implements TOS = TOS1[TOS].
+                        throw new NotImplementedException("BINARY_SUBSCR");
                         break;
 
-                    case Opcode.BINARY_LSHIFT:
+                    case Opcode.BINARY_LSHIFT: // Implements TOS = TOS1 << TOS.
+                        throw new NotImplementedException("BINARY_LSHIFT");
                         break;
 
-                    case Opcode.BINARY_RSHIFT:
+                    case Opcode.BINARY_RSHIFT: // Implements TOS = TOS1 >> TOS.
+                        throw new NotImplementedException("BINARY_RSHIFT");
                         break;
 
-                    case Opcode.BINARY_AND:
+                    case Opcode.BINARY_AND: // Implements TOS = TOS1 & TOS.
+                        throw new NotImplementedException("BINARY_AND");
                         break;
 
-                    case Opcode.BINARY_XOR:
+                    case Opcode.BINARY_XOR: // Implements TOS = TOS1 ^ TOS.
+                        throw new NotImplementedException("BINARY_XOR");
                         break;
 
-                    case Opcode.BINARY_OR:{
-                        //object b = stack.Pop();
-                        //object a = stack.Pop();
-                        //stack.Push(a._or(b));
+                    case Opcode.BINARY_OR: // Implements TOS = TOS1 | TOS.
+                        throw new NotImplementedException("BINARY_OR");
                         break;
-                    }
 
-                    case Opcode.LIST_APPEND: {
-                        object b = stack.Pop ();
-                        List a = stack.Pop () as List;
-                        a.append (b);
+                    case Opcode.LIST_APPEND/*(i)*/:  // Calls list.append(TOS[-i], TOS). Used to implement list comprehensions. While the appended value is popped off, the list object remains on the stack so that it is available for further iterations of the loop.
+                        {
+                            object b = stack.Pop();
+                            List a = stack.Pop() as List;
+                            a.append(b);
+                            stack.Push(a);
+                        }
                         break;
-                    }
 
-                    case Opcode.INPLACE_POWER:
+                    case Opcode.INPLACE_POWER: // Implements in-place TOS = TOS1 ** TOS.
+                        throw new NotImplementedException("INPLACE_POWER");
                         break;
 
-                    case Opcode.INPLACE_MULTIPLY:
+                    case Opcode.INPLACE_MULTIPLY: // Implements in-place TOS = TOS1 * TOS.
+                        throw new NotImplementedException("INPLACE_MULTIPLE");
                         break;
 
-                    case Opcode.INPLACE_DIVIDE:
+                    case Opcode.INPLACE_DIVIDE: // Implements in-place TOS = TOS1 / TOS when from __future__ import division is not in effect.
+                        throw new NotImplementedException("INPLACE_DIVIDE");
                         break;
 
-                    case Opcode.INPLACE_TRUE_DIVIDE:
+                    case Opcode.INPLACE_TRUE_DIVIDE: // Implements in-place TOS = TOS1 / TOS when from __future__ import division is in effect.
+                        throw new NotImplementedException("INPLACE_TRUE_DIVIDE");
                         break;
 
-                    case Opcode.INPLACE_FLOOR_DIVIDE:
+                    case Opcode.INPLACE_FLOOR_DIVIDE: // Implements in-place TOS = TOS1 // TOS.
+                        throw new NotImplementedException("INPLACE_FLOOR_DIVIDE");
                         break;
 
-                    case Opcode.INPLACE_MODULO:
+                    case Opcode.INPLACE_MODULO: // Implements in-place TOS = TOS1 % TOS.
+                        throw new NotImplementedException("INPLACE_MODULO");
                         break;
 
-                    case Opcode.INPLACE_ADD:
+                    case Opcode.INPLACE_ADD: // Implements in-place TOS = TOS1 + TOS.
+                        throw new NotImplementedException("INPLACE_ADD");
                         break;
 
-                    case Opcode.INPLACE_SUBTRACT:
+                    case Opcode.INPLACE_SUBTRACT: // Implements in-place TOS = TOS1 - TOS.
+                        throw new NotImplementedException("INPLACE_SUBTRACT");
                         break;
 
-                    case Opcode.INPLACE_LSHIFT:
+                    case Opcode.INPLACE_LSHIFT: // Implements in-place TOS = TOS1 << TOS.
+                        throw new NotImplementedException("INPLACE_LSHIFT");
                         break;
 
-                    case Opcode.INPLACE_RSHIFT:
+                    case Opcode.INPLACE_RSHIFT: // Implements in-place TOS = TOS1 >> TOS.
+                        throw new NotImplementedException("INPLACE_RSHIFT");
                         break;
 
-                    case Opcode.INPLACE_AND:
+                    case Opcode.INPLACE_AND: // Implements in-place TOS = TOS1 & TOS.
+                        throw new NotImplementedException("INPLACE_AND");
                         break;
 
-                    case Opcode.INPLACE_XOR:
+                    case Opcode.INPLACE_XOR: // Implements in-place TOS = TOS1 ^ TOS.
+                        throw new NotImplementedException("INPLACE_XOR");
                         break;
 
-                    case Opcode.INPLACE_OR:
+                    case Opcode.INPLACE_OR: // Implements in-place TOS = TOS1 | TOS.
+                        throw new NotImplementedException("INPLACE_OR");
                         break;
 
-                    case Opcode.SLICE + 0:
-                    case Opcode.SLICE + 1:
-                    case Opcode.SLICE + 2:
-                    case Opcode.SLICE + 3: {
-                        //object stop = (((opcode - (int)Opcode.SLICE) & 2) != 0) ? stack.Pop () : null;
-                        //object start = (((opcode - (int)Opcode.SLICE) & 1) != 0) ? stack.Pop () : null;
-                        //object obj = stack.Pop ();
-                        //stack.Push (obj.__getslice__ (start, stop));
+                    // The slice opcodes take up to three parameters.
+                    case Opcode.SLICE + 0: // Implements TOS = TOS[:].
+                    case Opcode.SLICE + 1: // Implements TOS = TOS1[TOS:].
+                    case Opcode.SLICE + 2: // Implements TOS = TOS1[:TOS].
+                    case Opcode.SLICE + 3: // Implements TOS = TOS2[TOS1: TOS].
+                        throw new NotImplementedException("SLICE");
                         break;
-                    }
 
-                    case Opcode.STORE_SLICE + 0:
-                    case Opcode.STORE_SLICE + 1:
-                    case Opcode.STORE_SLICE + 2:
-                    case Opcode.STORE_SLICE + 3:
+                    // Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.
+                    case Opcode.STORE_SLICE + 0: // Implements TOS[:] = TOS1.
+                    case Opcode.STORE_SLICE + 1: // Implements TOS1[TOS:] = TOS2.
+                    case Opcode.STORE_SLICE + 2: // Implements TOS1[:TOS] = TOS2.
+                    case Opcode.STORE_SLICE + 3: // Implements TOS2[TOS1:TOS] = TOS3.
+                        throw new NotImplementedException("STORE_SLICE");
                         break;
 
-                    case Opcode.DELETE_SLICE + 0:
-                    case Opcode.DELETE_SLICE + 1:
-                    case Opcode.DELETE_SLICE + 2:
-                    case Opcode.DELETE_SLICE + 3:
+                    case Opcode.DELETE_SLICE + 0: // Implements del TOS[:].
+                    case Opcode.DELETE_SLICE + 1: // Implements del TOS1[TOS:].
+                    case Opcode.DELETE_SLICE + 2: // Implements del TOS1[:TOS].
+                    case Opcode.DELETE_SLICE + 3: // Implements del TOS2[TOS1:TOS].
+                        throw new NotImplementedException("DELETE_SLICE");
                         break;
 
-                    case Opcode.STORE_SUBSCR: {
-                            object key = stack.Pop ();
-                            object obj = stack.Pop ();
-                            object value = stack.Pop ();
-                            PythonOps.Invoke (context.GlobalContext, obj, "__setitem__", key, value);
-                            break;
+                    case Opcode.STORE_SUBSCR:  // Implements TOS1[TOS] = TOS2.
+                        {
+                            object key = stack.Pop();
+                            object obj = stack.Pop();
+                            object value = stack.Pop();
+                            PythonOps.Invoke(context.GlobalContext, obj, "__setitem__", key, value);
                         }
-
-                    case Opcode.DELETE_SUBSCR: {
-                            object key = stack.Pop ();
-                            object obj = stack.Pop ();
-                            PythonOps.Invoke (context.GlobalContext, obj, "__delitem__", key);
-                            break;
+                        break;
+                        
+                    case Opcode.DELETE_SUBSCR: // Implements del TOS1[TOS].
+                        {
+                            object key = stack.Pop();
+                            object obj = stack.Pop();
+                            PythonOps.Invoke(context.GlobalContext, obj, "__delitem__", key);
                         }
+                        break;
+                        
 
-                    case Opcode.PRINT_EXPR:
+                    case Opcode.PRINT_EXPR: // Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_TOP.
+                        throw new NotImplementedException("PRINT_EXPR");
                         break;
 
-                    case Opcode.PRINT_ITEM_TO:
+                    case Opcode.PRINT_ITEM_TO: // Like PRINT_ITEM, but prints the item second from TOS to the file - like object at TOS.This is used by the extended print statement.
                         PythonOps.PrintCommaWithDest (context.GlobalContext, stack.Pop (), stack.Pop ());
                         break;
 
-                    case Opcode.PRINT_ITEM:
+                    case Opcode.PRINT_ITEM: // Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.
                         PythonOps.Print (context.GlobalContext, stack.Pop ());
                         break;
-
-                    case Opcode.PRINT_NEWLINE_TO:
+                         
+                    case Opcode.PRINT_NEWLINE_TO: // Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.
                         PythonOps.PrintNewlineWithDest (context.GlobalContext, stack.Pop ());
                         break;
 
-                    case Opcode.PRINT_NEWLINE:
+                    case Opcode.PRINT_NEWLINE: // Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.
                         PythonOps.PrintNewline (context.GlobalContext);
                         break;
 
-                    case Opcode.RAISE_VARARGS:
+                    case Opcode.RAISE_VARARGS/*(argc)*/: // Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.
+                        throw new NotImplementedException("RAISE_VARARGS");
                         break;
 
-                    case Opcode.LOAD_LOCALS:
-
+                    case Opcode.LOAD_LOCALS: // Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.
+                        throw new NotImplementedException("LOAD_LOCALS");
                         break;
 
-                    case Opcode.RETURN_VALUE:
+                    case Opcode.RETURN_VALUE: // Returns with TOS to the caller of the function.
                         retval = stack.Pop ();
                         break;
 
-                    case Opcode.YIELD_VALUE:
+                    case Opcode.YIELD_VALUE: // Pops TOS and yields it from a generator.
+                        throw new NotImplementedException("YIELD_VALUE");
                         break;
 
-                    case Opcode.EXEC_STMT:
+                    case Opcode.EXEC_STMT: // Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.
+                        throw new NotImplementedException("EXEC_STMT");
                         break;
 
-                    case Opcode.POP_BLOCK:
+                    case Opcode.POP_BLOCK: // Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.
+                        throw new NotImplementedException("POP_BLOCK");
                         break;
 
-                    case Opcode.END_FINALLY:
+                    case Opcode.END_FINALLY: // Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.
+                        throw new NotImplementedException("END_FINALLY");
                         break;
 
-                    case Opcode.BUILD_CLASS:
+                    case Opcode.BUILD_CLASS: // Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.
+                        throw new NotImplementedException("BUILD_CLASS");
                         break;
 
-                    case Opcode.STORE_NAME:
+                    case Opcode.STORE_NAME/*(namei)*/: // Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_FAST or STORE_GLOBAL if possible.
                         PythonOps.SetLocal (context.GlobalContext, co_names[oparg], stack.Pop ());
                         break;
 
-                    case Opcode.DELETE_NAME:
+                    case Opcode.DELETE_NAME/*(namei)*/: // Implements del name, where namei is the index into co_names attribute of the code object.
                         PythonOps.DeleteLocal (context.GlobalContext, co_names[oparg]);
                         break;
 
-                    case Opcode.UNPACK_SEQUENCE:
+                    case Opcode.UNPACK_SEQUENCE/*(count)*/: // Unpacks TOS into count individual values, which are put onto the stack right-to-left.
+                        throw new NotImplementedException("UNPACK_SEQUENCE");
                         break;
 
-                    case Opcode.STORE_ATTR: {
-                            object obj = stack.Pop ();
-                            object v = stack.Pop ();
-                            PythonOps.SetAttr (context.GlobalContext, obj, co_names[oparg], v);
-                            break;
+                    case Opcode.STORE_ATTR/*(namei)*/: // Implements TOS.name = TOS1, where namei is the index of name in co_names.
+                        {
+                            object obj = stack.Pop();
+                            object v = stack.Pop();
+                            PythonOps.SetAttr(context.GlobalContext, obj, co_names[oparg], v);
                         }
-
-                    case Opcode.DELETE_ATTR:
+                        break;
+                        
+                    case Opcode.DELETE_ATTR/*(namei)*/: // Implements del TOS.name, using namei as index into co_names.
                         PythonOps.DeleteAttr (context.GlobalContext, stack.Pop (), co_names[oparg]);
                         break;
 
-                    case Opcode.STORE_GLOBAL:
+                    case Opcode.STORE_GLOBAL/*(namei)*/: // Works as STORE_NAME, but stores the name as a global.
                         PythonOps.SetGlobal (context.GlobalContext, co_names[oparg], stack.Pop ());
                         break;
 
-                    case Opcode.DELETE_GLOBAL:
+                    case Opcode.DELETE_GLOBAL/*(namei)*/: // Works as DELETE_NAME, but deletes a global name.
                         PythonOps.DeleteGlobal (context.GlobalContext, co_names[oparg]);
                         break;
 
-                    case Opcode.LOAD_NAME:
+                    case Opcode.LOAD_NAME/*(namei)*/: // Pushes the value associated with co_names[namei] onto the stack.
                         PythonOps.GetLocal (context.GlobalContext, co_names[oparg]);
                         break;
 
-                    case Opcode.LOAD_GLOBAL:
+                    case Opcode.LOAD_GLOBAL/*(namei)*/: // Loads the global named co_names[namei] onto the stack.
                         stack.Push (PythonOps.GetGlobal (context.GlobalContext, co_names[oparg]));
                         break;
 
-                    case Opcode.DELETE_FAST:
+                    case Opcode.DELETE_FAST/*(var_num)*/: // Deletes local co_varnames[var_num].
+                        throw new NotImplementedException("DELETE_FAST");
                         break;
 
-                    case Opcode.LOAD_CLOSURE:
+                    case Opcode.LOAD_CLOSURE/*(i)*/: // Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].
+                        throw new NotImplementedException("LOAD_CLOSURE");
                         break;
 
-                    case Opcode.LOAD_DEREF:
+                    case Opcode.LOAD_DEREF/*(i)*/: // Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.
+                        throw new NotImplementedException("LOAD_DEREF");
                         break;
 
-                    case Opcode.STORE_DEREF:
+                    case Opcode.STORE_DEREF/*(i)*/: // Stores TOS into the cell contained in slot i of the cell and free variable storage.
+                        throw new NotImplementedException("STORE_DEREF");
                         break;
 
-                    case Opcode.BUILD_TUPLE:
-                        //                        PythonTuple res = PythonOps.MakeTuple()
-                        for (int i = 0; i < oparg; i++) {
-                            //res.
+                    case Opcode.BUILD_TUPLE/*(count)*/: // Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.
+                        {
+                            List l = new List();
+                            for (int i = 0; i < oparg; i++) {
+                                l.Add(stack.Pop());
+                            }
+                            stack.Push(PythonOps.MakeTupleFromSequence(l));
+                        }
+                        break;
 
+                    case Opcode.BUILD_LIST/*(count)*/: // Works as BUILD_TUPLE, but creates a list. 
+                        {
+                            List l = new List();
+                            for (int i = 0; i < oparg; i++) {
+                                l.Add(stack.Pop());
+                            }
+                            stack.Push(l);
                         }
                         break;
 
-                    case Opcode.BUILD_LIST:
-                        List l = new List ();
-                        for (int i = 0; i < oparg; i++) {
-                            l.Add (stack.Pop ());
+                    case Opcode.BUILD_SET/*(count)*/: // Works as BUILD_TUPLE, but creates a set.
+                        {
+                            SetCollection s = PythonOps.MakeSet();
+                            for (int i = 0; i < oparg; i++) {
+                                s.add(stack.Pop());
+                            }
+                            stack.Push(s);                            
                         }
-                        stack.Push (l);
                         break;
 
-                    case Opcode.BUILD_MAP:
-                        stack.Push (new PythonDictionary ());
+                    case Opcode.BUILD_MAP/*(count)*/: // Pushes a new dictionary object onto the stack. The dictionary is pre-sized to hold count entries.
+                        stack.Push (new PythonDictionary (oparg));
                         break;
 
-                    case Opcode.LOAD_ATTR:
+                    case Opcode.LOAD_ATTR/*(namei)*/: // Replaces TOS with getattr(TOS, co_names[namei]).
                         stack.Push (PythonOps.ObjectGetAttribute (context.GlobalContext, stack.Pop (), co_names[oparg]));
                         break;
 
-                    case Opcode.COMPARE_OP:
+                    case Opcode.COMPARE_OP/*(opname)*/: // Performs a Boolean operation. The operation name can be found in cmp_op[opname].
+                        throw new NotImplementedException("COMPARE_OP");
                         break;
 
-                    case Opcode.IMPORT_NAME:
-
+                    case Opcode.IMPORT_NAME/*(namei)*/: // Imports the module co_names[namei]. TOS and TOS1 are popped and provide the fromlist and level arguments of __import__(). The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.
+                        throw new NotImplementedException("IMPORT_NAME");
                         break;
 
-                    case Opcode.IMPORT_STAR:
-
+                    case Opcode.IMPORT_STAR: // Loads all symbols not starting with '_' directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.
+                        throw new NotImplementedException("IMPORT_STAR");
                         break;
 
-                    case Opcode.IMPORT_FROM:
+                    case Opcode.IMPORT_FROM/*(namei)*/: // Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.
+                        throw new NotImplementedException("IMPORT_FROM");
                         break;
 
-                    case Opcode.JUMP_FORWARD:
+                    case Opcode.JUMP_FORWARD/*(delta)*/: // Increments bytecode counter by delta.
                         next_instr += oparg;
                         break;
 
-                    case Opcode.JUMP_IF_FALSE:
+                    case Opcode.JUMP_IF_FALSE_OR_POP/*(target)*/: // If TOS is false, sets the bytecode counter to target and leaves TOS on the stack. Otherwise (TOS is true), TOS is popped.
                         if (!PythonOps.CheckingConvertToNonZero (stack.Peek ())) {
                             next_instr += oparg;
+                        } else {
+                            stack.Pop();
                         }
                         break;
 
-                    case Opcode.JUMP_IF_TRUE:
+                    case Opcode.JUMP_IF_TRUE_OR_POP/*(target)*/: // If TOS is true, sets the bytecode counter to target and leaves TOS on the stack. Otherwise (TOS is false), TOS is popped.
                         if (PythonOps.CheckingConvertToNonZero (stack.Peek ())) {
                             next_instr += oparg;
+                        } else {
+                            stack.Pop();
                         }
                         break;
 
-                    case Opcode.JUMP_ABSOLUTE:
+                    case Opcode.JUMP_ABSOLUTE/*(target)*/: // Set bytecode counter to target.
                         next_instr = oparg;
                         break;
 
-                    case Opcode.GET_ITER:
-                        //                        object it = PythonOps.Istack.Peek().__iter__();
-                        //1002                        if (it != null) {
-                        //1003                            stack.set_top(it);
-                        //1004                        }
+                    case Opcode.GET_ITER: // Implements TOS = iter(TOS).
+                        stack.Push(PythonOps.GetEnumerator(stack.Pop()));
                         break;
 
-                    case Opcode.FOR_ITER:
+                    case Opcode.FOR_ITER/*(delta)*/: // TOS is an iterator. Call its next() method. If this yields a new value, push it on the stack (leaving the iterator below it). If the iterator indicates it is exhausted TOS is popped, and the bytecode counter is incremented by delta.
+                        {
+                            //object tos = stack.Peek();
+                            
+                            throw new NotImplementedException("FOR_ITER");
+                        }
                         break;
 
-                    case Opcode.BREAK_LOOP:
+                    case Opcode.BREAK_LOOP: // Terminates a loop due to a break statement.
+                        throw new NotImplementedException("BREAK_LOOP");
                         break;
 
-                    case Opcode.CONTINUE_LOOP:
+                    case Opcode.CONTINUE_LOOP/*(target)*/: // Continues a loop due to a continue statement. target is the address to jump to (which should be a FOR_ITER instruction).
+                        throw new NotImplementedException("CONTINUE_LOOP");
                         break;
 
-                    case Opcode.SETUP_LOOP:
-                    case Opcode.SETUP_EXCEPT:
-                    case Opcode.SETUP_FINALLY:
+                    case Opcode.SETUP_LOOP/*(delta)*/: // Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.
+                        throw new NotImplementedException("SETUP_LOOP");
+                    case Opcode.SETUP_EXCEPT/*(delta)*/: // Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.
+                        throw new NotImplementedException("SETUP_EXCEPT");
+                    case Opcode.SETUP_FINALLY/*(delta)*/: // Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.
+                        throw new NotImplementedException("SETUP_FINALLY");
                         break;
 
-                    case Opcode.WITH_CLEANUP:
-                        /* TOP is the context.__exit__ bound method.
-                        Below that are 1-3 values indicating how/why
-                        we entered the finally clause:
-                        - SECOND = None
-                        - (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval
-                        - SECOND = WHY_*; no retval below it
-                        - (SECOND, THIRD, FOURTH) = exc_info()
-                        In the last case, we must call
-                        TOP(SECOND, THIRD, FOURTH)
-                        otherwise we must call
-                        TOP(None, None, None)
+                    case Opcode.WITH_CLEANUP: // Cleans up the stack when a with statement block exits. On top of the stack are 1–3 values indicating how/why the finally clause was entered:
+                        /* 
+                        TOP = None
+                        (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval
+                        TOP = WHY_*; no retval below it
+                        (TOP, SECOND, THIRD) = exc_info()
+                        Under them is EXIT, the context manager’s __exit__() bound method.
+
+                        In the last case, EXIT(TOP, SECOND, THIRD) is called, otherwise EXIT(None, None, None).
 
-                        In addition, if the stack represents an exception,
-                         *and* the function call returns a 'true' value, we
-                        "zap" this information, to prevent END_FINALLY from
-                        re-raising the exception.  (But non-local gotos
-                        should still be resumed.)
-                         */
+                        EXIT is removed from the stack, leaving the values above it in the same order. In addition, if the stack represents an exception, and the function call returns a ‘true’ value, this information is “zapped”, to prevent END_FINALLY from re-raising the exception. (But non-local gotos should still be resumed.)
+                        */
+                        throw new NotImplementedException("WITH_CLEANUP");
                         break;
 
-                    case Opcode.CALL_FUNCTION:
+                    case Opcode.CALL_FUNCTION/*(argc)*/:  // Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack. Pops all function arguments, and the function itself off the stack, and pushes the return value.
+                        throw new NotImplementedException("CALL_FUNCTION");
                         break;
 
-                    case Opcode.CALL_FUNCTION_VAR:
-                    case Opcode.CALL_FUNCTION_KW:
-                    case Opcode.CALL_FUNCTION_VAR_KW:
+                    case Opcode.CALL_FUNCTION_VAR/*(argc)*/: // Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.
+                        throw new NotImplementedException("CALL_FUNCTION_VAR");
+                    case Opcode.CALL_FUNCTION_KW/*(argc)*/: // Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.
+                        throw new NotImplementedException("CALL_FUNCTION_KW");
+                    case Opcode.CALL_FUNCTION_VAR_KW/*(argc)*/: // Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.
+                        throw new NotImplementedException("CALL_FUNCTION_VAR_KW");
                         break;
 
-                    case Opcode.MAKE_FUNCTION:
+                    case Opcode.MAKE_FUNCTION/*(argc)*/: // Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.
+                        throw new NotImplementedException("MAKE_FUNCTION");
                         break;
 
-                    case Opcode.MAKE_CLOSURE:
+                    case Opcode.MAKE_CLOSURE/*(argc)*/: // Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function, TOS1 the tuple containing cells for the closure’s free variables. The function also has argc default parameters, which are found below the cells.
+                        throw new NotImplementedException("MAKE_CLOSURE");
                         break;
 
-                    case Opcode.BUILD_SLICE:
+                    case Opcode.BUILD_SLICE/*(argc)*/: // Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.
                         object step = (oparg == 3) ? stack.Pop () : null;
                         object stop = stack.Pop ();
                         object start = stack.Pop ();
                         stack.Push (PythonOps.MakeSlice (start, stop, step));
                         break;
 
-                    case Opcode.EXTENDED_ARG:
+                    case Opcode.EXTENDED_ARG/*(ext)*/: // Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode’s argument, comprise a four-byte argument, ext being the two most-significant bytes.
                         opcode = co_code[next_instr++];
                         next_instr += 2;
                         oparg = oparg << 16 | ((co_code[next_instr] << 8) + co_code[next_instr - 1]);
                         break;
 
                     default:
+                        // TODO: determine if we want to throw an exception here or something
                         break;
                 }
 
@@ -615,6 +751,11 @@ enum Opcode {
             private set;
         }
 
+        public PythonTuple co_varnames {
+            get;
+            private set;
+        }
+
         public string[] co_names {
             get;
             private set;
