Bytecode Linker v5
Bytecode Linker v5
Link multiple module bytecode blobs into a single Bytecode program.
Function signature
func Link(mods []ModuleBytecode) (Bytecode, error)
Types
ModuleBytecodehasName,Imports,Exports,Bytecode.BytecodehasMain []InstrandFunctions []Function.FunctionhasID,Name,Params,Code []Instr.InstrhasOp,Int,Str.
Rules
- Module names must be unique.
mainmust exist and be last in the slice.- Each import must reference an earlier module by name.
- Unknown module:
unknown module: <name> - Import of future module:
import of future module: <name>
- Unknown module:
Linking steps
- Validate module order and imports.
- Merge function tables with ID rebasing.
- Patch every
MAKE_CLOSUREinstruction to the rebased ID. - Concatenate module
Maincode in order.
Notes
- Preserve module order from the input.
- Return the first error encountered.
- Keep the linker readable and straightforward.
Run tests to see results
No issues detected