1 /**
2 * .
3 * Copyright � 1999 Erich P G.
4 *
5 */
6
7 package autohit.vm;
8
9 import java.io.Serializable;
10
11 /**
12 * A Virtual Machine instruction base class. All vm instructions
13 * extend this class. This class also defines the static/final
14 * tokens and related constants used by both the vm and the
15 * compiler.
16 * <p>
17 * We will implement Serializable with this base class, so all
18 * final instruction classes will inherit it,
19 * <p>
20 * I thought about making this an interface, but since this IS
21 * a vm, it seem like a needless slowdown of a class that is
22 * going to get banged around enough as it is.
23 * <p>
24 * This class defines the numeric token for all instructions.
25 * So, if you create a new instruction, be sure to add a token
26 * for it in this class... and recompile ALL of the packages.
27 * <p>
28 * All derived-class constructors must set the numeric token.
29 *
30 * @author Erich P. Gatejen
31 * @version 1.0
32 * <i>Version History</i>
33 * <code>EPG - Initial - 5Jan99
34 * EPG - Add new instruction tokens - 3Feb99</code>
35 *
36 */
37 public class VMInstruction implements Serializable {
38
39 // --- FINAL FIELDS ------------------------------------------------------
40
41 /**
42 * Numeric token values.
43 *
44 * This is used as an optimization so we can do an OpCode
45 * switch(nToken) in the VM...
46 */
47 public static final int NOP = 0;
48 public static final int GET = 1;
49 public static final int FOR = 2;
50 public static final int WHILE = 3;
51 public static final int SET = 5;
52 public static final int WAIT = 6;
53 public static final int SCOPE = 7;
54 public static final int RSCOPE = 8;
55 public static final int HEADER = 9;
56 public static final int IF = 10;
57 public static final int NV = 11;
58 public static final int JUMP = 12;
59 public static final int ADD = 13;
60 public static final int VERIFY = 14;
61 public static final int CRC = 15;
62 public static final int SEEK = 16;
63 public static final int EXEC = 17;
64 public static final int ENV = 18;
65 public static final int SIM = 19;
66
67 /**
68 * Imbedded variable text token.
69 *
70 * You may NOT imbed a variable in another variable "name" (though,
71 * the reverse is possible).
72 */
73 public static final char IVToken = '$';
74
75 // --- FIELDS ------------------------------------------------------------
76 /**
77 * Numeric token.
78 * @serial
79 */
80 public int nToken;
81
82 /**
83 * Detected imbedded variable. An optimization,
84 * @serial
85 */
86 public boolean iv;
87
88 // --- PUBLIC METHODS ----------------------------------------------------
89
90 /**
91 * Default constructor
92 */
93 public VMInstruction() {
94 iv = false;
95 }
96
97 /**
98 * OR the IV with tap.
99 *
100 * <pre>
101 * iv tap | new iv
102 * T T | T
103 * T F | T
104 * F T | T
105 * F F | F
106 * </pre>
107 *
108 * @param tap value to OR against.
109 */
110 public void orIV(boolean tap) {
111
112 if ((iv != true)&&(tap != true)) iv = false;
113 else iv = true;
114 }
115
116 /**
117 * Dump this Instruction. Mostly for debugging. Subclasses should
118 * override thise
119 *
120 * @return a String containing the dump.
121 */
122 public String toString() {
123 StringBuffer d = new StringBuffer();
124 d.append(" VMInstr ---------------------------- \n");
125 return d.toString();
126 }
127
128 // --- PRIVATE METHODS ---------------------------------------------------
129
130
131 }
|