A High-Performance Virtual Machine for Delphi
๐ง NitroVM is a Work in Progress
NitroVM is currently under active development and evolving quickly. Some features described in this documentation may be incomplete, experimental, or subject to significant changes as the project matures.
We welcome your feedback, ideas, and issue reports โ your input will directly influence the direction and quality of NitroVM as we strive to build the ultimate modern Pascal development platform.
NitroVM is a high-performance, stack-based virtual machine designed specifically for Delphi applications. It provides a flexible and efficient platform for executing custom bytecode with full type safety and comprehensive error handling.
- ๐ High Performance: Optimized execution engine with separate opcode and operand arrays
- ๐ Stack-Based Architecture: Clean, predictable execution model
- ๐ง Fluent Interface: Chainable method calls for elegant code
- ๐พ Binary Program Format: Efficient loading and saving with checksums
- ๐ก๏ธ Type Safety: Full integration with Delphi's RTTI system
- ๐ฏ Comprehensive Error Handling: Detailed exception information with VM state
- ๐ฆ Extensible Opcode System: Easy registration of custom operations
- ๐ Debug Support: Rich debugging information and step-by-step execution
- Platform: Windows 64-bit
- Compiler: Delphi 12 Athens or higher
- Clone the repository:
git clone https://github.com/tinyBigGAMES/NitroVM.git-
Add the
NitroVM.pasunit to your Delphi project -
Add
NitroVMto your uses clause:
uses
NitroVM;uses
NitroVM;
var
LVM: TNitroVM;
begin
LVM := TNitroVM.Create;
try
// Register custom opcodes
LVM.RegisterOpcode(100, procedure(const AVM: TNitroVM)
begin
// Custom operation without operand
AVM.Push(42);
end);
// Build and execute a program
LVM.BeginProgram
.AddInstruction(100) // Push 42
.AddInstruction(OP_PUSH, 10) // Push 10
.AddInstruction(OP_ADD) // Add: 42 + 10 = 52
.AddInstruction(OP_STOP) // Stop execution
.ExecuteProgram;
// Get result
WriteLn('Result: ', LVM.Pop.AsInteger); // Output: 52
finally
LVM.Free;
end;
end;var
LVM: TNitroVM;
begin
LVM := TNitroVM.Create;
try
// Build program
LVM.BeginProgram
.AddInstruction(OP_PUSH, 100)
.AddInstruction(OP_PUSH, 200)
.AddInstruction(OP_MUL)
.AddInstruction(OP_STOP);
// Save to file
LVM.SaveProgram('myprogram.nvm');
// Load and execute
LVM.Reset
.LoadProgram('myprogram.nvm')
.ExecuteProgram;
WriteLn('Result: ', LVM.Pop.AsInteger); // Output: 20000
finally
LVM.Free;
end;
end;NitroVM uses a stack-based execution model where all operations work with values on the execution stack:
// Stack manipulation
LVM.Push(TValue.From<Integer>(42)) // Push value
.Push(TValue.From<String>('Hello')) // Push string
.Pop(LValue) // Pop into variable
.ClearStack; // Clear all values
// Stack inspection
LSize := LVM.StackSize; // Get current size
LTop := LVM.Peek(0); // Peek at top (index 0)
LSecond := LVM.Peek(1); // Peek at second (index 1)Register custom operations with or without operands:
// Opcode without operand
LVM.RegisterOpcode(200, procedure(const AVM: TNitroVM)
begin
// Duplicate top stack value
AVM.Push(AVM.Peek(0));
end);
// Opcode with operand
LVM.RegisterOpcode(201, procedure(const AVM: TNitroVM; const AOperand: TValue)
begin
// Push the operand value
AVM.Push(AOperand);
end);NitroVM provides comprehensive error information:
try
LVM.ExecuteProgram;
except
on E: ENVMException do
begin
WriteLn('VM Error: ', E.Message);
WriteLn('Debug Info:');
WriteLn(E.GetDebugInfo);
// Shows PC, opcode, stack size, VM state
end;
end;| Opcode | Name | Description |
|---|---|---|
| 0 | OP_NOP | No operation |
| 1 | OP_STOP | Stop execution |
| 2 | OP_ADD | Add two values |
| 3 | OP_SUB | Subtract two values |
| 4 | OP_MUL | Multiply two values |
| 5 | OP_DIV | Divide two values |
| 6 | OP_POP | Pop and discard top value |
| 7 | OP_DUP | Duplicate top value |
| 8 | OP_SWAP | Swap top two values |
| 9 | OP_ROT | Rotate top three values |
| 10 | OP_PUSH | Push operand value |
| 11 | OP_JUMP | Jump to address |
| 12 | OP_CALL | Call subroutine |
| 13 | OP_LOAD | Load from memory |
| 14 | OP_STORE | Store to memory |
| 15 | OP_JZ | Jump if zero |
| 16 | OP_JNZ | Jump if not zero |
NitroVM uses a binary format (.nvm) with the following structure:
Magic: 'NVM1' (4 bytes)
Version: Format version (2 bytes)
Flags: Future use (2 bytes)
CodeSize: Number of opcodes (4 bytes)
DataSize: Number of operands (4 bytes)
EntryPoint: Starting PC (4 bytes)
Checksum: Validation checksum (4 bytes)
Reserved: Future expansion (8 bytes)
- Code Section: Encoded opcodes with operand flags
- Data Section: Type-preserved operands (Integer, Double, Boolean, String)
// Execute one instruction at a time
while LVM.IsRunning and not LVM.IsHalted do
begin
LVM.ExecuteStep;
// Inspect VM state, implement breakpoints, etc.
end;
// Limited execution
LVM.ExecuteUntil(1000); // Execute max 1000 instructions// Fluent interface for program construction
LVM.BeginProgram
.AddInstruction(OP_PUSH, 10)
.AddInstruction(OP_PUSH, 20)
.AddInstruction(OP_ADD)
.AddInstruction(OP_DUP) // Duplicate result
.AddInstruction(OP_PUSH, 2)
.AddInstruction(OP_MUL) // Multiply by 2
.AddInstruction(OP_STOP);// Reset VM to initial state
LVM.Reset;
// Check execution state
if LVM.IsRunning then
WriteLn('VM is executing');
if LVM.IsHalted then
WriteLn('VM was halted');
// Manual control
LVM.Stop; // Force halt- Separate Arrays: Opcodes and operands stored separately for cache efficiency
- Inline Functions: Critical paths use inlined methods
- Minimal Allocations: Efficient memory management with pre-allocated arrays
- Direct Dispatch: Fast opcode handler lookup without virtual calls
Join our growing community of developers building the future of Pascal development!
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
BSD 3-Clause License
Copyright ยฉ 2025-present tinyBigGAMESโข LLC
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice
2. Redistributions in binary form must reproduce the above copyright notice
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
- ๐ Issues: GitHub Issues - Bug reports & feature requests
- ๐ฌ Discussions: GitHub Discussions - General questions & ideas
- ๐ฌ Discord: Join our community - Real-time chat & support
- ๐ฆ Bluesky: @tinybiggames.com - Updates & announcements
- ๐ Built with love for the Delphi community
- ๐ Focused on practical, real-world usage scenarios
- ๐ Committed to enterprise-grade quality and performance
- ๐ Supporting the future of Pascal application development
- Delphi Community - For continued support and feedback
- Beta Testers - Early adopters who helped shape NitroVM
- Contributors - Everyone who has submitted issues, PRs, and improvements
Made with โค๏ธ by tinyBigGAMESโข
NitroVM - Powering the next generation of Delphi applications with high-performance virtual machine technology.
