aot

package
v0.0.0-...-aaf2ed9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(iseq *bytecode.ISeq, goName, rubyName string) (string, bool)

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

func CompileMain(top *bytecode.ISeq) (fnSrc string, nCaches int, ok bool)

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

func CompileProgram(top *bytecode.ISeq) (content string, keys []string, ok bool)

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

func CompileSpecialized(iseq *bytecode.ISeq, goName, rubyName string) (string, bool)

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

func FreezeISeq(iseq *bytecode.ISeq, pkg, fn, buildTag string) string

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

func FrontendUses(top *bytecode.ISeq) []string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL