An open API service indexing awesome lists of open source software.

https://github.com/slince/hello-vm

一个超级mini的栈式虚拟机
https://github.com/slince/hello-vm

stack vm

Last synced: about 1 month ago
JSON representation

一个超级mini的栈式虚拟机

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));
}
}
```
这很酷!