meowrt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package meowrt provides the runtime support for compiled Meow programs. It defines the dynamic Value interface and concrete types used for all values at runtime, along with built-in functions and operators.

Value Types

Every Meow value implements the Value interface:

Constructors

Built-in Functions

  • Nya print values to stdout (like fmt.Println)
  • Hiss raise an error with a message
  • Gag call a function and recover from panics (returns Furball on error)
  • GagOr call a function and return a fallback on panic (~> operator)
  • IsFurball check if a value is a Furball
  • Call invoke a Func value
  • Len return the length of a String or List
  • ToInt convert to Int
  • ToFloat convert to Float
  • ToString convert to String

List Higher-Order Functions

  • Lick map a function over a list
  • Picky filter a list by predicate
  • Curl reduce (fold) a list
  • Append append a value to a list (returns new list)
  • Head return the first element
  • Tail return all elements except the first

Operators

Pattern Matching

  • MatchValue check if two values are equal
  • MatchRange check if a value is within an integer range [low, high]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsBool added in v0.2.0

func AsBool(v Value) bool

AsBool extracts a bool from a Value, panicking with a descriptive message on type mismatch.

func AsFloat added in v0.2.0

func AsFloat(v Value) float64

AsFloat extracts a float64 from a Value, panicking with a descriptive message on type mismatch.

func AsInt added in v0.2.0

func AsInt(v Value) int64

AsInt extracts an int64 from a Value, panicking with a descriptive message on type mismatch.

func AsString added in v0.2.0

func AsString(v Value) string

AsString extracts a string from a Value, panicking with a descriptive message on type mismatch.

func ClearMethods added in v0.2.0

func ClearMethods()

ClearMethods removes all registered methods from the registry.

func LookupMethod added in v0.2.0

func LookupMethod(typeName, methodName string) (func(...Value) Value, bool)

LookupMethod returns the method function for a type, if registered.

func MatchRange

func MatchRange(v Value, low, high int64) bool

MatchRange checks if a value is within an integer range [low, high].

func MatchValue

func MatchValue(v, pattern Value) bool

MatchValue checks if two values are equal.

func RegisterMethod added in v0.2.0

func RegisterMethod(typeName, methodName string, fn func(...Value) Value)

RegisterMethod registers a method for a named type.

func ToJSON added in v0.2.0

func ToJSON(v Value) string

ToJSON serializes a Value to its JSON string representation.

Types

type Bool

type Bool struct{ Val bool }

Bool represents a boolean value.

func NewBool

func NewBool(v bool) *Bool

NewBool creates a new Bool value.

func (*Bool) IsTruthy

func (b *Bool) IsTruthy() bool

func (*Bool) String

func (b *Bool) String() string

func (*Bool) Type

func (b *Bool) Type() string

type Float

type Float struct{ Val float64 }

Float represents a floating-point value.

func NewFloat

func NewFloat(v float64) *Float

NewFloat creates a new Float value.

func (*Float) IsTruthy

func (f *Float) IsTruthy() bool

func (*Float) String

func (f *Float) String() string

func (*Float) Type

func (f *Float) Type() string

type Func

type Func struct {
	// Name is the function name for display purposes.
	Name string
	// Fn is the underlying Go function implementation.
	Fn func(args ...Value) Value
	// Arity is the number of expected arguments. -1 means variadic (no currying).
	Arity int
}

Func represents a function value.

func NewFunc

func NewFunc(name string, fn func(args ...Value) Value) *Func

NewFunc creates a new Func value with the given name and implementation. The function is variadic (Arity -1) and will not be auto-curried. fn must not be nil; passing nil will panic.

func NewFuncWithArity added in v0.2.0

func NewFuncWithArity(name string, arity int, fn func(args ...Value) Value) *Func

NewFuncWithArity creates a new Func value with a fixed arity. When called with fewer arguments than arity, the function is automatically partially applied (curried).

func PartialApply added in v0.2.0

func PartialApply(fn *Func, args ...Value) *Func

PartialApply creates a new function that captures the given arguments and waits for the remaining ones. The returned function's arity is reduced by the number of supplied arguments.

func (*Func) Call

func (f *Func) Call(args ...Value) Value

Call invokes the function with the given arguments.

func (*Func) IsTruthy

func (f *Func) IsTruthy() bool

func (*Func) String

func (f *Func) String() string

func (*Func) Type

func (f *Func) Type() string

type Furball

type Furball struct{ Message string }

Furball represents an error value caught by Gag.

func (*Furball) IsTruthy

func (e *Furball) IsTruthy() bool

func (*Furball) String

func (e *Furball) String() string

func (*Furball) Type

func (e *Furball) Type() string

type Int

type Int struct{ Val int64 }

Int represents an integer value.

func NewInt

func NewInt(v int64) *Int

NewInt creates a new Int value.

func (*Int) IsTruthy

func (i *Int) IsTruthy() bool

func (*Int) String

func (i *Int) String() string

func (*Int) Type

func (i *Int) Type() string

type Kitty added in v0.2.0

type Kitty struct {
	TypeName   string
	FieldNames []string
	Fields     map[string]Value
}

Kitty represents a user-defined struct value.

func NewKitty added in v0.2.0

func NewKitty(typeName string, fieldNames []string, args ...Value) *Kitty

NewKitty creates a new Kitty value. Panics if argument count does not match field count.

func (*Kitty) GetField added in v0.2.0

func (k *Kitty) GetField(name string) Value

GetField returns the value of a field by name. Panics if the field does not exist.

func (*Kitty) IsTruthy added in v0.2.0

func (k *Kitty) IsTruthy() bool

func (*Kitty) String added in v0.2.0

func (k *Kitty) String() string

