View Javadoc

1   package com.tapina.robe.runtime.instruction;
2   
3   import java.lang.reflect.Method;
4   import java.io.Writer;
5   import java.io.IOException;
6   
7   import com.tapina.robe.runtime.*;
8   import com.tapina.robe.swi.SWIDecoder;
9   
10  /***
11   * Created by IntelliJ IDEA.
12   * User: gareth
13   * Date: Aug 21, 2003
14   * Time: 6:59:44 PM
15   */
16  public final class SWI extends Instruction {
17      private Method method;
18      private final boolean generateErrors;
19      public static final int X_BIT = 0x20000;
20  
21      public SWI(Condition condition, int swiNumber) throws UnknownSWIException {
22          super(condition);
23          this.generateErrors = (swiNumber & X_BIT) == 0;
24          swiNumber &= 0x7dffff;
25          try {
26              this.method = SWIDecoder.decode(swiNumber);
27          } catch (NoSuchMethodException e) {
28              throw new UnknownSWIException(swiNumber);
29          }
30      }
31  
32      protected final boolean execute(Environment environment) {
33          environment.dispatchSwi(method, generateErrors);
34          return false;
35      }
36  
37      public void dumpJavaSourceUnconditional(Writer out) throws IOException {
38          out.write("env.dispatchSwi(");
39          out.write(method.getClass().getName());
40          out.write(".class.getMethod(\"");
41          out.write(method.getName());
42          out.write("\", SWIHandler.METHOD_PARAMETERS), ");
43          out.write(String.valueOf(generateErrors));
44          out.write(");\n");
45      }
46  
47      public final String toString() {
48          final String className = method.getDeclaringClass().getName();
49          return "SWI " + className.substring(className.lastIndexOf('.') + 1) + "." + method.getName();
50      }
51  }