https://github.com/slince/hello-vm
一个超级mini的栈式虚拟机
https://github.com/slince/hello-vm
stack vm
Last synced: about 1 month ago
JSON representation
一个超级mini的栈式虚拟机
- Host: GitHub
- URL: https://github.com/slince/hello-vm
- Owner: slince
- Created: 2022-12-07T04:34:21.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T11:23:04.000Z (almost 3 years ago)
- Last Synced: 2025-01-17T22:29:26.921Z (9 months ago)
- Topics: stack, vm
- Language: Java
- Homepage:
- Size: 60.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hello-vm
一个只支持三个指令的超级mini的虚拟机# 用法
```java
package org.slince.hellovm;import java.util.List;
public class Main {
public static void main(String[] args) {
VirtualMachine vm = new VirtualMachine();
List instructions = List.of(
new VirtualMachine.Instruction("push", 1), // 常量入栈
new VirtualMachine.Instruction("push", 2), // 常量入栈
new VirtualMachine.Instruction("add", null), // 栈上加法
new VirtualMachine.Instruction("push", 5), // 入栈
new VirtualMachine.Instruction("sub", null) // 栈上减法
);
// 以上指令相当于 1 + 2 - 5 ; 输出-2
System.out.println(vm.execute(instructions));
}
}
```
这很酷!