Documentation ¶
Overview ¶
Package gen provides templated output generation from addition chain programs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Functions = []*Function{ { Name: "add", Description: "If the input operation is an `ir.Add` then return it, otherwise return `nil`", Func: func(op ir.Op) ir.Op { if a, ok := op.(ir.Add); ok { return a } return nil }, }, { Name: "double", Description: "If the input operation is an `ir.Double` then return it, otherwise return `nil`", Func: func(op ir.Op) ir.Op { if d, ok := op.(ir.Double); ok { return d } return nil }, }, { Name: "shift", Description: "If the input operation is an `ir.Shift` then return it, otherwise return `nil`", Func: func(op ir.Op) ir.Op { if s, ok := op.(ir.Shift); ok { return s } return nil }, }, { Name: "inc", Description: "Increment an integer", Func: func(n int) int { return n + 1 }, }, { Name: "format", Description: "Formats an addition chain script (`*ast.Chain`) as a string", Func: printer.String, }, { Name: "split", Description: "Calls `strings.Split`", Func: strings.Split, }, { Name: "join", Description: "Calls `strings.Join`", Func: strings.Join, }, { Name: "lines", Description: "Split input string into lines", Func: func(s string) []string { var lines []string scanner := bufio.NewScanner(strings.NewReader(s)) for scanner.Scan() { lines = append(lines, scanner.Text()) } return lines }, }, }
Functions is the list of functions provided to templates.
Functions ¶
func BuiltinTemplate ¶
BuiltinTemplate loads the named template. Returns an error if the template is unknown.
func BuiltinTemplateNames ¶
func BuiltinTemplateNames() []string
BuiltinTemplateNames returns all builtin template names.
func IsBuiltinTemplate ¶
IsBuiltinTemplate reports whether name is a builtin template name.
Types ¶
type Config ¶
type Config struct { // Allocator for temporary variables. This configuration determines variable // naming. Allocator pass.Allocator }
Config for template input generation.
type Data ¶
type Data struct { // Chain is the addition chain as a list of integers. Chain addchain.Chain // Ops is the complete sequence of addition operations required to compute // the addition chain. Ops addchain.Program // Script is the condensed representation of the addition chain computation // in the "addition chain calculator" language. Script *ast.Chain // Program is the intermediate representation of the addition chain // computation. This representation is likely the most convenient for code // generation. It contains a sequence of add, double and shift (repeated // doubling) instructions required to compute the chain. Temporary variable // allocation has been performed and the list of required temporaries // populated. Program *ir.Program // Metadata about the addchain project and the specific release parameters. // Please use this to include a reference or citation back to the addchain // project in your generated output. Meta *meta.Properties }
Data provided to templates.
Click to show internal directories.
Click to hide internal directories.