lang

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLangNotRegistered          = errors.New("lang not registered")
	ErrCompilerVersionMismatch    = errors.New("compiler version mismatch")
	ErrUnsupportedCompilerVersion = errors.New("unsupported compiler version")
	ErrExtensionNotRegistered     = errors.New("extension not registered")
)
View Source
var EmptyRunEnv = RunEnv{
	Print: func(string) {},
	Load: func(context.Context, *apiprogram.Path) (map[string]*apivalues.Value, *apilang.RunSummary, error) {
		return nil, nil, errors.New("load is not supported")
	},
	Call: func(context.Context, *apivalues.Value, map[string]*apivalues.Value, []*apivalues.Value, *apilang.RunSummary) (*apivalues.Value, error) {
		return nil, errors.New("call is not supported")
	},
}

Functions

This section is empty.

Types

type Catalog

type Catalog interface {
	Register(name string, l CatalogLang)

	// Returns lang name -> extensions.
	List() map[string][]string

	// Return a lang for the given name and scope.
	// If scope is empty, return a new lang.
	Acquire(name, scope string) (Lang, error)
}

type CatalogLang

type CatalogLang struct {
	New  NewLangFunc
	Exts []string // extensions without the prefix dot.
}

type ErrCanceled

type ErrCanceled struct{ CallStack []*apiprogram.CallFrame }

func (*ErrCanceled) Error

func (e *ErrCanceled) Error() string

func (*ErrCanceled) Unwrap

func (e *ErrCanceled) Unwrap() error

type ErrMissingDependencies

type ErrMissingDependencies []*apiprogram.Path

func (ErrMissingDependencies) Error

func (err ErrMissingDependencies) Error() string

type Lang

type Lang interface {
	IsCompilerVersionSupported(context.Context, string) (bool, error)

	CompileModule(
		_ context.Context,
		path *apiprogram.Path,
		src []byte,
		predecls []string,
	) (*apiprogram.Module, error)

	GetModuleDependencies(context.Context, *apiprogram.Module) ([]*apiprogram.Path, error)

	// In case of cancellation, will return ErrCanceled{Callstack: ...}.
	RunModule(
		ctx context.Context,
		env *RunEnv,
		mod *apiprogram.Module,
	) (map[string]*apivalues.Value, *apilang.RunSummary, error)

	// In case of cancellation, will return ErrCanceled{Callstack: ...}.
	CallFunction(
		ctx context.Context,
		env *RunEnv,
		fn *apivalues.Value,
		args []*apivalues.Value,
		kws map[string]*apivalues.Value,
	) (*apivalues.Value, *apilang.RunSummary, error)
}

type NewLangFunc

type NewLangFunc func(l L.L, name string) (Lang, error)

type PrintFunc

type PrintFunc func(string)

type RunEnv

type RunEnv struct {
	Scope    string
	Predecls map[string]*apivalues.Value

	// TODO: need to limit size of what can passed in this funcs to prevet DOS.
	Print PrintFunc
	Load  LoadFunc // not relevant for function calls.
	Call  CallFunc
}

func (*RunEnv) Clone

func (e *RunEnv) Clone() *RunEnv

func (*RunEnv) WithStubs

func (e *RunEnv) WithStubs() *RunEnv

Directories

Path Synopsis
starlarktest
Adapted from https://github.com/google/starlark-go/blob/master/starlarktest/starlarktest.go.
Adapted from https://github.com/google/starlark-go/blob/master/starlarktest/starlarktest.go.

Jump to

Keyboard shortcuts

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