A mini assembly language for the Fuel Virtual Machine (FuelVM).
- 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
# 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: 0x0011223344Comments: # 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:
bun installTo build:
bun run buildTo test:
bun testThere 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:
bun run build
python3 -m http.server 8080
# Go to http://localhost:8080/fast.dev/The primary API exports the compile function below:
export function compile(input: string = ""): CompileResult
This repo comes with a complete ACE grammar file:
./grammar/grammar.json- 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
- Special thanks to the Fuel Client team and the Fuel Typescript team
- More tests