Compiler/virtual machine interpreter: Difference between revisions
m
Minor improvement to coding.
(New post.) |
m (Minor improvement to coding.) |
||
Line 8,426:
public static void main(String[] args) throws IOException {
Path
VirtualMachineInfo info = loadCode(
runVirtualMachine(info.dataSize, info.vmStrings, info.codes());
}
Line 8,439:
int index = 0;
while ( opCode !=
opCode =
index += 1;
Line 8,458:
case NE -> stack.set(stack.size() - 2, ( stack.get(stack.size() - 2) != stack.pop() ) ? 1 : 0);
case AND -> { final int value = ( stack.get(stack.size() - 2) != 0 && stack.pop() != 0 ) ? 1 : 0;
}
case OR -> { final int value = ( stack.get(stack.size() - 2) != 0 || stack.pop() != 0 ) ? 1 : 0;
Line 8,478:
}
private static VirtualMachineInfo loadCode(Path
List<String> lines = Files.readAllLines(
String line = lines.getFirst();
Line 8,502:
sections = lines.get(i).trim().split("\\s+");
offset = Integer.parseInt(sections[0]);
codes.addLast(opCode.byteCode());
Line 8,518:
private static int operand(int index, List<Byte> codes) {
for ( int i = index; i < index + 4; i++ ) {
}
return
}
private static void addToCodes(int number, List<Byte> codes) {
for ( byte bb :
codes.addLast(bb);
}
Line 8,557:
}
private static ByteBuffer
private static enum
HALT(0), ADD(1), SUB(2), MUL(3), DIV(4), MOD(5), LT(6), GT(7), LE(8), GE(9), EQ(10), NE(11),
Line 8,569:
}
public static
return op_codes[(int) byteCode];
}
private
byteCode = aByteCode;
}
Line 8,579:
private int byteCode;
private static
}
|