codegen

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package codegen translates the Meow AST into Go source code. The generated code depends on the meowrt runtime package for dynamic typing.

Generated Code Structure

The output is a self-contained Go main package with the following layout:

package main
import meow "github.com/135yshr/meow/runtime/meowrt"
// user-defined functions
func main() { /* top-level statements */ }

All Meow values are represented as meow.Value at runtime.

Runtime Dependency

Generated code calls functions from the meowrt package for arithmetic, comparisons, built-in operations (nya, lick, picky, curl), and pattern matching.

Supported Constructs

  • Variable declarations and assignments
  • Function definitions and calls (including lambdas)
  • Arithmetic, comparison, and logical operators
  • If/else, while loops
  • List literals and index access
  • Pipe expressions (|=|)
  • Error recovery expressions (~>)
  • Pattern matching (peek)
  • Error raising (hiss) and recovery (gag/is_furball)

Usage

gen := codegen.New()
goSource, err := gen.Generate(prog)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CatwalkOutput added in v0.2.0

type CatwalkOutput map[string]string

CatwalkOutput maps catwalk function names to their expected output strings.

func ExtractCatwalkOutputs added in v0.2.0

func ExtractCatwalkOutputs(tokens iter.Seq[token.Token]) CatwalkOutput

ExtractCatwalkOutputs scans a token stream for catwalk_ functions and extracts their # Output: blocks. The token stream is consumed into a slice so it can be scanned with random access.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator produces Go source code from a Meow AST.

func New

func New() *Generator

New creates a new code generator.

func NewTest added in v0.2.0

func NewTest() *Generator

NewTest creates a code generator in test mode.

func (*Generator) EnableCoverage added in v0.2.0

func (g *Generator) EnableCoverage(filename string)

EnableCoverage activates statement coverage instrumentation.

func (*Generator) Generate

func (g *Generator) Generate(prog *ast.Program) (string, error)

Generate produces Go source code from a Program AST.

func (*Generator) GenerateFuzz added in v0.2.0

func (g *Generator) GenerateFuzz(prog *ast.Program) (helpers string, fuzzTests string, fuzzNames []string, err error)

GenerateFuzz produces Go fuzz test source from a Program AST. It converts fuzz_ prefixed functions into Go FuzzXxx functions. It returns helper code (main.go), fuzz test code (main_test.go), and the list of generated Go fuzz function names.

func (*Generator) GenerateTest added in v0.2.0

func (g *Generator) GenerateTest(prog *ast.Program) (string, error)

GenerateTest produces Go source code from a Program AST in test mode. It auto-imports the testing package and wraps test_ functions with Run/Report and catwalk_ functions with Catwalk.

func (*Generator) SetCatwalkOutput added in v0.2.0

func (g *Generator) SetCatwalkOutput(co CatwalkOutput)

SetCatwalkOutput sets the expected output map for catwalk_ functions.

func (*Generator) SetMutations added in v0.2.0

func (g *Generator) SetMutations(m map[ast.Expr][]mutation.MutationEntry)

SetMutations sets the mutation schema for schemata-based mutation testing.

func (*Generator) SetTypeInfo added in v0.2.0

func (g *Generator) SetTypeInfo(ti *checker.TypeInfo)

SetTypeInfo stores type checking results for use in code generation.

Jump to

Keyboard shortcuts

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