1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.vm.i;
22
23 import java.io.Serializable;
24 //import autohit.common.Constants;
25
26 /**
27 * A Virtual Machine instruction base class. All vm instructions
28 * extend this class. This class also defines the static/final
29 * tokens and related constants used by both the vm and the
30 * compiler.
31 * <p>
32 * We will implement Serializable with this base class, so all
33 * final instruction classes will inherit it,
34 * <p>
35 * I thought about making this an interface, but since this IS
36 * a vm, it seem like a needless slowdown of a class that is
37 * going to get banged around enough as it is.
38 * <p>
39 * This class defines the numeric token for all instructions.
40 * So, if you create a new instruction, be sure to add a token
41 * for it in this class... and recompile ALL of the packages.
42 * <p>
43 * All derived-class constructors must set the numeric token.
44 *
45 * @author Erich P. Gatejen
46 * @version 1.1
47 * <i>Version History</i>
48 * <code>EPG - Rewrite - 9Apr03<br>
49 * EPG - Add goto - 16Jul03</code>
50 */
51 public class VMInstruction implements Serializable {
52
53 final static long serialVersionUID = 1;
54
55 /**
56 * Numeric token values.
57 *
58 * This is used as an optimization so we can do an OpCode
59 * switch(nToken) in the VM...
60 */
61 public static final int NOP = 0;
62 public static final int EVAL = 1;
63 public static final int STORE = 2;
64 public static final int NEW = 3;
65 public static final int SCOPE = 4;
66 public static final int RSCOPE = 5;
67 public static final int REDUCE = 6;
68 public static final int MASK = 7;
69 public static final int MERGE = 8;
70 public static final int RIGHT = 9;
71 public static final int MATH = 10;
72 public static final int LOAD = 11;
73 public static final int CLEAR = 12;
74 public static final int FAULT = 13;
75 public static final int FETCH = 14;
76 public static final int IF = 15;
77 public static final int CALL = 16;
78 public static final int EXEC = 17;
79 public static final int SUBR = 18;
80 public static final int JUMP = 19;
81 public static final int GOTO = 20;
82 public static final int ASSERT = 21;
83 public static final int METHOD = 22;
84
85 /**
86 * instruction
87 * @serial
88 */
89 public int instruction;
90
91 /**
92 * source code line - good for debugging
93 * TODO sourceline doesn't actually work
94 * @serial
95 */
96 public int sourceline;
97
98
99 /**
100 * Default constructor
101 *
102 * Normally you would use the other constructor.
103 */
104 public VMInstruction() {
105 instruction = NOP;
106 sourceline = 0;
107 }
108
109 /**
110 * Typical constructor. Sets the instruction type. Use this one!
111 */
112 public VMInstruction(int I) {
113 instruction = I;
114 }
115
116 /**
117 * Dump this Instruction. Mostly for debugging.
118 *
119 * @return a String containing the dump.
120 */
121 public String toString() {
122 return instruction + ":" + sourceline + ":" + this.dump();
123 }
124
125 /**
126 * Dump this Instruction. Mostly for debugging. Subclasses should
127 * override this.
128 *
129 * @return a String containing the dump.
130 */
131 public String dump() {
132 return "";
133 }
134
135 }
|