001: /***
002: * Actions.java
003: */package org.openlaszlo.sc;
004:
005: import java.io.*;
006: import java.util.*;
007:
008: /*
009: * Single-word instructions are CAPS (to minimize the chance of
010: * collisions with client names). Multi-word instructions are
011: * CamelCase.
012: *
013: * Names (modulo case) are intended to be the same as those used by
014: * flasm. This aids debugging, and will also insure that the inline
015: * assembler assembles the same language as flasm, when this is added.
016: * There are probably some names that don't yet match flasm, especially
017: * outside the Flash 5 opcode set.
018: */
019:
020: /***
021: * Information about ActionScript bytecodes
022: * -1 for arity or returns means "don't know"
023: */
024: public class Actions {
025: protected static final int ACTIONS_SIZE = 256;
026: /* name -> Action */
027: public static final HashMap actions = new HashMap();
028: protected static Action[] actionArray = new Action[ACTIONS_SIZE];
029:
030: /* Returns set of Action */
031: public static Set items() {
032: return actions.entrySet();
033: }
034:
035: static final int opcodeIndex(byte opcode) {
036: return (int) opcode - (int) java.lang.Byte.MIN_VALUE;
037: }
038:
039: protected static Action find(byte opcode) {
040: Action action = actionArray[opcodeIndex(opcode)];
041: if (action == null)
042: throw new RuntimeException("null action");
043: return action;
044: }
045:
046: public static class Action implements Serializable {
047: public final String name;
048: public final byte opcode;
049: public final boolean args;
050: public final int arity;
051: public final int returns;
052:
053: public Action(String name, byte opcode) {
054: this (name, opcode, -1, -1);
055: }
056:
057: public Action(String name, byte opcode, int arity, int returns) {
058: this (name, opcode, arity, returns, (opcode & 0x80) != 0);
059: }
060:
061: public Action(String name, byte opcode, int arity, int returns,
062: boolean args) {
063: super ();
064: this .name = name;
065: this .opcode = opcode;
066: this .args = args;
067: this .arity = arity;
068: this .returns = returns;
069: assert actions.get(name) == null;
070: actions.put(name, this );
071: int index = opcodeIndex(opcode);
072: assert actionArray[index] == null;
073: actionArray[index] = this ;
074: }
075:
076: public Object writeReplace() {
077: return ActionReplacement.make(this .opcode);
078: }
079: }
080:
081: // This object is used to replace a serialized Action.
082: protected static class ActionReplacement implements Externalizable {
083: // class implementation
084: protected static final ActionReplacement[] array = new ActionReplacement[ACTIONS_SIZE];
085:
086: // return an interned object for this opcode
087: static ActionReplacement make(byte opcode) {
088: ActionReplacement object = array[opcodeIndex(opcode)];
089: if (object == null)
090: object = new ActionReplacement(opcode);
091: return object;
092: }
093:
094: // instance implementation
095: protected byte opcode;
096:
097: // The java serializer calls this. It has to be public.
098: public ActionReplacement() {
099: }
100:
101: protected ActionReplacement(byte opcode) {
102: assert array[opcodeIndex(opcode)] == null;
103: this .opcode = opcode;
104: array[opcodeIndex(opcode)] = this ;
105: }
106:
107: public void writeExternal(ObjectOutput out) throws IOException {
108: out.write(this .opcode);
109: }
110:
111: public void readExternal(ObjectInput in) throws IOException {
112: this .opcode = (byte) in.read();
113: }
114:
115: public Object readResolve() throws ObjectStreamException {
116: return Actions.find(this .opcode);
117: }
118: }
119:
120: public static Action NONE = new Action("NONE", (byte) 0x00, 0, 0);
121: public static Action NextFrame = new Action("NextFrame",
122: (byte) 0x04);
123: public static Action PreviousFrame = new Action("PreviousFrame",
124: (byte) 0x05);
125: public static Action PLAY = new Action("PLAY", (byte) 0x06);
126: public static Action STOP = new Action("STOP", (byte) 0x07);
127: public static Action ToggleQuality = new Action("ToggleQuality",
128: (byte) 0x08);
129: public static Action StopSounds = new Action("StopSounds",
130: (byte) 0x09);
131: public static Action NumericAdd = new Action("NumericAdd",
132: (byte) 0x0A, 2, 1);
133: public static Action SUBTRACT = new Action("SUBTRACT", (byte) 0x0B,
134: 2, 1);
135: public static Action MULTIPLY = new Action("MULTIPLY", (byte) 0x0C,
136: 2, 1);
137: public static Action DIVIDE = new Action("DIVIDE", (byte) 0x0D, 2,
138: 1);
139: public static Action OldEquals = new Action("OldEquals",
140: (byte) 0x0E, 2, 1);
141: public static Action OldLessThan = new Action("OldLessThan",
142: (byte) 0x0F, 2, 1);
143: public static Action LogicalAnd = new Action("LogicalAnd",
144: (byte) 0x10, 2, 1);
145: public static Action LogicalOr = new Action("LogicalOr",
146: (byte) 0x11, 2, 1);
147: public static Action NOT = new Action("NOT", (byte) 0x12, 1, 1);
148: public static Action StringEqual = new Action("StringEqual",
149: (byte) 0x13, 2, 1);
150: public static Action StringLength = new Action("StringLength",
151: (byte) 0x14, 1, 1);
152: public static Action SUBSTRING = new Action("SUBSTRING",
153: (byte) 0x15);
154: public static Action POP = new Action("POP", (byte) 0x17, 1, 0);
155: public static Action INT = new Action("INT", (byte) 0x18, 1, 1);
156: public static Action GetVariable = new Action("GetVariable",
157: (byte) 0x1C, 1, 1);
158: public static Action SetVariable = new Action("SetVariable",
159: (byte) 0x1D, 2, 0);
160: public static Action SetTargetExpression = new Action(
161: "SetTargetExpression", (byte) 0x20);
162: public static Action StringConcat = new Action("StringConcat",
163: (byte) 0x21, 2, 1);
164: public static Action GetProperty = new Action("GetProperty",
165: (byte) 0x22, 2, 1);
166: public static Action SetProperty = new Action("SetProperty",
167: (byte) 0x23, 3, 0);
168: public static Action DuplicateMovieClip = new Action(
169: "DuplicateMovieClip", (byte) 0x24);
170: public static Action RemoveClip = new Action("RemoveClip",
171: (byte) 0x25);
172: public static Action TRACE = new Action("TRACE", (byte) 0x26, 1, 0);
173: public static Action StartDragMovie = new Action("StartDragMovie",
174: (byte) 0x27);
175: public static Action StopDragMovie = new Action("StopDragMovie",
176: (byte) 0x28);
177: public static Action StringLessThan = new Action("StringLessThan",
178: (byte) 0x29, 2, 1);
179: public static Action RANDOM = new Action("RANDOM", (byte) 0x30, 0,
180: 1);
181: public static Action MBLENGTH = new Action("MBLENGTH", (byte) 0x31,
182: 1, 1);
183: public static Action ORD = new Action("ORD", (byte) 0x32, 1, 1);
184: public static Action CHR = new Action("CHR", (byte) 0x33, 1, 1);
185: public static Action GetTimer = new Action("GetTimer", (byte) 0x34,
186: 0, 1);
187: public static Action MBSUBSTRING = new Action("MBSUBSTRING",
188: (byte) 0x35);
189: public static Action MBORD = new Action("MBORD", (byte) 0x36, 1, 1);
190: public static Action MBCHR = new Action("MBCHR", (byte) 0x37, 1, 1);
191: public static Action GotoFrame = new Action("GotoFrame",
192: (byte) 0x81);
193: public static Action GetUrl = new Action("GetUrl", (byte) 0x83);
194: public static Action WaitForFrame = new Action("WaitForFrame",
195: (byte) 0x8A);
196: public static Action SetTarget = new Action("SetTarget",
197: (byte) 0x8B);
198: public static Action GotoLabel = new Action("GotoLabel",
199: (byte) 0x8C);
200: public static Action WaitForFrameExpression = new Action(
201: "WaitForFrameExpression", (byte) 0x8D);
202: public static Action PUSH = new Action("PUSH", (byte) 0x96, 0, 1);
203: public static Action BRANCH = new Action("BRANCH", (byte) 0x99);
204: public static Action GetURL2 = new Action("GetURL2", (byte) 0x9A,
205: 2, 0);
206: public static Action BranchIfTrue = new Action("BranchIfTrue",
207: (byte) 0x9D);
208: public static Action CallFrame = new Action("CallFrame",
209: (byte) 0x9E);
210: public static Action GotoExpression = new Action("GotoExpression",
211: (byte) 0x9F);
212: /*
213: * Flash 5
214: */
215: public static Action DELETE = new Action("DELETE", (byte) 0x3A, 2,
216: 1); // That's right delete takes 2 args
217: public static Action DELETE2 = new Action("DELETE2", (byte) 0x3B,
218: 1, 1); // and delete2 takes 1 arg
219: public static Action VarEquals = new Action("VarEquals",
220: (byte) 0x3C, 2, 0);
221: public static Action CallFunction = new Action("CallFunction",
222: (byte) 0x3D); // <fn> <#args> ...
223: public static Action RETURN = new Action("RETURN", (byte) 0x3E);
224: public static Action MODULO = new Action("MODULO", (byte) 0x3F, 2,
225: 1);
226: public static Action NEW = new Action("NEW", (byte) 0x40); // <fn> <#args> ...
227: public static Action VAR = new Action("VAR", (byte) 0x41, 1, 0);
228: public static Action InitArray = new Action("InitArray",
229: (byte) 0x42); // <#elts> ...
230: public static Action InitObject = new Action("InitObject",
231: (byte) 0x43); // <#pairs> ...
232: public static Action TypeOf = new Action("TypeOf", (byte) 0x44, 1,
233: 1);
234: public static Action TargetPath = new Action("TargetPath",
235: (byte) 0x45);
236: public static Action ENUMERATE = new Action("ENUMERATE",
237: (byte) 0x46);
238: public static Action ADD = new Action("ADD", (byte) 0x47, 2, 1);
239: public static Action LessThan = new Action("LessThan", (byte) 0x48,
240: 2, 1);
241: public static Action EQUALS = new Action("EQUALS", (byte) 0x49, 2,
242: 1);
243: public static Action ObjectToNumber = new Action("ObjectToNumber",
244: (byte) 0x4A, 1, 1);
245: public static Action ObjectToString = new Action("ObjectToString",
246: (byte) 0x4B, 1, 1);
247: public static Action DUP = new Action("DUP", (byte) 0x4C, 1, 2);
248: public static Action SWAP = new Action("SWAP", (byte) 0x4D, 2, 2);
249: public static Action GetMember = new Action("GetMember",
250: (byte) 0x4E, 2, 1);
251: public static Action SetMember = new Action("SetMember",
252: (byte) 0x4F, 3, 0);
253: public static Action Increment = new Action("Increment",
254: (byte) 0x50, 1, 1);
255: public static Action Decrement = new Action("Decrement",
256: (byte) 0x51, 1, 1);
257: public static Action CallMethod = new Action("CallMethod",
258: (byte) 0x52); // <meth> <obj> <#args> ...
259: public static Action NewMethod = new Action("NewMethod",
260: (byte) 0x53); // <meth> <obj> <//args> ...
261: public static Action BitwiseAnd = new Action("BitwiseAnd",
262: (byte) 0x60, 2, 1);
263: public static Action BitwiseOr = new Action("BitwiseOr",
264: (byte) 0x61, 2, 1);
265: public static Action BitwiseXor = new Action("BitwiseXor",
266: (byte) 0x62, 2, 1);
267: public static Action ShiftLeft = new Action("ShiftLeft",
268: (byte) 0x63, 2, 1);
269: public static Action ShiftRight = new Action("ShiftRight",
270: (byte) 0x64, 2, 1);
271: public static Action UShiftRight = new Action("UShiftRight",
272: (byte) 0x65, 2, 1);
273: public static Action SetRegister = new Action("SetRegister",
274: (byte) 0x87, 1, 1);
275: public static Action CONSTANTS = new Action("CONSTANTS",
276: (byte) 0x88);
277: public static Action WITH = new Action("WITH", (byte) 0x94);
278: public static Action DefineFunction = new Action("DefineFunction",
279: (byte) 0x9B);
280:
281: /*
282: * Flash 6
283: */
284: public static Action InstanceOf = new Action("InstanceOf",
285: (byte) 0x54, 2, 1);
286: public static Action EnumerateValue = new Action("EnumerateValue",
287: (byte) 0x55);
288: public static Action StrictEquals = new Action("StrictEquals",
289: (byte) 0x66, 2, 1);
290: public static Action GreaterThan = new Action("GreaterThan",
291: (byte) 0x67, 2, 1);
292: public static Action StringGreaterThan = new Action(
293: "StringGreaterThan", (byte) 0x68, 2, 1);
294: public static Action StrictMode = new Action("StrictMode",
295: (byte) 0x89, 0, 0);
296:
297: /*
298: * Flash 7
299: */
300: public static Action CAST = new Action("CAST", (byte) 0x2b);
301: public static Action IMPLEMENTS = new Action("IMPLEMENTS",
302: (byte) 0x2c);
303: public static Action EXTENDS = new Action("EXTENDS", (byte) 0x69);
304: public static Action DefineFunction2 = new Action(
305: "DefineFunction2", (byte) 0x8e);
306: public static Action TRY = new Action("TRY", (byte) 0x8f);
307: public static Action THROW = new Action("THROW", (byte) 0x2a, 1, 0);
308:
309: /*
310: * Flash Lite 2
311: */
312: public static Action FSCommand2 = new Action("FsCommand2",
313: (byte) 0x2d);
314: }
|