cache: document invoke/return some, add beginning of lvt to interpreter

This commit is contained in:
Adam
2017-05-21 17:03:21 -04:00
parent 82fcdb9506
commit 4f14eebd9d
8 changed files with 134 additions and 2 deletions

View File

@@ -58,7 +58,7 @@ public class Instructions
// 37 - pops strings eq to int operand, pushes 1 string
add(Opcodes.POP_INT, "pop_int", 1, 0);
add(Opcodes.POP_STRING, "pop_string", 0, 0, 1, 0);
// 40 seems to interact with other scripts, variable pops/pushes
// 40 invoke script, variable pops/pushes
add(42, 0, 1);
add(43, 1, 0);
add(44, 1, 0);

View File

@@ -44,7 +44,7 @@ public class Opcodes
public static final int SSTORE = 36;
public static final int POP_INT = 38;
public static final int POP_STRING = 39;
//public static final int INVOKE = 40;
public static final int INVOKE = 40;
public static final int SWITCH = 60;
public static final int WIDGET_PUT_HIDDEN = 1003;
public static final int WIDGET_PUT_SCROLL = 1100;

View File

@@ -32,6 +32,8 @@ public class Frame
private final ScriptDefinition script;
private final Stack intStack;
private final Stack stringStack;
private final Variables intVariables;
private final Variables stringVariables;
private boolean running = true;
int pc;
@@ -42,6 +44,8 @@ public class Frame
this.script = script;
this.intStack = new Stack();
this.stringStack = new Stack();
this.intVariables = new Variables(script.getLocalIntCount());
this.stringVariables = new Variables(script.getLocalStringCount());
}
public Frame(Interpreter interpreter, Frame other)
@@ -50,6 +54,8 @@ public class Frame
this.script = other.script;
this.intStack = new Stack(other.intStack);
this.stringStack = new Stack(other.stringStack);
this.intVariables = new Variables(other.intVariables);
this.stringVariables = new Variables(other.stringVariables);
this.pc = other.pc;
}

View File

@@ -33,6 +33,7 @@ import net.runelite.cache.script.interpreter.instructions.If_ICmpGT;
import net.runelite.cache.script.interpreter.instructions.If_ICmpLE;
import net.runelite.cache.script.interpreter.instructions.If_ICmpLT;
import net.runelite.cache.script.interpreter.instructions.If_ICmpNE;
import net.runelite.cache.script.interpreter.instructions.Invoke;
import net.runelite.cache.script.interpreter.instructions.Jump;
import net.runelite.cache.script.interpreter.instructions.LoadInt;
import net.runelite.cache.script.interpreter.instructions.Return;
@@ -56,6 +57,7 @@ public class InstructionHandlers
add(Opcodes.IF_ICMPGT, new If_ICmpGT());
add(Opcodes.IF_ICMPLE, new If_ICmpLE());
add(Opcodes.IF_ICMPGE, new If_ICmpGE());
add(Opcodes.INVOKE, new Invoke());
add(Opcodes.RETURN, new Return());
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.cache.script.interpreter;
public class VariableContext
{
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.cache.script.interpreter;
import java.util.Arrays;
public class Variables
{
private final VariableContext[] variables;
public Variables(int count)
{
variables = new VariableContext[count];
}
public Variables(Variables other)
{
variables = Arrays.copyOf(other.variables, other.variables.length);
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.cache.script.interpreter.instructions;
import net.runelite.cache.script.interpreter.Frame;
import net.runelite.cache.script.interpreter.InstructionContext;
import net.runelite.cache.script.interpreter.InstructionHandler;
import net.runelite.cache.script.interpreter.ScriptInstruction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Invoke extends InstructionHandler
{
private static final Logger logger = LoggerFactory.getLogger(Invoke.class);
@Override
public void execute(Frame frame, InstructionContext ctx)
{
ScriptInstruction scriptInstruction = ctx.getScriptInstruction();
int scriptToInvoke = scriptInstruction.getIop();
// copy new script's intStackCount/stringStackCount to the new LVT, and pop from caller's stack
logger.warn("Invoke not implemented yet");
}
}

View File

@@ -34,6 +34,8 @@ public class Return extends InstructionHandler
public void execute(Frame frame, InstructionContext ctx)
{
frame.stop();
// restore lvt from calling script. return value is on the stack.
}
}