compiler

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: AGPL-3.0, AGPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Overview

The compiler package provides a compiler and Go runtime for a subset of the IFQL language. Only pure functions are supported by the compiler. A function is compiled and then may be called repeatedly with different arguments. The function must be pure meaning it has no side effects. Other language features are not supported.

This runtime is not portable by design. The runtime consists of Go types that have been constructed based on the IFQL function being compiled. Those types are not serializable and cannot be transported to other systems or environments. This design is intended to limit the scope under which compilation must be supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompilationCache

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

CompilationCache caches compilation results based on the types of the input parameters.

func NewCompilationCache

func NewCompilationCache(fn *semantic.FunctionExpression) *CompilationCache

func (*CompilationCache) Compile

func (c *CompilationCache) Compile(types map[string]semantic.Type) (Func, error)

Compile returnes a compiled function bsaed on the provided types. The result will be cached for subsequent calls.

type Evaluator

type Evaluator interface {
	Type() semantic.Type
	EvalBool(scope Scope) bool
	EvalInt(scope Scope) int64
	EvalUInt(scope Scope) uint64
	EvalFloat(scope Scope) float64
	EvalString(scope Scope) string
	EvalRegexp(scope Scope) *regexp.Regexp
	EvalTime(scope Scope) Time
	EvalObject(scope Scope) *Object
}

type Func

type Func interface {
	Type() semantic.Type
	Eval(scope Scope) (Value, error)
	EvalBool(scope Scope) (bool, error)
	EvalInt(scope Scope) (int64, error)
	EvalUInt(scope Scope) (uint64, error)
	EvalFloat(scope Scope) (float64, error)
	EvalString(scope Scope) (string, error)
	EvalRegexp(scope Scope) (*regexp.Regexp, error)
	EvalTime(scope Scope) (Time, error)
	EvalObject(scope Scope) (*Object, error)
}

func Compile

func Compile(f *semantic.FunctionExpression, inTypes map[string]semantic.Type) (Func, error)

type Object

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

func NewObject

func NewObject() *Object

func (*Object) Bool

func (o *Object) Bool() bool

func (*Object) Float

func (o *Object) Float() float64

func (*Object) Get

func (o *Object) Get(name string) Value

func (*Object) Int

func (o *Object) Int() int64

func (*Object) Object

func (o *Object) Object() *Object

func (*Object) Regexp added in v0.0.6

func (o *Object) Regexp() *regexp.Regexp

func (*Object) Set

func (o *Object) Set(name string, v Value)

func (*Object) SetPropertyType

func (o *Object) SetPropertyType(name string, t semantic.Type)

func (*Object) Str

func (o *Object) Str() string

func (*Object) Time

func (o *Object) Time() Time

func (*Object) Type

func (o *Object) Type() semantic.Type

func (*Object) UInt

func (o *Object) UInt() uint64

type Scope

type Scope map[string]Value

func (Scope) GetBool

func (s Scope) GetBool(name string) bool

func (Scope) GetFloat

func (s Scope) GetFloat(name string) float64

func (Scope) GetInt

func (s Scope) GetInt(name string) int64

func (Scope) GetObject

func (s Scope) GetObject(name string) *Object

func (Scope) GetRegexp added in v0.0.6

func (s Scope) GetRegexp(name string) *regexp.Regexp

func (Scope) GetString

func (s Scope) GetString(name string) string

func (Scope) GetTime

func (s Scope) GetTime(name string) Time

func (Scope) GetUInt

func (s Scope) GetUInt(name string) uint64

func (Scope) Set

func (s Scope) Set(name string, v Value)

func (Scope) Type

func (s Scope) Type(name string) semantic.Type

type Time

type Time int64

type Value

type Value interface {
	Type() semantic.Type
	Bool() bool
	Int() int64
	UInt() uint64
	Float() float64
	Str() string
	Regexp() *regexp.Regexp
	Time() Time
	Object() *Object
}

func NewBool

func NewBool(v bool) Value

func NewFloat

func NewFloat(v float64) Value

func NewInt

func NewInt(v int64) Value

func NewRegexp added in v0.0.6

func NewRegexp(v *regexp.Regexp) Value

func NewString

func NewString(v string) Value

func NewTime

func NewTime(v Time) Value

func NewUInt

func NewUInt(v uint64) Value

Jump to

Keyboard shortcuts

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