recompiler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GeneratedImports []string

PrependImport registers a Go import path for the generated file. Not a runtime operation; used by the compiler to track imports.

Functions

func Add

func Add(a, b any) any

Type-dispatch numeric operations.

func ArrayGet

func ArrayGet(arr any, idx int64) any

func ArrayLen

func ArrayLen(arr any) int64

Array helpers.

func ArrayPush

func ArrayPush(arr any, val any) any

func ArraySet

func ArraySet(arr any, idx int64, val any) any

func CallFunc

func CallFunc(fn any, env *Env, args ...any) any

CallFunc calls a function value with the given arguments. Typed function variables are resolved to direct calls at compile time (see compileCallExpression in compiler.go); this function serves as the runtime fallback for truly dynamic cases only.

func CompleteGoJob

func CompleteGoJob(id int)

CompleteGoJob marks a goroutine job as done.

func Deref

func Deref(p any) any

Deref dereferences a pointer to get its value. Accepts *Ptr or any (will try type assertion).

func Div

func Div(a, b any) any

func Eq

func Eq(a, b any) bool

func ExpandStr

func ExpandStr(s string, env *Env) string

String interpolation: $var expansion with env fallback.

func GreaterEq

func GreaterEq(a, b any) bool

func GreaterThan

func GreaterThan(a, b any) bool

func IsTruthy

func IsTruthy(v any) bool

Truthy check: Kamishell truthiness semantics.

func LessEq

func LessEq(a, b any) bool

func LessThan

func LessThan(a, b any) bool

func MemberGet

func MemberGet(obj any, prop string) any

MemberGet gets a member value from an object. This should not be reached for well-formed programs — all member access should be resolved at compile time. Panics to surface bugs immediately.

func Mod

func Mod(a, b any) any

func Mul

func Mul(a, b any) any

func NewError

func NewError(msg string) error

func NotEq

func NotEq(a, b any) bool

func RegisterGoJob

func RegisterGoJob(cmd string) int

RegisterGoJob registers a goroutine-based background job and returns its ID.

func ResetImports

func ResetImports()

ResetImports clears the global import tracker and background job state. Called at the start of every compiled main() to prevent state leaks between runs.

func SetPtr

func SetPtr(p any, val any)

SetPtr sets the value through a pointer. Accepts *Ptr or any (will try type assertion).

func Sub

func Sub(a, b any) any

func ToStr

func ToStr(v any) string

ToStr converts any value to its string representation.

func WaitAll

func WaitAll()

WaitAll blocks until all background jobs finish.

func WaitAllTimeout

func WaitAllTimeout(secs any)

WaitAllTimeout blocks until all jobs finish or timeout.

Types

type CompiledScript

type CompiledScript struct {
	Source  string
	Imports []string
}

func Compile

func Compile(program *core.Program) (*CompiledScript, error)

type Env

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

func NewEnv

func NewEnv() *Env

func (*Env) Get

func (e *Env) Get(name string) (any, bool)

Get implements builtin.Environment — returns string as any.

func (*Env) GetInt

func (e *Env) GetInt(name string) int64

func (*Env) GetStr

func (e *Env) GetStr(name string) string

func (*Env) GetString

func (e *Env) GetString(name string) (string, bool)

GetString retrieves a string value directly (no boxing).

func (*Env) Set

func (e *Env) Set(name string, val any)

Set implements builtin.Environment — converts any to string via ToStr.

func (*Env) SetBool

func (e *Env) SetBool(name string, v bool)

func (*Env) SetFloat

func (e *Env) SetFloat(name string, v float64)

func (*Env) SetInt

func (e *Env) SetInt(name string, v int64)

func (*Env) SetStr

func (e *Env) SetStr(name string, v string)

func (*Env) SetString

func (e *Env) SetString(name string, val string)

SetString stores a string value directly (no boxing).

type Ptr

type Ptr struct {
	Get func() any
	Set func(any)
}

Ptr represents a pointer to a variable in compiled Kami code. Uses closures to capture variable references without relying on Env.

func NewPtr

func NewPtr(get func() any, set func(any)) *Ptr

NewPtr creates a pointer to a variable with any-typed closures. get returns the current value, set updates it.

func NewPtrBool

func NewPtrBool(get func() bool, set func(bool)) *Ptr

NewPtrBool creates a pointer to a bool variable.

func NewPtrFloat64

func NewPtrFloat64(get func() float64, set func(float64)) *Ptr

NewPtrFloat64 creates a pointer to a float64 variable.

func NewPtrInt64

func NewPtrInt64(get func() int64, set func(int64)) *Ptr

NewPtrInt64 creates a pointer to an int64 variable.

func NewPtrString

func NewPtrString(get func() string, set func(string)) *Ptr

NewPtrString creates a pointer to a string variable.

type Task

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

Task represents a goroutine future result.

func NewTask

func NewTask() *Task

func (*Task) SetError

func (t *Task) SetError(e error)

func (*Task) SetResult

func (t *Task) SetResult(v any)

func (*Task) Wait

func (t *Task) Wait() (any, error)

func (*Task) WaitTimeout

func (t *Task) WaitTimeout(secs int64) (any, error)

Jump to

Keyboard shortcuts

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