uk.ac.man.cs.rainbow.simulator
Class Instruction

java.lang.Object
  |
  +--uk.ac.man.cs.rainbow.simulator.Instruction
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Abs, BranchFalse, BranchTrue, BuildList, Call, Comment, Concat, DeclareDeviceWithState, Delay, Dup, Eql, Error, Exch, Exit, Get, GetArg, GetType, Index, Insert, Instruction.MACRO, IsAvailable, Jump, KillStackRange, LabelChannel, LabelDevice, Length, Line, Load, MakeChannel, MakeList, MakeRegister, MakeUnion, NDChoice, NDValue, Neg, Neq, Noop, Not, OpenUnion, Parallel, Pop, Project, Push, Put, PutArg, RASM.Abs, RASM.Add, RASM.And, RASM.BinaryIntFunction, RASM.BinaryLogicFunction, RASM.BranchFalse, RASM.BranchTrue, RASM.BuildList, RASM.Call, RASM.ChannelBox, RASM.Comment, RASM.Comparison, RASM.Concat, RASM.DeclareDeviceWithState, RASM.Delay, RASM.Div, RASM.Dup, RASM.Eql, RASM.Error, RASM.Exch, RASM.Exit, RASM.Geq, RASM.Get, RASM.GetArg, RASM.GetType, RASM.Gt, RASM.Index, RASM.Insert, RASM.IsAvailable, RASM.Jump, RASM.KillStackRange, RASM.LabelChannel, RASM.LabelDevice, RASM.Length, RASM.Leq, RASM.Line, RASM.Load, RASM.Lt, RASM.MakeChannel, RASM.MakeList, RASM.MakeRegister, RASM.MakeUnion, RASM.Mod, RASM.Mult, RASM.NDChoice, RASM.NDValue, RASM.Neg, RASM.Neq, RASM.Noop, RASM.Not, RASM.OpenUnion, RASM.Or, RASM.Parallel, RASM.Pop, RASM.Project, RASM.Push, RASM.Put, RASM.PutArg, RASM.Release, RASM.Return, RASM.Roll, RASM.SetType, RASM.Shl, RASM.Shr, RASM.Shrz, RASM.SignalForward, RASM.Sleep, RASM.Split, RASM.StatelessDevice, RASM.StaticStackBase, RASM.Store, RASM.Sub, RASM.TclExec, RASM.WaitRelease, RASM.Xor, Return, Roll, SetType, Sleep, Split, StatelessDevice, StaticStackBase, Store, TclExec

public abstract class Instruction
extends Object
implements Serializable

Superclass of all RASM instructions.

All constructors for any subclass of this class come in pairs: with and without a terminating RASMCode argument. Where the argument is supplied, the instruction will be automatically appended to the given code block during construction. This makes it easier to generate a sequence of instructions.

See Also:
RASMCode, RASMThread, RASM, Serialized Form

Inner Class Summary
static class Instruction.MACRO
          Instructions implemented in terms of other instructions must be subclasses of this class.
 
Constructor Summary
Instruction()
          Create a new instruction.
Instruction(RASMCode code)
          Automatically append this instruction to the given code block.
 
Method Summary
protected static void addClass(String name, Class clazz)
          Define an instruction so it can be looked up by name.
protected abstract  boolean execute(RASMThread t)
          Make this instruction execute in the given context.
static Instruction getInstruction(String name)
          Get a no-arg instruction instance.
static Instruction getInstruction(String name, Object arg)
          Get a one-arg instruction instance.
static Instruction getInstruction(String name, Object arg, RASMCode code)
          Get a two-arg instruction instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Instruction

public Instruction()
Create a new instruction.

Instruction

public Instruction(RASMCode code)
Automatically append this instruction to the given code block.
Method Detail

execute

protected abstract boolean execute(RASMThread t)
                            throws RainbowException
Make this instruction execute in the given context.
Throws:
RainbowException - All sorts of things can go wrong during execution...

addClass

protected static void addClass(String name,
                               Class clazz)
Define an instruction so it can be looked up by name.

getInstruction

public static Instruction getInstruction(String name)
                                  throws RASMCode.Exception
Get a no-arg instruction instance.
Parameters:
name - The name of instruction to get an instance of. The instruction will not need any arguments passing to its constructor.
Throws:
RASMCode.Exception - If the instruction cannot be instantiated for some reason (e.g. if it requires an argument, or if it doesn't exist.)

getInstruction

public static Instruction getInstruction(String name,
                                         Object arg)
                                  throws RASMCode.Exception
Get a one-arg instruction instance.
Parameters:
name - The name of instruction to get an instance of. The instruction will need one argument of the right type in its constructor.
arg - The argument to pass to the constructor.
Throws:
RASMCode.Exception - If the instruction cannot be instantiated for some reason (e.g. if there is an argument mismatch, or if it doesn't exist.)

getInstruction

public static Instruction getInstruction(String name,
                                         Object arg,
                                         RASMCode code)
                                  throws RASMCode.Exception
Get a two-arg instruction instance.
Parameters:
name - The name of instruction to get an instance of. The instruction will need two arguments of the right types in its constructor.
arg - The first argument to pass to the constructor.
code - The second argument to pass to the constructor. Will always be a code block where this method is legal at all.)
Throws:
RASMCode.Exception - If the instruction cannot be instantiated for some reason (e.g. if there is an argument mismatch, or if it doesn't exist.)