1
0
Fork 0
forked from fun/fun
fun/docs/bytecode-format.md

29 lines
1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bytecode Format (Overview)
This document summarizes the Fun bytecode format. For deep VM details, see `docs/internals.md`.
## Goals
- Compact representation for fast loading and dispatch
- Stable header with room for versioning
## File layout (typical)
1. Header
- Magic number / signature
- Format version
- Flags (endianness, feature bits)
- Offsets to sections
2. Constants table
- Literals: numbers, strings, compound constants
3. Code section
- Functions/procedures with instruction streams
- Line/column mapping (optional for debugging)
4. Auxiliary tables
- Imports/exports, names, debug info (optional)
## Instructions
- Fixed-size or small-variant opcodes grouped by domain (math, logic, stack, call, control flow, etc.).
- Operands encoded inline following the opcode (width varies by instruction).
## Versioning and compatibility
- The headers version field allows the VM to refuse or translate older/newer formats.
- Keep additions backward-compatible when possible by appending sections or flags.