ffi

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ffi provides Foreign Function Interface capabilities that enable seamless integration between Ale and Go code. It handles marshaling and unmarshaling between native Go values and Ale's value types, allowing Go functions to be called from Ale code and Ale values to be used in Go applications that embed the Ale interpreter.

Index

Constants

View Source
const (
	// ErrValueMustBeSequence is raised when an Array Unwrap call can't treat
	// its source as a data.Sequence
	ErrValueMustBeSequence = "value must be a sequence"

	// ErrBadSliceLength is raised when an Array Unwrap call receives a slice
	// with a length that does not match the expected length of the array
	ErrBadSliceLength = "bad slice length: expected %d, got %d"
)
View Source
const (
	// ErrInterfaceTypeMismatch is raised when an interface of the receiver in
	// a data.Object doesn't match the expected wrapped interface
	ErrInterfaceTypeMismatch = "interface type mismatch"

	// ErrInterfaceCoercionNotSupported is raised when the value to unwrap
	// isn't a data.Object
	ErrInterfaceCoercionNotSupported = "value cannot be coerced into interface"
)
View Source
const (
	// ErrValueMustBeSigned is raised when an int Unwrap call can't properly
	// size its source as a signed integer
	ErrValueMustBeSigned = "value must be a %d-bit signed integer"

	// ErrValueMustBeUnsigned is raised when a uint Unwrap call can't properly
	// size its source as an unsigned integer
	ErrValueMustBeUnsigned = "value must be a %d-bit unsigned integer"

	// ErrValueMustBeCons is raised when a complex Unwrap call can't treat its
	// source as a data.Cons
	ErrValueMustBeCons = "value must be a cons cell"

	// ErrValueMustBeFloat is raised when a float Unwrap call can't treat its
	// source as a data.Integer or data.Float
	ErrValueMustBeFloat = "value must be a float"

	// ErrConsMustContainFloat is raised when a complex Unwrap call can't treat
	// its source's components as data.Floats
	ErrConsMustContainFloat = "components must be float values"
)
View Source
const AleTag = "ale"

AleTag identifies the tag used to specify the kwd used when wrapping a struct as an Object

View Source
const ErrChannelCoercionNotSupported = "value cannot be coerced into chan"

ErrChannelCoercionNotSupported is raised when a channel Unwrap is called

View Source
const ErrCycleDetected = "cycle detected in wrapping"

ErrCycleDetected is raised when wrapping encounters a reference cycle

View Source
const ErrMustImplementValue = "must implement value"

ErrMustImplementValue is raised when a value Unwrap call can't treat its source as a data.Value

View Source
const ErrUnsupportedType = "unsupported type"

ErrUnsupportedType is raised when wrapping encounters an unsupported type

View Source
const ErrValueMustBeBool = "value must be a bool"

ErrValueMustBeBool is raised when a boolean Unwrap call can't treat its source as a data.Bool

View Source
const (
	ErrValueMustBeBoxed = "value must be a boxed value"
)
View Source
const ErrValueMustBeProcedure = "value must be a procedure"

ErrValueMustBeProcedure is raised when a function Unwrap call can't treat its source as a data.Procedure

View Source
const ErrValueMustBeString = "value must be a byte slice or string"

ErrValueMustBeString is raised when a string Unwrap call can't treat its source as a data.String

View Source
const ReceiverKey = data.Keyword("receiver")

ReceiverKey is the key used to store an interface receiver

Variables

This section is empty.

Functions

func MustWrap

func MustWrap(i any) ale.Value

MustWrap wraps a Go value into a data.Value or explodes violently

func Wrap

func Wrap(i any) (ale.Value, error)

Wrap takes a native Go value, potentially builds a Wrapper for its type, and returns a marshaled data.Value from the Wrapper

Types

type Boxed added in v0.3.0

type Boxed[T boxedTypes] struct {
	Value reflect.Value
}

Boxed is a wrapper for reflected values that are not addressable in Go, such as unsafe pointers or uintptrs

func (*Boxed[T]) Equal added in v0.3.0

func (b *Boxed[T]) Equal(other ale.Value) bool

type Context

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

Context tracks wrapped reflect.Values to detect cycles

func (*Context) Push

func (c *Context) Push(v reflect.Value) (*Context, error)

Push creates a new Context, checking the parent chain for cycles

type Wrapper

type Wrapper interface {
	Wrap(*Context, reflect.Value) (ale.Value, error)
	Unwrap(ale.Value) (reflect.Value, error)
}

Wrapper can marshal a native Go value to and from a data.Value

func WrapType

func WrapType(t reflect.Type) (Wrapper, error)

WrapType potentially builds a Wrapper for the provided reflected Type

type Wrappers

type Wrappers []Wrapper

Wrappers is a set of Wrapper

Directories

Path Synopsis
Code generated by gen_maxkind.go; DO NOT EDIT.
Code generated by gen_maxkind.go; DO NOT EDIT.

Jump to

Keyboard shortcuts

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