Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatLiteral ¶
FormatLiteral serializes a frozen Starlark value as a valid Starlark source literal. Used to inline closure bindings in synthetic files.
Supports: String, Int, Float, Bool, NoneType, List, Dict, Tuple, Struct. Struct values (e.g., marshaled Resources) are serialized as dict literals with sorted keys for deterministic output. Returns an error for types that cannot be represented as source literals.
Types ¶
type Callable ¶
type Callable struct {
Resource // embeds mem.Resource (source text in Data)
// Compiled bytecode — Program.Write output. Nil until Compile.
Compiled []byte
// URI identity fields — compose the opaque URI:
// mem:callable/<FuncType>/<ReceiverName>
FuncType string // named Go type: "file.Reducer", "Predicate"
Name string // function name or <action>.<param> for lambdas
// Metadata captured at extraction time.
FuncName string // function name in synthetic file ("_callable" or original)
ParamNames []string // parameter names
NumParams int // total params (for validation)
CompilerVersion uint32 // starlark.CompilerVersion at compile time
OriginalPos string // "recipe.star:42" (diagnostics only)
// contains filtered or unexported fields
}
Callable is a mem.Resource that holds a Starlark function extracted into a self-contained synthetic source file with compiled bytecode.
The URI is opaque: mem:callable/<FuncType>/<ReceiverName>. FuncType is the named Go type the callable satisfies (e.g., "file.Reducer", "Predicate"). Name is the function name or <action>.<param> for lambdas.
The Data field (inherited from Resource) holds the synthetic source text. The Compiled field holds serialized bytecode from Program.Write. Both are []byte — serializable, transferable, persistable.
Lifecycle:
- Extract(*starlark.Function) → Callable (Phase 2)
- Compile() → populates Compiled bytecode (Phase 3)
- Init(thread) → loads bytecode, extracts live fn (Phase 3)
- Fn() → returns live callable for adapter invocation
func Extract ¶
Extract introspects a *starlark.Function and produces a self-contained Callable with synthesized source text. The synthetic file inlines all closure bindings as module-level constants, making it independent of the original script.
The function name is derived from fn.ReceiverName() (or "<action>.<param>" for lambdas when the caller provides a fallback via ExtractWithName).
Parameters:
- fn: Starlark function to extract
- funcType: Go type name the callable satisfies (e.g., "file.Reducer")
Returns:
- *Callable: the extracted callable with synthesized source
- error: any extraction error
func ExtractWithName ¶
ExtractWithName is like Extract but allows the caller to specify the callable name (useful for lambdas where the default name is "lambda").
Parameters:
- fn: Starlark function to extract
- funcType: Go type name the callable satisfies (e.g., "file.Reducer")
- name: ReceiverName for the callable (overrides fn.ReceiverName())
Returns:
- *Callable: the extracted callable with synthesized source
- error: any extraction error
func NewCallable ¶
NewCallable creates a Callable with the given function type and name. The source text (Data) and compiled bytecode should be set by the extraction and compilation phases.
func (*Callable) Compile ¶
Compile compiles the synthetic source text and stores the bytecode. Called once after extraction. Idempotent — recompiling with the same source and compiler version produces the same bytecode.
func (*Callable) FuncTypeName ¶
FuncTypeName returns the Go type name this callable satisfies. Implements op.CallableResource.
type Resource ¶
type Resource struct {
op.ResourceBase
ContentType string // "callable", "json", "template", etc.
Qualifier string // type-specific qualifier (e.g., "file.Reducer/myfn" for callables)
Data []byte // raw content
Hash string // SHA-256 of Data — metadata, NOT part of URI
}
Resource represents an in-memory data resource identified by a mem: URI.
Unlike file or git resources that reference external systems, a mem.Resource holds its content directly. The Data field contains the raw bytes (source text, JSON, template content, etc.). The ContentType field classifies the content for dispatch (e.g., "callable", "json", "template").
The URI is opaque: mem:<content-type>/<qualifier>. The content hash is stored as a metadata field for change detection — NOT part of the URI. Two resources with the same URI but different hashes trigger a catalog shadow.
func NewResource ¶
NewResource creates a mem.Resource with the given content type and qualifier.
Data must be set separately; Hash is computed when ComputeHash is called.
func NewResourceWithData ¶
NewResourceWithData creates a mem.Resource with content and computes the hash.
func ResourceFromValue ¶
ResourceFromValue constructs a mem.Resource from a string mem: URI.
Parameters:
- v: expected to be a string in the format "mem:<content-type>[/<qualifier>]"
Returns:
- Resource: initialized with the parsed content type and qualifier
- error: if v is not a string or the URI format is invalid
func (*Resource) ComputeHash ¶
func (r *Resource) ComputeHash()
ComputeHash calculates the SHA-256 hash of Data and stores it in Hash.