Clean up array ops to match the new GET/SETFIELD style.
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 05 01:10:49 2012 -0700 (2012-08-05)
changeset 157b760e8cb29a8
parent 156 0d28dc5af6c7
child 158 91071a2255bf
Clean up array ops to match the new GET/SETFIELD style.
src/BytecodeCompiler.cpp
src/BytecodeEmitter.h
src/Interpreter.cpp
src/Opcodes.cpp
src/Opcodes.tbl
     1.1 --- a/src/BytecodeCompiler.cpp	Sun Aug 05 00:49:31 2012 -0700
     1.2 +++ b/src/BytecodeCompiler.cpp	Sun Aug 05 01:10:49 2012 -0700
     1.3 @@ -264,7 +264,7 @@
     1.4  
     1.5          if (node->token() != TOK_ASSIGN || (type->isStruct() || type->isArray())) {
     1.6              __ bounds();
     1.7 -            __ getarray(index->type());
     1.8 +            __ getelem(index->type());
     1.9          }
    1.10      }
    1.11  
    1.12 @@ -302,10 +302,10 @@
    1.13          __ setfield(expr->fieldIndex(), expr->type());
    1.14      } else {
    1.15          IndexExpression *index = node->lvalue()->toIndexExpression();
    1.16 -        // :TODO: get rid of the BOUNDS instruction, embed it in g/setarray*?
    1.17 +        // :TODO: get rid of the BOUNDS instruction, embed it in g/setelem*?
    1.18          // We can't emit it here because the stack is slightly out of position.
    1.19          // __ bounds();
    1.20 -        __ setarray(index->type());
    1.21 +        __ setelem(index->type());
    1.22      }
    1.23  }
    1.24  
    1.25 @@ -384,7 +384,7 @@
    1.26          assert(!node->type()->isArray());
    1.27          __ bounds();
    1.28          __ dup2();
    1.29 -        __ getarray(node->type());
    1.30 +        __ getelem(node->type());
    1.31  
    1.32          if (node->postfix()) {
    1.33              // The stack looks like this now:
    1.34 @@ -425,7 +425,7 @@
    1.35          __ setfield(field->fieldIndex(), field->type());
    1.36      } else {
    1.37          assert(expr->isIndexExpression());
    1.38 -        __ setarray(node->type());
    1.39 +        __ setelem(node->type());
    1.40      }
    1.41  
    1.42      // Perform step (8).
    1.43 @@ -539,7 +539,7 @@
    1.44      node->right()->accept(this);
    1.45      __ note_position(node->pos());
    1.46      __ bounds();
    1.47 -    __ getarray(node->type());
    1.48 +    __ getelem(node->type());
    1.49  }
    1.50  
    1.51  void
     2.1 --- a/src/BytecodeEmitter.h	Sun Aug 05 00:49:31 2012 -0700
     2.2 +++ b/src/BytecodeEmitter.h	Sun Aug 05 01:10:49 2012 -0700
     2.3 @@ -365,39 +365,16 @@
     2.4          writeUint32(argc);
     2.5      }
     2.6  
     2.7 -    void getarray(Type *type) {
     2.8 -        if (type->isTraceable()) {
     2.9 -            singleByteOp(OP_GETARRAY_O);
    2.10 -            markOop(1);
    2.11 -            return;
    2.12 -        }
    2.13 +    void getelem(Type *type) {
    2.14 +        singleByteOp(OP_GETELEM);
    2.15  
    2.16 -        switch (type->pod()) {
    2.17 -          case PrimitiveType_Float:
    2.18 -            singleByteOp(OP_GETARRAY_F);
    2.19 -            break;
    2.20 -          case PrimitiveType_Int32:
    2.21 -            singleByteOp(OP_GETARRAY_I);
    2.22 -            break;
    2.23 -          default:
    2.24 -            assert(type->pod() == PrimitiveType_Char);
    2.25 -            singleByteOp(OP_GETARRAY_C);
    2.26 -            break;
    2.27 -        }
    2.28 +        if (type->isTraceable())
    2.29 +            markOop(1);
    2.30      }
    2.31 -    void setarray(Type *type) {
    2.32 -        switch (type->pod()) {
    2.33 -          case PrimitiveType_Float:
    2.34 -            singleByteOp(OP_SETARRAY_F);
    2.35 -            break;
    2.36 -          case PrimitiveType_Int32:
    2.37 -            singleByteOp(OP_SETARRAY_I);
    2.38 -            break;
    2.39 -          default:
    2.40 -            assert(type->pod() == PrimitiveType_Char);
    2.41 -            singleByteOp(OP_SETARRAY_C);
    2.42 -            break;
    2.43 -        }
    2.44 +    void setelem(Type *type) {
    2.45 +        singleByteOp(OP_SETELEM);
    2.46 +
    2.47 +        assert(!type->isTraceable());
    2.48      }
    2.49  
    2.50      void getfield(unsigned index, Type *type) {
     3.1 --- a/src/Interpreter.cpp	Sun Aug 05 00:49:31 2012 -0700
     3.2 +++ b/src/Interpreter.cpp	Sun Aug 05 01:10:49 2012 -0700
     3.3 @@ -120,22 +120,71 @@
     3.4  }
     3.5  
     3.6  static void
     3.7 +GetElement(Array *array, int index, LocalSlot *vp)
     3.8 +{
     3.9 +    if (array->type()->contained()->isTraceable()) {
    3.10 +        vp->obj = array->readObject(index);
    3.11 +        return;
    3.12 +    }
    3.13 +
    3.14 +    switch (array->type()->contained()->pod()) {
    3.15 +      case PrimitiveType_Float:
    3.16 +        vp->f = array->readFloat(index);
    3.17 +        break;
    3.18 +
    3.19 +      case PrimitiveType_Char:
    3.20 +        vp->i32 = array->readChar(index);
    3.21 +        break;
    3.22 +
    3.23 +      default:
    3.24 +        assert(array->type()->contained()->pod() == PrimitiveType_Int32);
    3.25 +        vp->i32 = array->readInt32(index);
    3.26 +        break;
    3.27 +    }
    3.28 +}
    3.29 +
    3.30 +static void
    3.31 +SetElement(Zone *zone, Array *array, int index, const LocalSlot &v)
    3.32 +{
    3.33 +    if (array->type()->contained()->isTraceable()) {
    3.34 +        array->writeObject(zone, index, v.obj);
    3.35 +        return;
    3.36 +    }
    3.37 +
    3.38 +    switch (array->type()->contained()->pod()) {
    3.39 +      case PrimitiveType_Float:
    3.40 +        array->writeFloat(index, v.f);
    3.41 +        break;
    3.42 +
    3.43 +      case PrimitiveType_Char:
    3.44 +        array->writeChar(index, v.i32);
    3.45 +        break;
    3.46 +
    3.47 +      default:
    3.48 +        assert(array->type()->contained()->pod() == PrimitiveType_Int32);
    3.49 +        array->writeInt32(index, v.i32);
    3.50 +        break;
    3.51 +    }
    3.52 +}
    3.53 +
    3.54 +static void
    3.55  GetField(Struct *obj, Descriptor *desc, LocalSlot *vp)
    3.56  {
    3.57      // :TODO: assert no GC.
    3.58      if (desc->type()->isTraceable()) {
    3.59          vp->obj = obj->get<Object *>(desc);
    3.60 -    } else {
    3.61 -        switch (desc->type()->pod()) {
    3.62 -          case PrimitiveType_Float:
    3.63 -            vp->f = obj->get<float>(desc);
    3.64 -            break;
    3.65 +        return;
    3.66 +    }
    3.67  
    3.68 -          default:
    3.69 -            assert(desc->type()->pod() == PrimitiveType_Int32);
    3.70 -            vp->i32 = obj->get<int>(desc);
    3.71 -            break;
    3.72 -        }
    3.73 +    switch (desc->type()->pod()) {
    3.74 +      case PrimitiveType_Float:
    3.75 +        vp->f = obj->get<float>(desc);
    3.76 +        break;
    3.77 +
    3.78 +      default:
    3.79 +        assert(desc->type()->pod() == PrimitiveType_Int32);
    3.80 +        vp->i32 = obj->get<int>(desc);
    3.81 +        break;
    3.82      }
    3.83  }
    3.84  
    3.85 @@ -152,17 +201,18 @@
    3.86      // :TODO: assert no GC.
    3.87      if (desc->type()->isTraceable()) {
    3.88          obj->set(zone, desc, v.obj);
    3.89 -    } else {
    3.90 -        switch (desc->type()->pod()) {
    3.91 -          case PrimitiveType_Float:
    3.92 -            obj->set<float>(desc, v.f);
    3.93 -            break;
    3.94 +        return;
    3.95 +    }
    3.96  
    3.97 -          default:
    3.98 -            assert(desc->type()->pod() == PrimitiveType_Int32);
    3.99 -            obj->set<int>(desc, v.i32);
   3.100 -            break;
   3.101 -        }
   3.102 +    switch (desc->type()->pod()) {
   3.103 +      case PrimitiveType_Float:
   3.104 +        obj->set<float>(desc, v.f);
   3.105 +        break;
   3.106 +
   3.107 +      default:
   3.108 +        assert(desc->type()->pod() == PrimitiveType_Int32);
   3.109 +        obj->set<int>(desc, v.i32);
   3.110 +        break;
   3.111      }
   3.112  }
   3.113  
   3.114 @@ -702,72 +752,25 @@
   3.115      break;
   3.116  }
   3.117  
   3.118 -case OP_GETARRAY_I:
   3.119 -{
   3.120 -    Array *array = top.sp[-2].array;
   3.121 -    int index = top.sp[-1].i32;
   3.122 -    top.sp[-2].i32 = array->readInt32(index);
   3.123 -    top.sp--;
   3.124 -    break;
   3.125 -}
   3.126 -
   3.127 -case OP_GETARRAY_F:
   3.128 +case OP_GETELEM:
   3.129  {
   3.130 -    Array *array = top.sp[-2].array;
   3.131 +    Array *array = Array::cast(top.sp[-2].obj);
   3.132      int index = top.sp[-1].i32;
   3.133 -    top.sp[-2].f = array->readFloat(index);
   3.134 -    top.sp--;
   3.135 -    break;
   3.136 -}
   3.137 -
   3.138 -case OP_GETARRAY_C:
   3.139 -{
   3.140 -    Array *array = top.sp[-2].array;
   3.141 -    int index = top.sp[-1].i32;
   3.142 -    top.sp[-2].i32 = array->readChar(index);
   3.143 +    GetElement(array, index, &top.sp[-2]);
   3.144      top.sp--;
   3.145      break;
   3.146  }
   3.147  
   3.148 -case OP_SETARRAY_I:
   3.149 +case OP_SETELEM:
   3.150  {
   3.151 -    Array *array = top.sp[-3].array;
   3.152 +    Array *array = Array::cast(top.sp[-3].obj);
   3.153      int index = top.sp[-2].i32;
   3.154 -    array->writeInt32(index, top.sp[-1].i32);
   3.155 -    top.sp[-3] = top.sp[-1];
   3.156 -    top.sp -= 2;
   3.157 -    break;
   3.158 -}
   3.159 -
   3.160 -case OP_SETARRAY_F:
   3.161 -{
   3.162 -    Array *array = top.sp[-3].array;
   3.163 -    int index = top.sp[-2].i32;
   3.164 -    array->writeFloat(index, top.sp[-1].f);
   3.165 +    SetElement(zone, array, index, top.sp[-1]);
   3.166      top.sp[-3] = top.sp[-1];
   3.167      top.sp -= 2;
   3.168      break;
   3.169  }
   3.170  
   3.171 -case OP_SETARRAY_C:
   3.172 -{
   3.173 -    Array *array = top.sp[-3].array;
   3.174 -    int index = top.sp[-2].i32;
   3.175 -    array->writeChar(index, top.sp[-1].i32);
   3.176 -    top.sp[-3] = top.sp[-1];
   3.177 -    top.sp -= 2;
   3.178 -    break;
   3.179 -}
   3.180 -
   3.181 -case OP_GETARRAY_O:
   3.182 -{
   3.183 -    Array *array = top.sp[-2].array;
   3.184 -    int index = top.sp[-1].i32;
   3.185 -    top.sp[-2].obj = array->readObject(index);
   3.186 -    top.sp--;
   3.187 -    break;
   3.188 -}
   3.189 -
   3.190  case OP_CVT_I2F:
   3.191  {
   3.192      int ival = POP_I32(top);
     4.1 --- a/src/Opcodes.cpp	Sun Aug 05 00:49:31 2012 -0700
     4.2 +++ b/src/Opcodes.cpp	Sun Aug 05 01:10:49 2012 -0700
     4.3 @@ -160,13 +160,8 @@
     4.4            case OP_DIV_F:
     4.5            case OP_CVT_I2F:
     4.6            case OP_POP:
     4.7 -          case OP_GETARRAY_I:
     4.8 -          case OP_SETARRAY_I:
     4.9 -          case OP_GETARRAY_F:
    4.10 -          case OP_SETARRAY_F:
    4.11 -          case OP_GETARRAY_C:
    4.12 -          case OP_SETARRAY_C:
    4.13 -          case OP_GETARRAY_O:
    4.14 +          case OP_GETELEM:
    4.15 +          case OP_SETELEM:
    4.16            case OP_BOUNDS:
    4.17            case OP_SHL:
    4.18            case OP_SHR:
     5.1 --- a/src/Opcodes.tbl	Sun Aug 05 00:49:31 2012 -0700
     5.2 +++ b/src/Opcodes.tbl	Sun Aug 05 01:10:49 2012 -0700
     5.3 @@ -103,25 +103,27 @@
     5.4  OPDEF(OP_GETARG,        38,         "getarg",       5,      0,  1)
     5.5  OPDEF(OP_SETARG,        39,         "setarg",       5,      1,  1)
     5.6  
     5.7 +// Allocate an array. The HeapTenure is stored as a byte following pc. The
     5.8 +// ArrayMap to use is specified as an index into the script's Map table.
     5.9 +//
    5.10 +// Format:
    5.11 +//  [u8 op] [u32 index]
    5.12 +OPDEF(OP_NEWARRAY,      40,         "newarray",     6,      0,  1)
    5.13 +
    5.14 +// Performs an array-to-array assignment.
    5.15 +//   Left = pop()
    5.16 +//   Right = pop()
    5.17 +//   copy(Left, Right)
    5.18 +//   push(Left)
    5.19 +OPDEF(OP_COPYARRAY,     41,         "arraycopy",    1,      2,  1)
    5.20 +
    5.21  // Reads or writes an integer element to an unsafe array.
    5.22  //  index = pop()
    5.23  //  ref = pop()
    5.24  //  ref[index]
    5.25  //
    5.26 -OPDEF(OP_GETARRAY_I,    40,         "getarray.i",   1,      2,  1)
    5.27 -OPDEF(OP_SETARRAY_I,    41,         "setarray.i",   1,      3,  1)
    5.28 -OPDEF(OP_GETARRAY_F,    42,         "getarray.f",   1,      2,  1)
    5.29 -OPDEF(OP_SETARRAY_F,    43,         "setarray.f",   1,      3,  1)
    5.30 -OPDEF(OP_GETARRAY_C,    44,         "getarray.c",   1,      2,  1)
    5.31 -OPDEF(OP_SETARRAY_C,    45,         "setarray.c",   1,      3,  1)
    5.32 -OPDEF(OP_GETARRAY_O,    46,         "getarray.o",   1,      2,  1)
    5.33 -
    5.34 -// Allocate an array. The HeapTenure is stored as a byte following pc. The
    5.35 -// ArrayMap to use is specified as an index into the script's Map table.
    5.36 -//
    5.37 -// Format:
    5.38 -//  [u8 op] [u32 index]
    5.39 -OPDEF(OP_NEWARRAY,      47,         "newarray",     6,      0,  1)
    5.40 +OPDEF(OP_GETELEM,       42,         "getelem",      1,      2,  1)
    5.41 +OPDEF(OP_SETELEM,       43,         "setelem",      1,      3,  1)
    5.42  
    5.43  // Performs a bounds check on an unsafe array.
    5.44  //
    5.45 @@ -129,75 +131,67 @@
    5.46  // array = pop()
    5.47  // push(array)
    5.48  // push(index)
    5.49 -OPDEF(OP_BOUNDS,        48,         "bounds",       1,      2,  2)
    5.50 +OPDEF(OP_BOUNDS,        44,         "bounds",       1,      2,  2)
    5.51  
    5.52  // Pushes a 32-bit IEEE-754 floating point immediate onto the stack.
    5.53 -OPDEF(OP_FLOAT,         49,         "float",        5,      0,  1)
    5.54 +OPDEF(OP_FLOAT,         45,         "float",        5,      0,  1)
    5.55  
    5.56  // Converts an integer to a 32-bit IEEE-754 floating point immediate.
    5.57 -OPDEF(OP_CVT_I2F,       50,         "cvt.i2f",      1,      1,  1)
    5.58 +OPDEF(OP_CVT_I2F,       46,         "cvt.i2f",      1,      1,  1)
    5.59  
    5.60  // Stack transitions for these binary operators:
    5.61  // rhs = pop()
    5.62  // lhs = pop()
    5.63  // push(lhs OP rhs)
    5.64 -OPDEF(OP_ADD_F,         51,         "add.f",        1,      2,  1)
    5.65 -OPDEF(OP_SUB_F,         52,         "sub.f",        1,      2,  1)
    5.66 -OPDEF(OP_MUL_F,         53,         "mul.f",        1,      2,  1)
    5.67 -OPDEF(OP_DIV_F,         54,         "div.f",        1,      2,  1)
    5.68 -OPDEF(OP_UNUSED1,       55,         "unused0",      1,      0,  0)
    5.69 +OPDEF(OP_ADD_F,         47,         "add.f",        1,      2,  1)
    5.70 +OPDEF(OP_SUB_F,         48,         "sub.f",        1,      2,  1)
    5.71 +OPDEF(OP_MUL_F,         49,         "mul.f",        1,      2,  1)
    5.72 +OPDEF(OP_DIV_F,         50,         "div.f",        1,      2,  1)
    5.73  
    5.74 -OPDEF(OP_LT_F,          56,         "lt.f",         1,      2,  1)
    5.75 -OPDEF(OP_LE_F,          57,         "le.f",         1,      2,  1)
    5.76 -OPDEF(OP_GE_F,          58,         "ge.f",         1,      2,  1)
    5.77 -OPDEF(OP_GT_F,          59,         "gt.f",         1,      2,  1)
    5.78 -OPDEF(OP_EQ_F,          60,         "eq.f",         1,      2,  1)
    5.79 -OPDEF(OP_NE_F,          61,         "ne.f",         1,      2,  1)
    5.80 +OPDEF(OP_LT_F,          51,         "lt.f",         1,      2,  1)
    5.81 +OPDEF(OP_LE_F,          52,         "le.f",         1,      2,  1)
    5.82 +OPDEF(OP_GE_F,          53,         "ge.f",         1,      2,  1)
    5.83 +OPDEF(OP_GT_F,          54,         "gt.f",         1,      2,  1)
    5.84 +OPDEF(OP_EQ_F,          55,         "eq.f",         1,      2,  1)
    5.85 +OPDEF(OP_NE_F,          56,         "ne.f",         1,      2,  1)
    5.86  
    5.87 -OPDEF(OP_NOT_F,         62,         "not.f",        1,      1,  1)
    5.88 -OPDEF(OP_NEG_F,         63,         "neg.f",        1,      1,  1)
    5.89 +OPDEF(OP_NOT_F,         57,         "not.f",        1,      1,  1)
    5.90 +OPDEF(OP_NEG_F,         58,         "neg.f",        1,      1,  1)
    5.91  
    5.92  // Bitwise operators.
    5.93 -OPDEF(OP_SHL,           64,         "shl",          1,      2,  1)
    5.94 -OPDEF(OP_SHR,           65,         "shr",          1,      2,  1)
    5.95 -OPDEF(OP_USHR,          66,         "ushr",         1,      2,  1)
    5.96 -OPDEF(OP_BITAND,        67,         "bitand",       1,      2,  1)
    5.97 -OPDEF(OP_BITOR,         68,         "bitor",        1,      2,  1)
    5.98 -OPDEF(OP_BITXOR,        69,         "bitxor",       1,      2,  1)
    5.99 -OPDEF(OP_BITNOT,        70,         "bitnot",       1,      1,  1)
   5.100 +OPDEF(OP_SHL,           59,         "shl",          1,      2,  1)
   5.101 +OPDEF(OP_SHR,           60,         "shr",          1,      2,  1)
   5.102 +OPDEF(OP_USHR,          61,         "ushr",         1,      2,  1)
   5.103 +OPDEF(OP_BITAND,        62,         "bitand",       1,      2,  1)
   5.104 +OPDEF(OP_BITOR,         63,         "bitor",        1,      2,  1)
   5.105 +OPDEF(OP_BITXOR,        64,         "bitxor",       1,      2,  1)
   5.106 +OPDEF(OP_BITNOT,        65,         "bitnot",       1,      1,  1)
   5.107  
   5.108  // Saves or restores the position of the LIFO heap to/from a local slot.
   5.109 -OPDEF(OP_SAVELIFO,      71,         "savelifo",     5,      0,  0)
   5.110 -OPDEF(OP_UNWINDLIFO,    72,         "unwindlifo",   5,      0,  0)
   5.111 +OPDEF(OP_SAVELIFO,      66,         "savelifo",     5,      0,  0)
   5.112 +OPDEF(OP_UNWINDLIFO,    67,         "unwindlifo",   5,      0,  0)
   5.113  
   5.114  // Composes a variable reference to a stack slot or argument.
   5.115 -OPDEF(OP_VARREF_LIFO,   73,         "varref.lifo",  5,      0,  1)
   5.116 -OPDEF(OP_ARGREF_LIFO,   74,         "argref.lifo",  5,      0,  1)
   5.117 -OPDEF(OP_SLOTREF_LIFO,  75,         "slotref.lifo", 1,      1,  1)
   5.118 -OPDEF(OP_ARRAYREF_LIFO, 76,         "arrayref.lifo",1,      2,  1)
   5.119 -OPDEF(OP_GETREF_I,      77,         "getref.i",     1,      1,  1)
   5.120 -OPDEF(OP_SETREF_I,      78,         "setref.i",     1,      2,  1)
   5.121 -OPDEF(OP_GETREF_F,      79,         "getref.f",     1,      1,  1)
   5.122 -OPDEF(OP_SETREF_F,      80,         "setref.f",     1,      2,  1)
   5.123 +OPDEF(OP_VARREF_LIFO,   68,         "varref.lifo",  5,      0,  1)
   5.124 +OPDEF(OP_ARGREF_LIFO,   69,         "argref.lifo",  5,      0,  1)
   5.125 +OPDEF(OP_SLOTREF_LIFO,  70,         "slotref.lifo", 1,      1,  1)
   5.126 +OPDEF(OP_ARRAYREF_LIFO, 71,         "arrayref.lifo",1,      2,  1)
   5.127 +OPDEF(OP_GETREF_I,      72,         "getref.i",     1,      1,  1)
   5.128 +OPDEF(OP_SETREF_I,      73,         "setref.i",     1,      2,  1)
   5.129 +OPDEF(OP_GETREF_F,      74,         "getref.f",     1,      1,  1)
   5.130 +OPDEF(OP_SETREF_F,      75,         "setref.f",     1,      2,  1)
   5.131  
   5.132  // Pushes an object reference onto the stack.
   5.133 -OPDEF(OP_OBJECT,        81,         "object",       5,      0,  1)
   5.134 -
   5.135 -// Performs an array-to-array assignment.
   5.136 -//   Left = pop()
   5.137 -//   Right = pop()
   5.138 -//   copy(Left, Right)
   5.139 -//   push(Left)
   5.140 -OPDEF(OP_COPYARRAY,     82,         "arraycopy",    1,      2,  1)
   5.141 +OPDEF(OP_OBJECT,        76,         "object",       5,      0,  1)
   5.142  
   5.143  // Duplicates the top item on the stack.
   5.144 -OPDEF(OP_DUP,           83,         "dup",          1,      1,  2)
   5.145 +OPDEF(OP_DUP,           77,         "dup",          1,      1,  2)
   5.146  
   5.147  // Duplicates the top two items on the stack.
   5.148 -OPDEF(OP_DUP2,          84,         "dup2",         1,      2,  4)
   5.149 +OPDEF(OP_DUP2,          78,         "dup2",         1,      2,  4)
   5.150  
   5.151  // Swaps the two items at the top of the stack.
   5.152 -OPDEF(OP_SWAP,          85,         "swap",         1,      2,  2)
   5.153 +OPDEF(OP_SWAP,          79,         "swap",         1,      2,  2)
   5.154  
   5.155  // Roll operation is the same as Forth. It steals a value on the stack,
   5.156  // shifting all stack values down, and then places the stolen value back at
   5.157 @@ -207,14 +201,14 @@
   5.158  //  sp[-3] = sp[-2]
   5.159  //  sp[-2] = sp[-1]
   5.160  //  sp[-1] = p
   5.161 -OPDEF(OP_ROLL3,         86,         "roll3",        1,      3, 3)
   5.162 +OPDEF(OP_ROLL3,         80,         "roll3",        1,      3, 3)
   5.163  
   5.164  // Pick operation is the same as Forth. It pushes a copy of a slot at a
   5.165  // specific depth.
   5.166  //
   5.167  // push(sp[-n])
   5.168 -OPDEF(OP_PICK2,         87,         "pick2",        1,      2, 3)
   5.169 -OPDEF(OP_PICK3,         88,         "pick3",        1,      3, 4)
   5.170 +OPDEF(OP_PICK2,         81,         "pick2",        1,      2, 3)
   5.171 +OPDEF(OP_PICK3,         82,         "pick3",        1,      3, 4)
   5.172  
   5.173  // Calls a native function. During the course of calling a native, arguments
   5.174  // on the stack are re-pushed to match the cell-based native calling
   5.175 @@ -225,51 +219,51 @@
   5.176  //
   5.177  // [u8 Opcode] [u32 Index] [u32 ArgCount]
   5.178  //
   5.179 -OPDEF(OP_CALLNATIVE,    89,         "callnative",   9,      -1, 1)
   5.180 +OPDEF(OP_CALLNATIVE,    83,         "callnative",   9,      -1, 1)
   5.181  
   5.182  // Returns from a function that does return a value.
   5.183 -OPDEF(OP_RETURNVOID,    90,         "returnvoid",   1,      0, 0)
   5.184 +OPDEF(OP_RETURNVOID,    84,         "returnvoid",   1,      0, 0)
   5.185  
   5.186  // Loads the module of the running function.
   5.187 -OPDEF(OP_MODULE,        91,         "module",       1,      0, 1)
   5.188 +OPDEF(OP_MODULE,        85,         "module",       1,      0, 1)
   5.189  
   5.190  // Loads a function from a module object. The operand is the slot number
   5.191  // in the module.
   5.192 -OPDEF(OP_GETMODULE_FN,  92,         "getmodule.fn", 5,      1, 1)
   5.193 +OPDEF(OP_GETMODULE_FN,  86,         "getmodule.fn", 5,      1, 1)
   5.194  
   5.195  // Opcodes for accessing an environment slot in the global scope.
   5.196 -OPDEF(OP_SETGLOBAL_I,   93,         "setglobal.i",  5,      1, 1)
   5.197 -OPDEF(OP_SETGLOBAL_F,   94,         "setglobal.f",  5,      1, 1)
   5.198 -OPDEF(OP_SETGLOBAL_O,   95,         "setglobal.o",  5,      1, 1)
   5.199 -OPDEF(OP_GETGLOBAL_I,   96,         "getglobal.i",  5,      0, 1)
   5.200 -OPDEF(OP_GETGLOBAL_F,   97,         "getglobal.f",  5,      0, 1)
   5.201 -OPDEF(OP_GETGLOBAL_O,   98,         "getglobal.o",  5,      0, 1)
   5.202 +OPDEF(OP_SETGLOBAL_I,   87,         "setglobal.i",  5,      1, 1)
   5.203 +OPDEF(OP_SETGLOBAL_F,   88,         "setglobal.f",  5,      1, 1)
   5.204 +OPDEF(OP_SETGLOBAL_O,   89,         "setglobal.o",  5,      1, 1)
   5.205 +OPDEF(OP_GETGLOBAL_I,   90,         "getglobal.i",  5,      0, 1)
   5.206 +OPDEF(OP_GETGLOBAL_F,   91,         "getglobal.f",  5,      0, 1)
   5.207 +OPDEF(OP_GETGLOBAL_O,   92,         "getglobal.o",  5,      0, 1)
   5.208  
   5.209  // Reinterprets a 32-bit integer as a float, or vice-versa.
   5.210 -OPDEF(OP_BITS_I2F,      99,         "bits.i2f",     1,      1, 1)
   5.211 -OPDEF(OP_BITS_F2I,      100,        "bits.f2i",     1,      1, 1)
   5.212 +OPDEF(OP_BITS_I2F,      93,         "bits.i2f",     1,      1, 1)
   5.213 +OPDEF(OP_BITS_F2I,      94,         "bits.f2i",     1,      1, 1)
   5.214  
   5.215  // Pushes a boolean value.
   5.216 -OPDEF(OP_TRUE,          101,        "true",         1,      0, 1)
   5.217 -OPDEF(OP_FALSE,         102,        "false",        1,      0, 1)
   5.218 +OPDEF(OP_TRUE,          95,         "true",         1,      0, 1)
   5.219 +OPDEF(OP_FALSE,         96,         "false",        1,      0, 1)
   5.220  
   5.221  // Allocate a struct. The HeapTenure is stored as a byte following pc. The
   5.222  // StructMap to use is specified as an index into the script's Map table.
   5.223  //
   5.224  // Format:
   5.225  //  [u8 op] [u32 index]
   5.226 -OPDEF(OP_NEWSTRUCT,     103,        "newstruct",    6,      0, 1)
   5.227 -
   5.228 -// Sets or gets a property in a struct. The index of the field is specified as
   5.229 -// a 32-bit integer. Note that these opcodes follow a new style of deriving
   5.230 -// their types at runtime.
   5.231 -OPDEF(OP_GETFIELD,      104,        "getfield",     5,      1, 1)
   5.232 -OPDEF(OP_SETFIELD,      105,        "setfield",     5,      2, 1)
   5.233 +OPDEF(OP_NEWSTRUCT,     97,         "newstruct",    6,      0, 1)
   5.234  
   5.235  // Performs a struct-to-struct assignment.
   5.236  //   Left = pop()
   5.237  //   Right = pop()
   5.238  //   copy(Left, Right)
   5.239  //   push(Left)
   5.240 -OPDEF(OP_COPYSTRUCT,    106,        "structcopy",   1,      2, 1)
   5.241 +OPDEF(OP_COPYSTRUCT,    98,         "structcopy",   1,      2, 1)
   5.242  
   5.243 +// Sets or gets a property in a struct. The index of the field is specified as
   5.244 +// a 32-bit integer. Note that these opcodes follow a new style of deriving
   5.245 +// their types at runtime.
   5.246 +OPDEF(OP_GETFIELD,      99,         "getfield",     5,      1, 1)
   5.247 +OPDEF(OP_SETFIELD,      100,        "setfield",     5,      2, 1)
   5.248 +