vm-dev

Design and implement bytecode-driven virtual machines with memory management.

34|5|Updated Oct 18, 2020
One-click install
npx skills add https://github.com/whtoo/How_to_implment_PL_in_Antlr4 --skill vm-dev-whtoo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vm-dev
Source: https://github.com/whtoo/How_to_implment_PL_in_Antlr4/tree/main/.claude/skills/vm-dev
Command: npx skills add https://github.com/whtoo/How_to_implment_PL_in_Antlr4 --skill vm-dev-whtoo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

构建与维护高效、可观测的虚拟机需要清晰的字节码定义、栈帧管理和垃圾回收策略。本 Skill 提供关于字节码设计、栈式虚拟机实现和内存管理的操作指南。

Core Features & Use Cases

  • 字节码设计: 定义指令集及操作数栈行为,便于实现跨平台执行。
  • 栈式虚拟机实现: 管理栈帧、局部变量和调用/返回,简化运行时行为。
  • 内存管理/GC: 引入引用计数等回收策略,降低内存泄露风险。
  • 使用场景: EP18 的实现中新增 50+ 指令和 GC,提升执行效率与内存安全。

Quick Start

将新的指令添加到 BytecodeDefinition, 实现对应指令类,并通过 mvn test 验证。

Frequently Asked Questions about vm-dev

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a bytecode instruction set for a virtual machine?

Bytecode design defines the instruction set and operand stack behavior for cross-platform execution. Start by specifying opcodes in BytecodeDefinition, then implement corresponding instruction handlers. This approach simplifies runtime behavior and enables portable execution across different environments.

What's the best way to implement a stack-based virtual machine?

A stack-based VM manages stack frames, local variables, and call/return operations to simplify runtime execution. Define your instruction set, implement stack frame management, and wire instruction handlers to bytecode operations. Use mvn test to validate each new instruction as you add it.

How do I add garbage collection to a virtual machine?

Garbage collection strategies like mark-sweep and reference counting reduce memory leaks in VM execution. Implement object layout specifications, track reachable objects during marking phases, and reclaim unreachable memory. This prevents memory bloat during long-running bytecode execution.

Do I need to implement both stack-based and register-based VMs?

Stack-based VMs are simpler to implement and manage stack frames naturally, while register-based VMs offer performance optimization. This Skill covers both approaches; choose stack-based for clarity and register-based when you need efficiency gains after profiling bytecode execution.

How do I test new opcodes and instruction handlers in a VM?

Add new instructions to BytecodeDefinition, implement their handler logic, then run mvn test to validate behavior. This workflow integrates testing into the development cycle, catching instruction errors early and ensuring memory safety during execution.