codegen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package codegen is the CODEGEN STRATUM: erased intermediate representation to target source, kept behind the Backend interface so a new deployment target is one plugin, not a fork. Dependent types are a build-time discipline; what deploys is the erasure — the shadow.

THE SHADOW RULE (CLAUDE.md): any optimization IR is built on erased, throwaway codegen output, NEVER on the immutable core/store. The core is the source of truth and identity; codegen mutates only its own shadow.

v1 ships one Backend (JavaScript); the interface exists so a later version adds targets without a rewrite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Target names the backend (e.g. "js").
	Target() string
	// Emit lowers an erased program to target source.
	Emit(p Program) (TargetSource, error)
}

Backend is the codegen stratum interface: it turns an erased Program into target source. One implementation ships per supported target.

func Default added in v1.0.0

func Default() Backend

Default returns the v1 backend.

type CtorSpec added in v1.0.0

type CtorSpec struct {
	Name  string
	Tag   int
	Arity int
}

CtorSpec is one constructor of an emitted datatype: its bound name, its 0-based tag, and the total number of curried parameters it takes (datatype parameters + its own arguments; parameters arrive erased).

type DataSpec added in v1.0.0

type DataSpec struct {
	ElimName  string
	NumParams int
	Ctors     []CtorSpec
	Rec       [][]bool
}

DataSpec is one datatype: its eliminator's bound name, the number of datatype parameters, and its constructors in declaration order. Rec mirrors core.CtorSig.Rec for building recursive calls in the eliminator.

type DefSpec added in v1.0.0

type DefSpec struct {
	Name string
	Body Ir
}

DefSpec is one emitted definition.

type IApp added in v1.0.0

type IApp struct {
	Fn  Ir
	Arg Ir
}

IApp is application.

type IGlobal added in v1.0.0

type IGlobal struct {
	Name string
}

IGlobal is a reference to a top-level definition, constructor, or eliminator, by the name the emitted program binds it to.

type ILam added in v1.0.0

type ILam struct {
	Name string
	Body Ir
}

ILam is a one-parameter function.

type ILet added in v1.0.0

type ILet struct {
	Name string
	Val  Ir
	Body Ir
}

ILet is a local binding.

type IUnit added in v1.0.0

type IUnit struct{}

IUnit is the erased token: every type, proof, and 0-quantity value.

type IVar added in v1.0.0

type IVar struct {
	Idx int
}

IVar is a bound variable (de Bruijn index, as in core).

type Ir added in v1.0.0

type Ir interface {
	// contains filtered or unexported methods
}

Ir is an erased term. Sealed like core.Tm.

func Erase

func Erase(t core.Tm, names map[core.Hash]string, typeRefs map[core.Hash]bool) Ir

Erase lowers elaborated, meta-free core to the erased IR. names maps a definition hash to its emitted global name; typeRefs holds the hashes that denote types at runtime (datatype formers), which erase to the unit token.

type JS added in v1.0.0

type JS struct{}

JS is the v1 backend: boring JavaScript. Everything is curried one-argument arrow functions; constructors build {tag, args} records; eliminators are switch-dispatch with recursive calls for the inductive hypotheses; the erased token is null. The output runs under node with no dependencies.

func (JS) Emit added in v1.0.0

func (JS) Emit(p Program) (TargetSource, error)

Emit lowers a program to a self-contained JavaScript source file.

func (JS) Target added in v1.0.0

func (JS) Target() string

type Program added in v1.0.0

type Program struct {
	Datas []DataSpec
	Defs  []DefSpec
	// Main, when non-empty, names the definition whose value the emitted
	// program prints on run.
	Main string
}

Program is a whole erased program in definition order (acyclic, so the order is also the emission order).

type TargetSource

type TargetSource string

TargetSource is emitted source for some concrete backend target.

Jump to

Keyboard shortcuts

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