// Path: src/stone/StoneException.java
// public class StoneException extends RuntimeException {
//     public StoneException(String m) { super(m); }
//     public StoneException(String m, ASTree t) {
//         super(m + " " + t.location());
//     }
// }


import stone.StoneException;
package chap13;

public class Opcode {
    public static final byte ICONST = 1;    // load an integer
    public static final byte BCONST = 2;    // load an 8bit (1byte) integer
    public static final byte SCONST = 3;    // load a character string
    public static final byte MOVE = 4;      // move a value
    public static final byte GMOVE = 5;     // move a value (global variable)
    public static final byte IFZERO = 6;    // branch if false
    public static final byte GOTO = 7;      // always branch
    public static final byte CALL = 8;      // call a function
    public static final byte RETURN = 9;    // return
    public static final byte SAVE = 10;     // save all registers
    public static final byte RESTORE = 11;  // restore all registers
    public static final byte NEG = 12;      // arithmetic negation
    public static final byte ADD = 13;      // add
    public static final byte SUB = 14;      // subtract
    public static final byte MUL = 15;      // multiply
    public static final byte DIV = 16;      // divide
    public static final byte REM = 17;      // remainder
    public static final byte EQUAL = 18;    // equal
    public static final byte MORE = 19;     // more than
    public static final byte LESS = 20;     // less than

    public static byte encodeRegister(int reg) {
        if (reg > StoneVM.NUM_OF_REG)
// Path: src/stone/StoneException.java
// public class StoneException extends RuntimeException {
//     public StoneException(String m) { super(m); }
//     public StoneException(String m, ASTree t) {
//         super(m + " " + t.location());
//     }
// }


// Path: src/chap13/Opcode.java
import stone.StoneException;

package chap13;

public class Opcode {
    public static final byte ICONST = 1;    // load an integer
    public static final byte BCONST = 2;    // load an 8bit (1byte) integer
    public static final byte SCONST = 3;    // load a character string
    public static final byte MOVE = 4;      // move a value
    public static final byte GMOVE = 5;     // move a value (global variable)
    public static final byte IFZERO = 6;    // branch if false
    public static final byte GOTO = 7;      // always branch
    public static final byte CALL = 8;      // call a function
    public static final byte RETURN = 9;    // return
    public static final byte SAVE = 10;     // save all registers
    public static final byte RESTORE = 11;  // restore all registers
    public static final byte NEG = 12;      // arithmetic negation
    public static final byte ADD = 13;      // add
    public static final byte SUB = 14;      // subtract
    public static final byte MUL = 15;      // multiply
    public static final byte DIV = 16;      // divide
    public static final byte REM = 17;      // remainder
    public static final byte EQUAL = 18;    // equal
    public static final byte MORE = 19;     // more than
    public static final byte LESS = 20;     // less than

    public static byte encodeRegister(int reg) {
        if (reg > StoneVM.NUM_OF_REG)
            throw new StoneException("too many registers required");