KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > sc > Actions


1 /***
2  * Actions.java
3  */

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.sc;
11 import java.io.*;
12 import java.util.*;
13
14 /*
15  * Single-word instructions are CAPS (to minimize the chance of
16  * collisions with client names). Multi-word instructions are
17  * CamelCase.
18  *
19  * Names (modulo case) are intended to be the same as those used by
20  * flasm. This aids debugging, and will also insure that the inline
21  * assembler assembles the same language as flasm, when this is added.
22  * There are probably some names that don't yet match flasm, especially
23  * outside the Flash 5 opcode set.
24  */

25
26 /***
27  * Information about ActionScript bytecodes
28  * -1 for arity or returns means "don't know"
29  */

30 public class Actions {
31     protected static final int ACTIONS_SIZE = 256;
32     /* name -> Action */
33     public static final HashMap actions = new HashMap();
34     protected static Action[] actionArray = new Action[ACTIONS_SIZE];
35     
36     /* Returns set of Action */
37     public static Set items() {
38         return actions.entrySet();
39     }
40     
41     static final int opcodeIndex(byte opcode) {
42         return (int) opcode - (int) java.lang.Byte.MIN_VALUE;
43     }
44     
45     protected static Action find(byte opcode) {
46         Action action = actionArray[opcodeIndex(opcode)];
47         if (action == null) throw new RuntimeException JavaDoc("null action");
48         return action;
49     }
50     
51     public static class Action implements Serializable {
52         public final String JavaDoc name;
53         public final byte opcode;
54         public final boolean args;
55         public final int arity;
56         public final int returns;
57         
58         public Action(String JavaDoc name, byte opcode) {
59             this(name, opcode, -1, -1);
60         }
61         
62         public Action(String JavaDoc name, byte opcode, int arity, int returns) {
63             this(name, opcode, arity, returns, (opcode & 0x80) != 0);
64         }
65         
66         public Action(String JavaDoc name, byte opcode, int arity, int returns, boolean args) {
67             super();
68             this.name = name;
69             this.opcode = opcode;
70             this.args = args;
71             this.arity = arity;
72             this.returns = returns;
73             assert actions.get(name) == null;
74             actions.put(name, this);
75             int index = opcodeIndex(opcode);
76             assert actionArray[index] == null;
77             actionArray[index] = this;
78         }
79         
80         public Object JavaDoc writeReplace() {
81             return ActionReplacement.make(this.opcode);
82         }
83     }
84     
85     // This object is used to replace a serialized Action.
86
protected static class ActionReplacement implements Externalizable {
87         // class implementation
88
protected static final ActionReplacement[] array = new ActionReplacement[ACTIONS_SIZE];
89         
90         // return an interned object for this opcode
91
static ActionReplacement make(byte opcode) {
92             ActionReplacement object = array[opcodeIndex(opcode)];
93             if (object == null)
94                 object = new ActionReplacement(opcode);
95             return object;
96         }
97         
98         // instance implementation
99
protected byte opcode;
100         
101         // The java serializer calls this. It has to be public.
102
public ActionReplacement() {
103         }
104         
105         protected ActionReplacement(byte opcode) {
106             assert array[opcodeIndex(opcode)] == null;
107             this.opcode = opcode;
108             array[opcodeIndex(opcode)] = this;
109         }
110         
111         public void writeExternal(ObjectOutput out)
112             throws IOException
113         {
114             out.write(this.opcode);
115         }
116         
117         public void readExternal(ObjectInput in)
118             throws IOException
119         {
120             this.opcode = (byte) in.read();
121         }
122         
123         public Object JavaDoc readResolve() throws ObjectStreamException {
124             return Actions.find(this.opcode);
125         }
126     }
127     
128     public static Action NONE = new Action("NONE", (byte)0x00, 0, 0);
129     public static Action NextFrame = new Action("NextFrame", (byte)0x04);
130     public static Action PreviousFrame = new Action("PreviousFrame", (byte)0x05);
131     public static Action PLAY = new Action("PLAY", (byte)0x06);
132     public static Action STOP = new Action("STOP", (byte)0x07);
133     public static Action ToggleQuality = new Action("ToggleQuality", (byte)0x08);
134     public static Action StopSounds = new Action("StopSounds", (byte)0x09);
135     public static Action NumericAdd = new Action("NumericAdd", (byte)0x0A, 2, 1);
136     public static Action SUBTRACT = new Action("SUBTRACT", (byte)0x0B, 2, 1);
137     public static Action MULTIPLY = new Action("MULTIPLY", (byte)0x0C, 2, 1);
138     public static Action DIVIDE = new Action("DIVIDE", (byte)0x0D, 2, 1);
139     public static Action OldEquals = new Action("OldEquals", (byte)0x0E, 2, 1);
140     public static Action OldLessThan = new Action("OldLessThan", (byte)0x0F, 2, 1);
141     public static Action LogicalAnd = new Action("LogicalAnd", (byte)0x10, 2, 1);
142     public static Action LogicalOr = new Action("LogicalOr", (byte)0x11, 2, 1);
143     public static Action NOT = new Action("NOT", (byte)0x12, 1, 1);
144     public static Action StringEqual = new Action("StringEqual", (byte)0x13, 2, 1);
145     public static Action StringLength = new Action("StringLength", (byte)0x14, 1, 1);
146     public static Action SUBSTRING = new Action("SUBSTRING", (byte)0x15);
147     public static Action POP = new Action("POP", (byte)0x17, 1, 0);
148     public static Action INT = new Action("INT", (byte)0x18, 1, 1);
149     public static Action GetVariable = new Action("GetVariable", (byte)0x1C, 1, 1);
150     public static Action SetVariable = new Action("SetVariable", (byte)0x1D, 2, 0);
151     public static Action SetTargetExpression = new Action("SetTargetExpression", (byte)0x20);
152     public static Action StringConcat = new Action("StringConcat", (byte)0x21, 2, 1);
153     public static Action GetProperty = new Action("GetProperty", (byte)0x22, 2, 1);
154     public static Action SetProperty = new Action("SetProperty", (byte)0x23, 3, 0);
155     public static Action DuplicateMovieClip = new Action("DuplicateMovieClip", (byte)0x24);
156     public static Action RemoveClip = new Action("RemoveClip", (byte)0x25);
157     public static Action TRACE = new Action("TRACE", (byte)0x26, 1, 0);
158     public static Action StartDragMovie = new Action("StartDragMovie", (byte)0x27);
159     public static Action StopDragMovie = new Action("StopDragMovie", (byte)0x28);
160     public static Action StringLessThan = new Action("StringLessThan", (byte)0x29, 2, 1);
161     public static Action RANDOM = new Action("RANDOM", (byte)0x30, 0, 1);
162     public static Action MBLENGTH = new Action("MBLENGTH", (byte)0x31, 1, 1);
163     public static Action ORD = new Action("ORD", (byte)0x32, 1, 1);
164     public static Action CHR = new Action("CHR", (byte)0x33, 1, 1);
165     public static Action GetTimer = new Action("GetTimer", (byte)0x34, 0, 1);
166     public static Action MBSUBSTRING = new Action("MBSUBSTRING", (byte)0x35);
167     public static Action MBORD = new Action("MBORD", (byte)0x36, 1, 1);
168     public static Action MBCHR = new Action("MBCHR", (byte)0x37, 1, 1);
169     public static Action GotoFrame = new Action("GotoFrame", (byte)0x81);
170     public static Action GetUrl = new Action("GetUrl", (byte)0x83);
171     public static Action WaitForFrame = new Action("WaitForFrame", (byte)0x8A);
172     public static Action SetTarget = new Action("SetTarget", (byte)0x8B);
173     public static Action GotoLabel = new Action("GotoLabel", (byte)0x8C);
174     public static Action WaitForFrameExpression = new Action("WaitForFrameExpression", (byte)0x8D);
175     public static Action PUSH = new Action("PUSH", (byte)0x96, 0, 1);
176     public static Action BRANCH = new Action("BRANCH", (byte)0x99);
177     public static Action GetURL2 = new Action("GetURL2", (byte)0x9A, 2, 0, false);
178     public static Action BranchIfTrue = new Action("BranchIfTrue", (byte)0x9D);
179     public static Action CallFrame = new Action("CallFrame", (byte)0x9E);
180     public static Action GotoExpression = new Action("GotoExpression", (byte)0x9F);
181     /*
182      * Flash 5
183      */

184     public static Action DELETE = new Action("DELETE", (byte)0x3A, 2, 1); // That's right delete takes 2 args
185
public static Action DELETE2 = new Action("DELETE2", (byte)0x3B, 1, 1); // and delete2 takes 1 arg
186
public static Action VarEquals = new Action("VarEquals", (byte)0x3C, 2, 0);
187     public static Action CallFunction = new Action("CallFunction", (byte)0x3D); // <fn> <#args> ...
188
public static Action RETURN = new Action("RETURN", (byte)0x3E);
189     public static Action MODULO = new Action("MODULO", (byte)0x3F, 2, 1);
190     public static Action NEW = new Action("NEW", (byte)0x40); // <fn> <#args> ...
191
public static Action VAR = new Action("VAR", (byte)0x41, 1, 0);
192     public static Action InitArray = new Action("InitArray", (byte)0x42); // <#elts> ...
193
public static Action InitObject = new Action("InitObject", (byte)0x43); // <#pairs> ...
194
public static Action TypeOf = new Action("TypeOf", (byte)0x44, 1, 1);
195     public static Action TargetPath = new Action("TargetPath", (byte)0x45);
196     public static Action ENUMERATE = new Action("ENUMERATE", (byte)0x46);
197     public static Action ADD = new Action("ADD", (byte)0x47, 2, 1);
198     public static Action LessThan = new Action("LessThan", (byte)0x48, 2, 1);
199     public static Action EQUALS = new Action("EQUALS", (byte)0x49, 2, 1);
200     public static Action ObjectToNumber = new Action("ObjectToNumber", (byte)0x4A, 1, 1);
201     public static Action ObjectToString = new Action("ObjectToString", (byte)0x4B, 1, 1);
202     public static Action DUP = new Action("DUP", (byte)0x4C, 1, 2);
203     public static Action SWAP = new Action("SWAP", (byte)0x4D, 2, 2);
204     public static Action GetMember = new Action("GetMember", (byte)0x4E, 2, 1);
205     public static Action SetMember = new Action("SetMember", (byte)0x4F, 3, 0);
206     public static Action Increment = new Action("Increment", (byte)0x50, 1, 1);
207     public static Action Decrement = new Action("Decrement", (byte)0x51, 1, 1);
208     public static Action CallMethod = new Action("CallMethod", (byte)0x52); // <meth> <obj> <#args> ...
209
public static Action NewMethod = new Action("NewMethod", (byte)0x53); // <meth> <obj> <//args> ...
210
public static Action BitwiseAnd = new Action("BitwiseAnd", (byte)0x60, 2, 1);
211     public static Action BitwiseOr = new Action("BitwiseOr", (byte)0x61, 2, 1);
212     public static Action BitwiseXor = new Action("BitwiseXor", (byte)0x62, 2, 1);
213     public static Action ShiftLeft = new Action("ShiftLeft", (byte)0x63, 2, 1);
214     public static Action ShiftRight = new Action("ShiftRight", (byte)0x64, 2, 1);
215     public static Action UShiftRight = new Action("UShiftRight", (byte)0x65, 2, 1);
216     public static Action SetRegister = new Action("SetRegister", (byte)0x87, 1, 1);
217     public static Action CONSTANTS = new Action("CONSTANTS", (byte)0x88);
218     public static Action WITH = new Action("WITH", (byte)0x94);
219     public static Action DefineFunction = new Action("DefineFunction", (byte)0x9B);
220     
221     /*
222      * Flash 6
223      */

224     public static Action InstanceOf = new Action("InstanceOf", (byte)0x54, 2, 1);
225     public static Action EnumerateValue = new Action("EnumerateValue", (byte)0x55);
226     public static Action StrictEquals = new Action("StrictEquals", (byte)0x66, 2, 1);
227     public static Action GreaterThan = new Action("GreaterThan", (byte)0x67, 2, 1);
228     public static Action StringGreaterThan = new Action("StringGreaterThan", (byte)0x68, 2, 1);
229     public static Action StrictMode = new Action("StrictMode", (byte)0x89, 0, 0);
230     
231     /*
232      * Flash 7
233      */

234     public static Action CAST = new Action("CAST", (byte)0x2b);
235     public static Action IMPLEMENTS = new Action("IMPLEMENTS", (byte)0x2c);
236     public static Action EXTENDS = new Action("EXTENDS", (byte)0x69);
237     public static Action DefineFunction2 = new Action("DefineFunction2", (byte)0x8e);
238     public static Action TRY = new Action("TRY", (byte)0x8f);
239     public static Action THROW = new Action("THROW", (byte)0x2a);
240 }
241
Popular Tags