Documentation
¶
Overview ¶
Package gen turns a notebook's code cells into a Go program: the worker the kernel compiles and drives.
Each cell becomes a function. The names a cell defines at its top level become package-level variables — so every cell, and every function, can read them, and their values outlive the call — which needs their types: gen type-checks the cells one by one in dependency order to learn them. The cells' own text is kept, edited in place (":=" becomes "= ", a final expression is wrapped in a call that shows it), under //line directives that point back into the notebook, so the compiler's errors and a panic's stack name the notebook's lines.
Index ¶
Constants ¶
const RubyModule = "github.com/go-scikit/ruby"
RubyModule is the module RubyPath belongs to.
const RubyPath = "github.com/go-scikit/ruby/cells"
RubyPath is the import path of the package that runs Ruby cells: the go-scikit Ruby bindings' cells, over the pure-Go Ruby go-embedded-ruby.
const RuntimePath = "github.com/go-notebook/notebook/runtime"
RuntimePath is the import path of the package the program links.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct {
Source string
Line int
// Lang is the cell's language: "go" (or "") or "ruby".
Lang string
}
Code is one code cell: its source and the 1-based line of the notebook where that source starts.
type Diag ¶
type Diag struct {
Cell int // -1 when it is not inside a cell
Line, Col int // in the notebook
Msg string
}
Diag is a problem in the notebook, at a cell and a position in it.
type Options ¶ added in v0.3.0
type Options struct {
// RubyTypes maps a Ruby cell's variable to the Go type its value had the
// last time the cell ran, as the cells package names it
// ("[]float64", "*{github.com/go-plot/plot}.Figure"). A Go cell sees the
// variable with that type. A variable not in it is declared any, and the
// Go cells that read it are deferred until it is known.
RubyTypes map[string]string
}
Options configure GenerateWith.
type Program ¶
type Program struct {
Source []byte
Vars []Var
Graph *analysis.Graph
// Imports maps every package the program imports (but the runtime) to
// the name it is imported under.
Imports map[string]string
// Diags are the notebook's errors. A program with diagnostics is still
// returned, but will not compile.
Diags []Diag
// Deferred maps a cell that cannot be compiled yet to why: it reads a
// Ruby cell's variable whose Go type is known only once that cell has
// run (see Options.RubyTypes). It is emitted as a stub that says so.
Deferred map[int]string
}
Program is a generated worker.
type Var ¶
type Var struct {
Name string
Type string // Go syntax, qualified with the program's import names
Cell int
// Ruby marks a Ruby cell's variable. Its Go holder is named Ident when
// its name is no Go identifier (len, type): Go cells do not see it.
Ruby bool
Ident string
}
Var is a notebook variable as the program declares it.