https://github.com/fuellabs/fasm
A mini Fuel Assembly language.
https://github.com/fuellabs/fasm
assembly compiler fasm fuel language
Last synced: 3 months ago
JSON representation
A mini Fuel Assembly language.
- Host: GitHub
- URL: https://github.com/fuellabs/fasm
- Owner: FuelLabs
- License: mit
- Created: 2025-04-30T05:29:15.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-30T05:30:34.000Z (9 months ago)
- Last Synced: 2025-07-02T14:44:31.199Z (6 months ago)
- Topics: assembly, compiler, fasm, fuel, language
- Language: TypeScript
- Homepage: https://fasm.dev
- Size: 240 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fasm
A mini assembly language for the Fuel Virtual Machine (FuelVM).
## Features
- Lightweight (~350 lines of code) and written in Typescript
- Compiles directly to FuelVM assembly
- Debugging information included
- Clean errors with line numbers
- Simplistic syntax and grammar
- Supports:
- Single line comments
- Static and relative jump labels
- Data management
- Error code and error mangement
- Custom register labeling and management
- Basic equality (largely for visbility)
- All FuelVM opcodes
- Supportive dictionaries (gm, gtf, reserved registers)
- Meant as a learning tool for Fuel, the FuelVM and for improving the performance of Sway
- Open Source under MIT
## Example:
```bash
# FASM example
# Loop 5 times, add 1 to index, then log gm, gtf codes and my_data, then return 1
reg.max = movi 5
.loop
reg.index = addi reg.index 1
jnei reg.index reg.max .loop.rel
# Log gm.tx_start code, gtf.tx_length code, my_data and return 1
reg.data_start = addi reg.is data.my_data.start
reg.data_length = movi data.my_data.len
logd gm.tx_start gtf.tx_length reg.data_start reg.data_length
ret reg.one
my_data: 0xabcdef
second_data: 0x0011223344
```
## FASM Language Rules
```
Comments: # My Comment
Jump label: .my_label
Relative jump label: .my_label.rel
Data start pointer: data.my_data.start # program length + data position
Data length pointer: data.my_data.len
Data end pointer: data.my_data.end # program length + data position + data len
Total Data length: data.len
Reserved registers: reg.zero, reg.one, reg.is
Errors: error.my_error # first use assigns, secondary use references, starts from 0 and counts up
Custom register labeling: reg.my_new_reg # first use assigns, secondary use refers, starts at 16 (up to 64)
Custom register equality assignment: reg.max = movi 5 # is the same as movi reg.max 5
```
To install dependencies:
```bash
bun install
```
To build:
```bash
bun run build
```
To test:
```bash
bun test
```
## Browser
There is an editor included in the fasm.dev.
Features:
- Code examples
- Auto complete
- Syntax highlighting
- ACE configurations
- Output Console
This can be run locally using a simple server:
```bash
bun run build
python3 -m http.server 8080
# Go to http://localhost:8080/fast.dev/
```
## API
The primary API exports the `compile` function below:
```
export function compile(input: string = ""): CompileResult
```
## Grammar File
This repo comes with a complete ACE grammar file:
```bash
./grammar/grammar.json
```
## Compiler Design
- A single function written in TS
- Does multiple passes (likely 4-6)
- Is designed around single code line grammar
- Designed to work around the FuelVM opcodes directly
- Register and error manager just counts up (no free pointer logic just yet)
- Max 48 custom registers can be assigned
## Contributors
- Special thanks to the Fuel Client team and the Fuel Typescript team
## Todo
- More tests