func (*Kitty) Type added in v0.2.0

func (k *Kitty) Type() string

type List

type List struct {
	// Items is the slice of values in the list.
	Items []Value
}

List represents a list value.

func NewList

func NewList(items ...Value) *List

NewList creates a new List value from the given items.

func (*List) Get

func (l *List) Get(index int) Value

Get returns the item at the given index. It panics if index is out of range.

func (*List) IsTruthy

func (l *List) IsTruthy() bool

func (*List) Iter

func (l *List) Iter() iter.Seq[Value]

Iter returns an iterator over the list items.

func (*List) Len

func (l *List) Len() int

Len returns the number of items in the list.

func (*List) String

func (l *List) String() string

func (*List) Type

func (l *List) Type() string

type Map added in v0.2.0

type Map struct {
	Items map[string]Value
}

Map represents a map value with string keys.

func NewMap added in v0.2.0

func NewMap(items map[string]Value) *Map

NewMap creates a new Map value from the given items.

func (*Map) Get added in v0.2.0

func (m *Map) Get(key string) (Value, bool)

Get returns the value for the given key and whether it was found.

func (*Map) IsTruthy added in v0.2.0

func (m *Map) IsTruthy() bool

func (*Map) String added in v0.2.0

func (m *Map) String() string

func (*Map) Type added in v0.2.0

func (m *Map) Type() string

type NilValue

type NilValue struct{}

NilValue represents a nil/catnap value.

func NewNil

func NewNil() *NilValue

NewNil creates a new NilValue.

func (*NilValue) IsTruthy

func (n *NilValue) IsTruthy() bool

func (*NilValue) String

func (n *NilValue) String() string

func (*NilValue) Type

func (n *NilValue) Type() string

type String

type String struct{ Val string }

String represents a string value.

func NewString

func NewString(v string) *String

NewString creates a new String value.

func (*String) IsTruthy

func (s *String) IsTruthy() bool

func (*String) String

func (s *String) String() string

func (*String) Type

func (s *String) Type() string

type Value

type Value interface {
	Type() string
	String() string
	IsTruthy() bool
}

Value is the core interface for all Meow values.

func Add

func Add(a, b Value) Value

Add performs addition on same-type operands only. int+int→int, float+float→float, string+string→string.

func And

func And(a, b Value) Value

And performs logical AND (short-circuit).

func Append

func Append(lst Value, v Value) Value

Append appends a value to a list, returning a new list.

func Call

func Call(fn Value, args ...Value) Value

Call invokes a function value with the given arguments. If the function has a fixed arity and fewer arguments are supplied, it returns a partially applied function.

func Curl

func Curl(lst Value, init Value, fn Value) Value

Curl reduces a list (like fold/reduce).

func DispatchMethod added in v0.2.0

func DispatchMethod(obj Value, methodName string, args ...Value) Value

DispatchMethod calls a method on a value by looking up the method registry.

func Div

func Div(a, b Value) Value

Div performs division on same-type operands only. int/int→int, float/float→float.

func Equal

func Equal(a, b Value) Value

Equal checks equality between same-type operands only.

func Gag

func Gag(fn Value) Value

Gag calls fn (a zero-argument Func) and recovers from any panic, returning the panic message wrapped in a Furball. If fn succeeds, its return value is returned as-is.

func GagOr

func GagOr(fn Value, fallback Value) Value

GagOr calls fn (a zero-argument Func) and recovers from any panic. If the call succeeds, its return value is returned as-is. If it panics, the fallback is used: if fallback is a Func it is called with the Furball as argument; otherwise fallback is returned directly.

func GreaterEqual

func GreaterEqual(a, b Value) Value

GreaterEqual performs greater-than-or-equal comparison on same-type operands only.

func GreaterThan

func GreaterThan(a, b Value) Value

GreaterThan performs greater-than comparison on same-type operands only.

func Head(lst Value) Value

Head returns the first element of a list.

func Hiss

func Hiss(args ...Value) Value

Hiss raises an error with the given message.

func IsFurball

func IsFurball(v Value) Value

IsFurball returns NewBool(true) if v is a Furball, NewBool(false) otherwise.

func Len

func Len(v Value) Value

Len returns the length of a string or list.

func LessEqual

func LessEqual(a, b Value) Value

LessEqual performs less-than-or-equal comparison on same-type operands only.

func LessThan

func LessThan(a, b Value) Value

LessThan performs less-than comparison on same-type operands only.

func Lick

func Lick(lst Value, fn Value) Value

Lick maps a function over a list (like map).

func Mod

func Mod(a, b Value) Value

Mod performs modulo on integers only.

func Mul

func Mul(a, b Value) Value

Mul performs multiplication on same-type operands only. int*int→int, float*float→float.

func Negate

func Negate(v Value) Value

Negate negates a value.

func Not

func Not(v Value) Value

Not performs logical NOT.

func NotEqual

func NotEqual(a, b Value) Value

NotEqual checks inequality between same-type operands only.

func Nya

func Nya(args ...Value) Value

Nya prints a value (the Meow print function).

func Or

func Or(a, b Value) Value

Or performs logical OR (short-circuit).

func Picky

func Picky(lst Value, fn Value) Value

Picky filters a list (like filter).

func Sub

func Sub(a, b Value) Value

Sub performs subtraction on same-type operands only. int-int→int, float-float→float.

func Tail

func Tail(lst Value) Value

Tail returns all elements except the first.

func ToFloat

func ToFloat(v Value) Value

ToFloat converts a value to a float.

func ToInt

func ToInt(v Value) Value

ToInt converts a value to an integer.

func ToString

func ToString(v Value) Value

ToString converts a value to a string.

Jump to

Keyboard shortcuts

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