- // FEATURE: call() that accepts an Object[] array and automatically allocates strings/arrays/etc on the stack
- public final int call(String sym) throws CallException { return call(sym,0,0,0,0,0,0,0); }
- public final int call(String sym, int a0) throws CallException { return call(sym,a0,0,0,0,0,0,0); }
- public final int call(String sym, int a0, int a1) throws CallException { return call(sym,a0,a1,0,0,0,0,0); }
- public final int call(String sym, int a0, int a1, int a2) throws CallException { return call(sym,a0,a1,a2,0,0,0,0); }
- public final int call(String sym, int a0, int a1, int a2, int a3) throws CallException { return call(sym,a0,a1,a2,a3,0,0,0); }
- public final int call(String sym, int a0, int a1, int a2, int a3, int a4) throws CallException { return call(sym,a0,a1,a2,a3,a4,0,0); }
- public final int call(String sym, int a0, int a1, int a2, int a3, int a4, int a5) throws CallException { return call(sym,a0,a1,a2,a3,a4,a5,0); }
+ public final int call(String sym, Object[] args) throws CallException, FaultException {
+ if(state != PAUSED && state != CALLJAVA) throw new IllegalStateException("call() called in inappropriate state");
+ if(args.length > 7) throw new IllegalArgumentException("args.length > 7");
+ CPUState state = new CPUState();
+ getCPUState(state);
+
+ int sp = state.r[SP];
+ int[] ia = new int[args.length];
+ for(int i=0;i<args.length;i++) {
+ Object o = args[i];
+ byte[] buf = null;
+ if(o instanceof String) {
+ buf = getBytes((String)o);
+ } else if(o instanceof byte[]) {
+ buf = (byte[]) o;
+ } else if(o instanceof Number) {
+ ia[i] = ((Number)o).intValue();
+ }
+ if(buf != null) {
+ sp -= buf.length;
+ copyout(buf,sp,buf.length);
+ ia[i] = sp;
+ }
+ }
+ int oldSP = state.r[SP];
+ if(oldSP == sp) return call(sym,ia);
+
+ state.r[SP] = sp;
+ setCPUState(state);
+ int ret = call(sym,ia);
+ state.r[SP] = oldSP;
+ setCPUState(state);
+ return ret;
+ }
+
+ public final int call(String sym) throws CallException { return call(sym,new int[]{}); }
+ public final int call(String sym, int a0) throws CallException { return call(sym,new int[]{a0}); }
+ public final int call(String sym, int a0, int a1) throws CallException { return call(sym,new int[]{a0,a1}); }