types

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package types provides Go-to-Simplicity type mapping, sum type parsing (Either/Option), and tuple type utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSumType added in v0.1.1

func IsSumType(typeStr string) bool

IsSumType checks if a type string represents a sum type

Types

type MatchArm added in v0.1.1

type MatchArm struct {
	Pattern string // "Left(data)" or "Right(sig)" or "Some(val)" or "None"
	VarName string // The bound variable name (data, sig, val, etc.)
	VarType string // The type of the bound variable
	Body    string // The body of the match arm
}

MatchArm represents a single arm of a match expression

type MatchExpr added in v0.1.1

type MatchExpr struct {
	Scrutinee string     // The expression being matched (e.g., "witness::DATA")
	Arms      []MatchArm // The match arms
}

MatchExpr represents a complete match expression

func (*MatchExpr) ToSimplicityHL added in v0.1.1

func (m *MatchExpr) ToSimplicityHL(indent string) string

ToSimplicityHL generates SimplicityHL code for the match expression

type SumType added in v0.1.1

type SumType struct {
	Kind      SumTypeKind
	LeftType  string // For Either: left type, For Option: the inner type
	RightType string // For Either: right type, For Option: unused
}

SumType represents Either<L, R> or Option<T> types

func ParseSumType added in v0.1.1

func ParseSumType(typeStr string) (*SumType, error)

ParseSumType parses a string like "Either<u256, [u8; 64]>" or "Option<[u8; 64]>"

func (*SumType) IsEither added in v0.1.1

func (st *SumType) IsEither() bool

IsEither returns true if this is an Either type

func (*SumType) IsOption added in v0.1.1

func (st *SumType) IsOption() bool

IsOption returns true if this is an Option type

func (*SumType) ToSimplicityHL added in v0.1.1

func (st *SumType) ToSimplicityHL() string

ToSimplicityHL returns the SimplicityHL representation of the sum type

type SumTypeKind added in v0.1.1

type SumTypeKind int

SumTypeKind identifies whether a SumType is Either or Option.

const (
	// SumTypeEither represents an Either<L, R> type.
	SumTypeEither SumTypeKind = iota
	// SumTypeOption represents an Option<T> type.
	SumTypeOption
)

type TupleType added in v0.1.1

type TupleType struct {
	Elements []string
}

TupleType represents a tuple like (u256, [u8; 64])

func ParseTupleType added in v0.1.1

func ParseTupleType(typeStr string) (*TupleType, error)

ParseTupleType parses a string like "(u256, [u8; 64])"

func (*TupleType) ToSimplicityHL added in v0.1.1

func (tt *TupleType) ToSimplicityHL() string

ToSimplicityHL returns the SimplicityHL representation

type TypeMapper

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

TypeMapper maps Go types to Simplicity types

func NewTypeMapper

func NewTypeMapper() *TypeMapper

NewTypeMapper creates a new type mapper

func (*TypeMapper) GetBitSize

func (tm *TypeMapper) GetBitSize(simplicityType string) int

GetBitSize returns the bit size for a Simplicity type

func (*TypeMapper) InferHexType added in v0.1.1

func (tm *TypeMapper) InferHexType(hexValue string) string

InferHexType infers the Simplicity type from a hex literal value

func (*TypeMapper) MapGoType

func (tm *TypeMapper) MapGoType(goType ast.Expr) (string, error)

MapGoType converts a Go type to its Simplicity equivalent

func (*TypeMapper) SupportedTypes

func (tm *TypeMapper) SupportedTypes() []string

SupportedTypes returns a list of all supported Go types

Jump to

Keyboard shortcuts

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