Documentation
¶
Overview ¶
Package aot is the build-time ahead-of-time compiler: it lowers a method's bytecode ISeq to Go source, which the Go toolchain then compiles to native code. This is the "level-1" form — sound and unspecialised: every operator still goes through vm.binaryOp and every non-self send through vm.dispatchSend, so the generated code's semantics are identical to the interpreter, while the bytecode dispatch loop, operand-stack heap traffic and per-instruction overhead are gone. A method using an opcode or constant this stage cannot lower is simply left to the interpreter (Compile returns ok=false).
Index ¶
- func Compile(iseq *bytecode.ISeq, goName, rubyName string) (string, bool)
- func CompileMain(top *bytecode.ISeq) (fnSrc string, nCaches int, ok bool)
- func CompileProgram(top *bytecode.ISeq) (content string, keys []string, ok bool)
- func CompileSpecialized(iseq *bytecode.ISeq, goName, rubyName string) (string, bool)
- func FreezeISeq(iseq *bytecode.ISeq, pkg, fn, buildTag string) string
- func FrontendUses(top *bytecode.ISeq) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
Compile emits the Go source of a `func (vm *VM) <goName>(self object.Value, args []object.Value) object.Value` that runs iseq. rubyName is the method's own Ruby name, so a self-send to it becomes a direct recursive call to goName. ok is false when the body uses something this stage does not lower yet, in which case the caller keeps interpreting that method.
func CompileMain ¶
CompileMain lowers the program's top-level ISeq to `func (vm *VM) aotMain() object.Value`, plus the `nCaches` inline-cache slots its send sites need. ok is false when the top level uses a construct this stage does not lower, in which case the caller keeps interpreting the whole program.
func CompileProgram ¶
CompileProgram lowers the top-level methods of a program to a single Go source file (package vm) that `rbgo build` links into the binary: one function per compilable method plus an init() registering each with the dispatch seam (RegisterCompiled). Methods this stage cannot lower — and any redefinition of a name already taken — are skipped and left to the interpreter.
It handles methods defined at the top level (owner Object); methods inside class/module bodies are not walked yet and remain interpreted. ok is false when nothing could be compiled, so the caller can build a plain binary.
func CompileSpecialized ¶
CompileSpecialized tries to lower iseq as a level-3 "integer kernel": when the whole body is integer arithmetic/comparison on Integer parameters (with self-recursion and integer constants), it emits three functions —
<goName>_l1 the sound level-1 body (the universal fall-back)
<goName>_k the unboxed int64 kernel (the fast path)
<goName> a boxed entry that guards the args are Integer and recovers a
kernel deopt (overflow / divide-by-zero), re-running via _l1
so the registered entry runs entirely on int64 in the common case and remains correct for every input. ok is false when the body is not a pure integer kernel, leaving the caller to use the level-1 Compile.
func FreezeISeq ¶
FreezeISeq returns the Go source of a self-contained file that reconstructs iseq — with no lexer, parser or compiler — as `func fn() *bytecode.ISeq`. It is how a closed-world binary embeds its program (and the prelude): the compiled bytecode is baked in as Go literals, so the front-end can be dropped from the link.
pkg is the package clause; fn the constructor name; buildTag, when non-empty, is emitted as a `//go:build <tag>` constraint. The output is gofmt-clean (it is run through go/format); a formatting failure indicates a serializer bug and surfaces as the raw, unformatted source so the eventual build fails loudly.
Only the constant kinds the compiler ever pools — Integer, Bignum, Float, String and Symbol — are supported; any other value type is a programming error and panics, since it could not have come from a real compilation.
func FrontendUses ¶
FrontendUses scans a compiled program (the top-level ISeq and every nested method/class/block body) for calls to front-end-dependent methods, returning their names sorted and de-duplicated. `rbgo build --closed` reports these so the user knows which calls would raise in the closed binary.
It is a name-level scan (the selectors a send could target), deliberately conservative: it cannot tell `obj.eval` from `Kernel#eval`, so it may over-report, but it never misses a literal use.
Types ¶
This section is empty.