https://github.com/fernandothedev/fiber
Minimalist VM
https://github.com/fernandothedev/fiber
compiler dlang intermediate-representation vitual-machine vm
Last synced: 3 months ago
JSON representation
Minimalist VM
- Host: GitHub
- URL: https://github.com/fernandothedev/fiber
- Owner: FernandoTheDev
- License: mit
- Created: 2025-08-24T19:29:41.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2025-09-06T22:04:08.000Z (4 months ago)
- Last Synced: 2025-09-07T00:09:38.891Z (4 months ago)
- Topics: compiler, dlang, intermediate-representation, vitual-machine, vm
- Language: D
- Homepage:
- Size: 3.22 MB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fiber
Fiber is a custom-built virtual machine (VM) and compiler toolchain, designed from scratch with a focus on high-speed and optimized bytecode execution.
---
## The Architecture
Fiber utilizes a custom intermediate representation (IR), which allows for seamless integration with APIs from other programming languages. These APIs can generate the Fiber-IR, and the Fiber compiler can then automatically compile and execute the code.
### Key Design Principles
* **Memory-to-Memory Architecture:** The VM operates directly on memory addresses, eliminating the overhead of a register-based system for a cleaner, more efficient design.
* **High Performance:** The entire toolchain achieves ultra-low execution times, with compilation and VM execution measured in microseconds.
* **Bytecode Compression:** Drastically reduces the size of compiled binaries for faster distribution and loading.
---
## Getting Started
### Prerequisites
* A D compiler (DMD, LDC, or GDC).
* Dub
### Building
```bash
# Clone the repository
git clone https://github.com/fernandothedev/fiber.git
# Navigate to the project directory
cd fiber
# Build the project using dub
dub build --build=release
```
### Usage
```bash
# Compile and run a source file
./fiber your_program.fir
# Compile a source file to bytecode
./fiber -o your_program.bc your_program.fir
# Run a pre-compiled bytecode file
./fiber your_program.bc
# Enable debug mode to see compilation steps
./fiber -d your_program.fir
# Show execution statistics
./fiber -s your_program.fir
```
### Example
The following code is compiled and executed by Fiber.
```llvm
.main {
x: int = 60
$0: int;
store $0, 9
$1: int;
add $1, $0, x
print $1
halt
}
```
With function calls:
```llvm
.main
{
$0: int;
main_x: int = 60
main_y: int = 9
call sum(int main_x, int main_y), $0
print $0
halt
}
fn sum (sum_x, sum_y) int {
sum_0: int;
add sum_0, sum_x, sum_y
ret sum_0
}
```
Compile and run
```bash
❯ ./fiber examples/hard.fir
69
```
Or view the generated bytecode
```bash
❯ ./fiber examples/hard.fir -o hard.bc
Program saved to: hard.bc
Compression: 541 -> 32 tokens (5.9%)
❯ cat hard.bc
FIBERBC 26 512 70 101 114 110 97 110 100 111 68 101 118 6 1 9 1 2 1 0 7 2 12 70 105 98 101 114 MEMORY 60 F511
```