P-Code VM is an educational virtual machine and debugger plugin for IntelliJ IDEA. It helps students explore compiler-generated intermediate code, stack-based execution, method calls, and recursion.
Install P-Code VM from the JetBrains Marketplace
- P-Code syntax highlighting for
.pcodefiles - Execute P-Code programs from the editor
- Step through execution one instruction at a time
- Inspect the operand stack, symbol table, call stack, and runtime frames
- Explore method calls, recursion, and return values
- Install P-Code VM from the JetBrains Marketplace in IntelliJ IDEA.
- Create or open a file with the
.pcodeextension. - Add a P-Code program, such as the example below.
- Right-click in the editor and select Execute P-Code to run the program, or Step P-Code to advance instruction by instruction.
- Use the P-Code Console tool window to inspect execution and runtime state.
The editor actions also have default shortcuts: F5 for execution and F10 for stepping. Shortcut availability may depend on your IDE keymap.
This P-Code program computes the factorial of 5:
factorial-int,method,global,1
n,int,factorial-int,0
#P,label,global,15
#E1,label,global,8
@
STO n,0
LOD n,0
LIT 1,0
OPR 15,0
JMC #E1,false
LIT 1,0
OPR 1,0
LOD n,0
LOD n,0
LIT 1,0
OPR 3,0
CAL factorial-int,0
OPR 4,0
OPR 1,0
LIT 5,0
CAL factorial-int,0
OPR 21,0
OPR 0,0
Expected output:
120
- Instruction Set โ P-Code instructions and their meaning
- Runtime Model โ How program execution and runtime state work
- Sample Programs โ Additional examples for learning and experimentation
P-Code VM is intended for compiler construction and programming language courses. It provides a way to observe how intermediate instructions are executed, how calls and returns work, and how recursion affects runtime state.
