Documentation
¶
Overview ¶
Package rugaroo compiles a typed subset of Ruby to Go.
Index ¶
- Constants
- Variables
- func Compile(ctx context.Context, mainName string, src []byte, loadPath ...string) ([]byte, []string, error)
- func CompileFiles(ctx context.Context, files []File, loadPath ...string) ([]byte, []string, error)
- func CompileTrace(ctx context.Context, main string, runs [][]string, rubyOpts []string, ...) ([]byte, []string, error)
- func CompileTraced(ctx context.Context, entryName string, src []byte, main string, ...) ([]byte, []string, error)
- func CompileWithGems(ctx context.Context, mainName string, src []byte, loadPath ...string) ([]byte, []string, error)
- func GoSum() string
- func PreludeStubs(ctx context.Context) ([]byte, error)
- func UserCode(code []byte, mainName string) string
- func WriteModule(dir string) error
- type File
- type Inference
- type SkippedTest
Constants ¶
const GoMod = "module gen\n\ngo " + GoVersion + "\n\nrequire (\n\tgithub.com/dlclark/regexp2 " + regexp2Version + "\n\tgithub.com/ebitengine/purego " + puregoVersion + "\n)\n"
GoMod is the go.mod generated code builds in: the runtime modules a program may import (regexp2 for patterns RE2 cannot match, decision 242; purego for Fiddle, decision 326); Go loads one only when main.go imports it.
const GoVersion = "1.25.0"
GoVersion is the go directive for the module generated code builds in.
const StubsPath = "prelude/go/0_stubs.go"
StubsPath is where PreludeStubs' output goes, relative to the repo root: the only prelude/go file the embed pattern leaves out.
Variables ¶
var GemSigs embed.FS
GemSigs holds vendored `.rbs` signatures for the gems rugaroo compiles (decision 160), under sig/gems/<gem>/. A gem program (one that requires a gem, so its load phase runs under MRI at compile time, decision 161) reads them to type the gem's otherwise-unannotated classes.
var Prelude embed.FS
Prelude holds prelude.rb, its require_relatives, prelude/go/*.go (pure-Go helpers embedded directly; see loadPreludeGo), and the vendored gems' lib files (vendored/<name>/, mirrored from the gems/<name> submodules by scripts/vendor-gems so the module proxy has them; pure Ruby compiled as user code when required: vendoredLibs, decision 328). The character class leaves out prelude/go/0_stubs.go, the generated type-checking stubs (decision 154): helper files must start with a letter.
Functions ¶
func Compile ¶
func Compile(ctx context.Context, mainName string, src []byte, loadPath ...string) ([]byte, []string, error)
Compile transpiles the Ruby source of mainName (with the embedded prelude) into a single Go file. loadPath is `ruby -I`'s: directories a `require` searches for the program's own files.
func CompileFiles ¶
CompileFiles transpiles several Ruby files into one Go program, as Ruby loads them into one process: in order, each file's top level running before the next's (decision 84).
func CompileTrace ¶
func CompileTrace(ctx context.Context, main string, runs [][]string, rubyOpts []string, loadPath ...string) ([]byte, []string, error)
CompileTrace runs main under MRI once per args in runs (rubyOpts first) and compiles what those runs loaded (decision 296).
func CompileTraced ¶
func CompileTraced(ctx context.Context, entryName string, src []byte, main string, loadPath ...string) ([]byte, []string, error)
CompileTraced compiles an entry file listing the requires MRI loaded (decision 197), then the program's main file (the CLI's -main, decision 288). The -I dirs are gem dirs.
func CompileWithGems ¶
func CompileWithGems(ctx context.Context, mainName string, src []byte, loadPath ...string) ([]byte, []string, error)
CompileWithGems is Compile for the CLI: a require only an installed gem answers is looked up under MRI and the program compiled with the gem (decision 173); a program without one never starts Ruby.
func PreludeStubs ¶
PreludeStubs is prelude/go/0_stubs.go's content (decision 154): what the generated program declares and prelude/go names, bodies replaced by panic(0), so the helpers type-check under `-tags rugaroo_prelude`.
func UserCode ¶
UserCode is the part of Compile's output that mainName produced, for display: decls a `//line mainName:` directive precedes, of a decl with one inside (the top-level function) the part from there on, and the plumbing generated for mainName's types, found by name (X, XI, NewX, X_..., super_X_, receivers of those).
Types ¶
type File ¶
type File struct {
Name string // as given, relative to where the program runs: it is what messages and failure locations show
Src []byte
}
File is one Ruby source file of a multi-file program.
type Inference ¶
Inference carries parameter types inferred from use (docs/design.md decision 146) between compiles of nearly the same sources.
func NewInference ¶
func NewInference() *Inference
NewInference is an empty Inference for CompileTestsSkipping.
type SkippedTest ¶
type SkippedTest = compiler.SkippedTest
SkippedTest is a test method CompileTestsSkipping could not compile and turned into a skip.
func CompileTestsSkipping ¶
func CompileTestsSkipping(ctx context.Context, files []File, seed *Inference) ([]byte, []string, []SkippedTest, error)
CompileTestsSkipping is CompileFiles for running what a test suite can: each test_ method (an `it` included) that fails to compile becomes a minitest skip carrying the error instead of failing the build. seed, when not nil, carries inferred parameter types to the next call for the same sources, which then starts from them.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
rubyspec
command
Command rubyspec runs ruby/spec directories under rugaroo, one minitest program each, so an example rugaroo can't compile is skipped with its error instead of losing the directory.
|
Command rubyspec runs ruby/spec directories under rugaroo, one minitest program each, so an example rugaroo can't compile is skipped with its error instead of losing the directory. |
|
rugaroo
command
Command rugaroo builds or runs a typed Ruby file as Go, like `go build` and `go run`, or prints the Go it compiles to.
|
Command rugaroo builds or runs a typed Ruby file as Go, like `go build` and `go run`, or prints the Go it compiles to. |
|
rugaroo-wasm
command
Command rugaroo-wasm is rugaroo's compiler for a browser (the static `rugaroo web`, decision 102): it defines rugarooCompile(src) and stays alive for calls.
|
Command rugaroo-wasm is rugaroo's compiler for a browser (the static `rugaroo web`, decision 102): it defines rugarooCompile(src) and stays alive for calls. |
|
Package examples embeds examples/*/main.rb for `rugaroo web`'s example picker, kept out of the rugaroo library so its importers don't carry them.
|
Package examples embeds examples/*/main.rb for `rugaroo web`'s example picker, kept out of the rugaroo library so its importers don't carry them. |
|
internal
|
|
|
boot
Package boot runs a Ruby program's load phase under MRI at compile time and records what the source alone does not show: methods built by define_method or a string eval, the files autoload actually loaded, the classes and their ancestors, and the objects held in class state (docs/design.md decision 161).
|
Package boot runs a Ruby program's load phase under MRI at compile time and records what the source alone does not show: methods built by define_method or a string eval, the files autoload actually loaded, the classes and their ancestors, and the objects held in class state (docs/design.md decision 161). |
|
compiler
Package compiler turns typed Ruby (rbs-inline) into Go.
|
Package compiler turns typed Ruby (rbs-inline) into Go. |
|
rbs
Package rbs parses the subset of RBS type syntax that rugaroo understands.
|
Package rbs parses the subset of RBS type syntax that rugaroo understands. |