Documentation
¶
Index ¶
- type FuncDefaults
- type Generator
- func (g *Generator) Diagnostics() []diagnostics.Diagnostic
- func (g *Generator) Generate() (string, error)
- func (g *Generator) SetAnalysisResult(r *semantic.AnalysisResult)
- func (g *Generator) SetMCPTarget(v bool)
- func (g *Generator) SetProjectDir(dir string)
- func (g *Generator) SetSiblingDeclarations(decls []ast.Declaration)
- func (g *Generator) SetSourceFile(path string)
- func (g *Generator) SetStandaloneFile(v bool)
- func (g *Generator) SetStdlibModule(base string)
- func (g *Generator) SetStripLineDirectives(v bool)
- func (g *Generator) VarMap() map[string]string
- func (g *Generator) Warnings() []error
- type Lowerer
- type TypeParameter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FuncDefaults ¶
type FuncDefaults struct {
ParamNames []string // Parameter names in order
DefaultValues []ast.Expression // Default values (nil if no default)
HasVariadic bool // Whether the last parameter is variadic
}
Generator generates Go code from an AST.
ARCHITECTURE NOTE: Kukicha uses placeholders like "any" and "key" in stdlib function signatures to represent generic type parameters. When generating Go code, we detect these placeholders and emit proper Go generics (e.g., [T any, K comparable]). This allows Kukicha users to write simple code while getting type-safe Go generics.
The isStdlibIter and placeholderMap fields work together:
- isStdlibIter is true when generating stdlib/iterator or stdlib/slice code
- placeholderMap maps Kukicha placeholders ("any", "key") to Go type params ("T", "K")
- During type annotation generation, we substitute placeholders with type params
This design keeps Kukicha's "beginner-friendly" goal: users don't write generic syntax, but the generated Go code is fully type-safe with proper generic constraints. FuncDefaults stores information about a function's default parameter values
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator generates Go code from an AST.
State is split in two: an immutable-during-render *sharedState (the program, configuration, and all semantic-analysis maps), shared by pointer with every childGenerator; and the per-render mutable fields below (output buffer, indent level, render-time ctx), which each child owns its own copy of. Temp-name minting lives in a shared *nameGen so parent and children never collide. See codegen_shared.go for the rationale (issue #264 / the #208 field-copy bug).
func (*Generator) Diagnostics ¶ added in v0.7.0
func (g *Generator) Diagnostics() []diagnostics.Diagnostic
Diagnostics returns all diagnostics (errors and warnings) collected during code generation.
func (*Generator) SetAnalysisResult ¶ added in v0.1.0
func (g *Generator) SetAnalysisResult(r *semantic.AnalysisResult)
SetAnalysisResult passes all semantic analysis outputs to the generator at once.
func (*Generator) SetMCPTarget ¶
SetMCPTarget enables special codegen for MCP servers (e.g., print to stderr)
func (*Generator) SetProjectDir ¶ added in v0.1.5
SetProjectDir sets the absolute path to the project root, used to emit relative paths in //line directives
func (*Generator) SetSiblingDeclarations ¶ added in v0.19.0
func (g *Generator) SetSiblingDeclarations(decls []ast.Declaration)
SetSiblingDeclarations provides declarations from other files in the same package, used by cross-file codegen helpers (hasMethodOnType, return-type inference, listAliases) when transpiling a single file with --package-context.
func (*Generator) SetSourceFile ¶
SetSourceFile sets the source file path and detects if special transpilation is needed
func (*Generator) SetStandaloneFile ¶ added in v0.16.0
SetStandaloneFile marks this output as a standalone generated file (not a directory build). When true, Generate emits a "//go:build ignore" constraint so that go test ./... and go build . skip the file; kukicha build and explicit "go build file.go" invocations are unaffected by this constraint.
func (*Generator) SetStdlibModule ¶
SetStdlibModule overrides the base module path used when rewriting "stdlib/X" imports to full Go module paths. The default is "github.com/kukichalang/kukicha". Set this when building a fork or vendoring the kukicha stdlib under a different module name.
func (*Generator) SetStripLineDirectives ¶ added in v0.0.29
SetStripLineDirectives disables emission of //line directives in generated Go. Useful for production builds where .kuki source files are not present at runtime and smaller/cleaner output is preferred over source-mapped errors.
type Lowerer ¶
type Lowerer struct {
// contains filtered or unexported fields
}
Lowerer transforms high-level AST constructs (pipes, onerr) into IR nodes. It delegates sub-expression rendering to Generator.exprToString and uses Generator.inferReturnCount / isErrorOnlyReturn for semantic queries.
type TypeParameter ¶
type TypeParameter struct {
Name string // Generated name: T, U, V, etc.
Placeholder string // Original placeholder: "any", "key", etc.
Constraint string // "any", "comparable", "cmp.Ordered"
}
TypeParameter represents a type parameter for stdlib special transpilation This is internal to codegen and separate from the removed ast.TypeParameter