@@ -61,9 +61,11 @@ enum class Opcode {
6161  AllocClosure = 8U ,
6262  GetField = 9U ,
6363  If = 10U ,
64-   Select = 11U ,
65-   LoadConst = 12U ,
66-   Goto = 13U 
64+   LoadConst = 11U ,
65+   Goto = 12U ,
66+   GetTag = 13U ,
67+   LoadConsti = 14U ,
68+   Fatal = 15U ,
6769};
6870
6971/* ! \brief A single virtual machine instruction.
@@ -123,22 +125,16 @@ struct Instruction {
123125      /* ! \brief The arguments to pass to the packed function. */ 
124126      RegName* packed_args;
125127    };
126-     struct  /*  Select Operands */ 
127-       /* ! \brief The condition of select. */ 
128-       RegName select_cond;
129-       /* ! \brief The true branch. */ 
130-       RegName select_op1;
131-       /* ! \brief The false branch. */ 
132-       RegName select_op2;
133-     };
134128    struct  /*  If Operands */ 
135-       /* ! \brief The register containing the condition value. */ 
136-       RegName if_cond;
129+       /* ! \brief The register containing the test value. */ 
130+       RegName test;
131+       /* ! \brief The register containing the target value. */ 
132+       RegName target;
137133      /* ! \brief The program counter offset for the true branch. */ 
138134      Index true_offset;
139135      /* ! \brief The program counter offset for the false branch. */ 
140136      Index false_offset;
141-     };
137+     } if_op ;
142138    struct  /*  Invoke Operands */ 
143139      /* ! \brief The function to call. */ 
144140      Index func_index;
@@ -151,6 +147,10 @@ struct Instruction {
151147      /*  \brief The index into the constant pool. */ 
152148      Index const_index;
153149    };
150+     struct  /*  LoadConsti Operands */ 
151+       /*  \brief The index into the constant pool. */ 
152+       size_t  val;
153+     } load_consti;
154154    struct  /*  Jump Operands */ 
155155      /* ! \brief The jump offset. */ 
156156      Index pc_offset;
@@ -161,6 +161,10 @@ struct Instruction {
161161      /* ! \brief The field to read out. */ 
162162      Index field_index;
163163    };
164+     struct  /*  GetTag Operands */ 
165+       /* ! \brief The register to project from. */ 
166+       RegName object;
167+     } get_tag;
164168    struct  /*  AllocDatatype Operands */ 
165169      /* ! \brief The datatype's constructor tag. */ 
166170      Index constructor_tag;
@@ -179,19 +183,15 @@ struct Instruction {
179183    };
180184  };
181185
182-   /* ! \brief Construct a select instruction.
183-    *  \param cond The condition register. 
184-    *  \param op1 The true register. 
185-    *  \param op2 The false register. 
186-    *  \param dst The destination register. 
187-    *  \return The select instruction. 
188-    */  
189-   static  Instruction Select (RegName cond, RegName op1, RegName op2, RegName dst);
190186  /* ! \brief Construct a return instruction.
191187   *  \param return_reg The register containing the return value. 
192188   *  \return The return instruction. 
193189   * */  
194190  static  Instruction Ret (RegName return_reg);
191+   /* ! \brief Construct a fatal instruction.
192+    *  \return The fatal instruction. 
193+    * */    
194+   static  Instruction Fatal ();
195195  /* ! \brief Construct a invoke packed instruction.
196196   *  \param packed_index The index of the packed function. 
197197   *  \param arity The arity of the function. 
@@ -240,13 +240,20 @@ struct Instruction {
240240   *  \return The get field instruction. 
241241   */  
242242  static  Instruction GetField (RegName object_reg, Index field_index, RegName dst);
243+   /* ! \brief Construct a get_tag instruction.
244+    *  \param object_reg The register containing the object to project from. 
245+    *  \param dst The destination register. 
246+    *  \return The get_tag instruction. 
247+    */  
248+   static  Instruction GetTag (RegName object_reg, RegName dst);
243249  /* ! \brief Construct an if instruction.
244-    *  \param cond_reg The register containing the condition. 
250+    *  \param test The register containing the test value. 
251+    *  \param target The register containing the target value. 
245252   *  \param true_branch The offset to the true branch. 
246253   *  \param false_branch The offset to the false branch. 
247254   *  \return The if instruction. 
248255   */  
249-   static  Instruction If (RegName cond_reg , Index true_branch, Index false_branch);
256+   static  Instruction If (RegName test, RegName target , Index true_branch, Index false_branch);
250257  /* ! \brief Construct a goto instruction.
251258   *  \param pc_offset The offset from the current pc. 
252259   *  \return The goto instruction. 
@@ -272,6 +279,12 @@ struct Instruction {
272279   *  \return The load constant instruction. 
273280   */  
274281  static  Instruction LoadConst (Index const_index, RegName dst);
282+   /* ! \brief Construct a load_constanti instruction.
283+    *  \param val The interger constant value. 
284+    *  \param dst The destination register. 
285+    *  \return The load_constanti instruction. 
286+    */  
287+   static  Instruction LoadConsti (size_t  val, RegName dst);
275288  /* ! \brief Construct a move instruction.
276289   *  \param src The source register. 
277290   *  \param dst The destination register. 
@@ -398,6 +411,12 @@ struct VirtualMachine {
398411   */  
399412  inline  Object ReadRegister (RegName reg) const ;
400413
414+   /* ! \brief Read a VM register and cast it to int32_t
415+    *  \param reg The register to read from. 
416+    *  \return The read scalar. 
417+    */  
418+   int32_t  LoadScalarInt (RegName reg) const ;
419+ 
401420  /* ! \brief Invoke a VM function.
402421   * \param func The function. 
403422   * \param args The arguments to the function. 
0 commit comments