feat: implement capturable locals realloc
This commit is contained in:
parent
4bfc062aaf
commit
07411f62c8
@ -64,7 +64,8 @@ public class Instruction {
|
||||
GLOB_DEF(0x62),
|
||||
|
||||
STACK_ALLOC(0x70),
|
||||
STACK_FREE(0x71);
|
||||
STACK_REALLOC(0x71),
|
||||
STACK_FREE(0x72);
|
||||
|
||||
private static final HashMap<Integer, Type> types = new HashMap<>();
|
||||
public final int numeric;
|
||||
@ -456,11 +457,14 @@ public class Instruction {
|
||||
return new Instruction(Type.OPERATION, op);
|
||||
}
|
||||
|
||||
public static Instruction stackAlloc(int i) {
|
||||
return new Instruction(Type.STACK_ALLOC, i);
|
||||
public static Instruction stackAlloc(int n) {
|
||||
return new Instruction(Type.STACK_ALLOC, n);
|
||||
}
|
||||
public static Instruction stackFree(int i) {
|
||||
return new Instruction(Type.STACK_FREE, i);
|
||||
public static Instruction stackRealloc(int n) {
|
||||
return new Instruction(Type.STACK_REALLOC, n);
|
||||
}
|
||||
public static Instruction stackFree(int n) {
|
||||
return new Instruction(Type.STACK_FREE, n);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
|
@ -505,7 +505,15 @@ public class InstructionRunner {
|
||||
int n = instr.get(0);
|
||||
|
||||
for (var i = 0; i < n; i++) frame.locals.add(new Value[] { Value.UNDEFINED });
|
||||
|
||||
|
||||
frame.codePtr++;
|
||||
return null;
|
||||
}
|
||||
private static Value execStackRealloc(Environment env, Instruction instr, Frame frame) {
|
||||
int n = instr.get(0);
|
||||
|
||||
for (var i = frame.locals.size() - n; i < frame.locals.size(); i++) frame.locals.set(i, new Value[] { frame.locals.get(i)[0] });
|
||||
|
||||
frame.codePtr++;
|
||||
return null;
|
||||
}
|
||||
@ -576,6 +584,7 @@ public class InstructionRunner {
|
||||
case GLOB_SET: return exexGlobSet(env, instr, frame);
|
||||
|
||||
case STACK_ALLOC: return execStackAlloc(env, instr, frame);
|
||||
case STACK_REALLOC: return execStackRealloc(env, instr, frame);
|
||||
case STACK_FREE: return execStackFree(env, instr, frame);
|
||||
|
||||
default: throw EngineException.ofSyntax("Invalid instruction " + instr.type.name() + ".");
|
||||
|
Loading…
Reference in New Issue
Block a user