Help us shape the future of Go! Take the 2026 Go Developer Survey

machine

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2019 License: Unlicense Imports: 17 Imported by: 0

README

Machine

A programable virtual machine.

; Anything that follows a `;` is considered a comment.
; Lines must end with a ;

; You can group and pipe the return value from one function to another.
(alert(response-time GTE 600)|recover(LT 500)).page();

; You can assign a variable from any expression that returns a value.
; Variables are considered constants and cannot be changed once set unless you delete if first with a `_delete` call
const warnID = warn(response-time GTE 300);

; You can use a variable by it's name preceded by a `$`
slack(#team-channel $warnID);

; The `_delete` call is special. It's implemented in the machine itself.
; It can be used to un-set a variable. Once a variable is unset it can be reset.
_delete(warnID);

; You can nest multiple function calls.
scale-up(env(app-name) cpu GT f0.8);

; Every value is a string.
; The only exception's from that are variables that begin with f and have a .
scale-down(env(app-name) cpu LTE f0.4);

; true and false are also special cases and are mapped to their boolean value.
enable(scaling env(app-name) true);

Reserved words

  • true

  • false

  • const

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeIL_DValue_Kind_name = map[int32]string{
	0: "STR",
	1: "FLT",
	2: "BOOL",
}
View Source
var NodeIL_DValue_Kind_value = map[string]int32{
	"STR":  0,
	"FLT":  1,
	"BOOL": 2,
}
View Source
var NodeIL_Kind_name = map[int32]string{
	0: "NONE",
	1: "ROOT",
	2: "GROUP",
	3: "FUNC",
	4: "VALUE",
	5: "ASSIGN",
	6: "VAR",
	7: "NAT",
}
View Source
var NodeIL_Kind_value = map[string]int32{
	"NONE":   0,
	"ROOT":   1,
	"GROUP":  2,
	"FUNC":   3,
	"VALUE":  4,
	"ASSIGN": 5,
	"VAR":    6,
	"NAT":    7,
}
View Source
var TokenIL_Kind_name = map[int32]string{
	0: "NONE",
	1: "VALUE",
	2: "OPEN",
	3: "CLOSE",
	4: "END",
	5: "DOT",
	6: "PIPE",
	7: "ASSIGN",
	8: "VAR",
}
View Source
var TokenIL_Kind_value = map[string]int32{
	"NONE":   0,
	"VALUE":  1,
	"OPEN":   2,
	"CLOSE":  3,
	"END":    4,
	"DOT":    5,
	"PIPE":   6,
	"ASSIGN": 7,
	"VAR":    8,
}

Functions

func LastReturn

func LastReturn(ctx context.Context) interface{}

LastReturn gets the last returned value from the context

func NodeCompare

func NodeCompare(lhs, rhs *NodeIL) bool

NodeCompare compares all nodes. The ID can be different, but all sub-values must be the same.

func Run

func Run(i *Implementation, src string) error

Run takes raw source and compiles it and runs in a new machine.

Types

type Implementation

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

Implementation contains the implementation of a machine

func (*Implementation) Func

func (i *Implementation) Func(name string, handler interface{})

Func adds a function handler to the implementation

func (*Implementation) Functions

func (i *Implementation) Functions() []string

Functions returns a list of function documentation.

type MacC

type MacC interface {
	Getenv(string) string
}

MacC is the interface available in a running program's context.

func Mac

func Mac(ctx context.Context) MacC

Mac returns the MacC from the context

type Machine

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

Machine is the VM that will run a program.

func New

func New(impl *Implementation) *Machine

New returns a new machine.

func (*Machine) Execute

func (m *Machine) Execute(p *ProgramIL) error

Execute runs the program in the machine.

func (*Machine) Getenv

func (m *Machine) Getenv(name string) string

Getenv returns the environment variable

func (*Machine) Setenv

func (m *Machine) Setenv(name string, value string)

Setenv sets an environment variable

func (*Machine) Shutdown

func (m *Machine) Shutdown()

Shutdown stops the machine.

func (*Machine) State

func (m *Machine) State() MacC

State returns the last state of the machine.

type NodeIL

type NodeIL struct {
	Id                   []byte         `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Kind                 NodeIL_Kind    `protobuf:"varint,2,opt,name=kind,proto3,enum=machine.NodeIL_Kind" json:"kind,omitempty"`
	Children             []*NodeIL      `protobuf:"bytes,3,rep,name=children,proto3" json:"children,omitempty"`
	Chained              *NodeIL        `protobuf:"bytes,4,opt,name=chained,proto3" json:"chained,omitempty"`
	Value                *NodeIL_DValue `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"`
	SubType              string         `protobuf:"bytes,6,opt,name=sub_type,json=subType,proto3" json:"sub_type,omitempty"`
	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
	XXX_unrecognized     []byte         `json:"-"`
	XXX_sizecache        int32          `json:"-"`
}

func (*NodeIL) Descriptor

func (*NodeIL) Descriptor() ([]byte, []int)

func (*NodeIL) GetChained

func (m *NodeIL) GetChained() *NodeIL

func (*NodeIL) GetChildren

func (m *NodeIL) GetChildren() []*NodeIL

func (*NodeIL) GetId

func (m *NodeIL) GetId() []byte

func (*NodeIL) GetKind

func (m *NodeIL) GetKind() NodeIL_Kind

func (*NodeIL) GetSubType

func (m *NodeIL) GetSubType() string

func (*NodeIL) GetValue

func (m *NodeIL) GetValue() *NodeIL_DValue

func (*NodeIL) ProtoMessage

func (*NodeIL) ProtoMessage()

func (*NodeIL) Reset

func (m *NodeIL) Reset()

func (*NodeIL) String

func (m *NodeIL) String() string

func (*NodeIL) XXX_DiscardUnknown

func (m *NodeIL) XXX_DiscardUnknown()

func (*NodeIL) XXX_Marshal

func (m *NodeIL) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NodeIL) XXX_Merge

func (m *NodeIL) XXX_Merge(src proto.Message)

func (*NodeIL) XXX_Size

func (m *NodeIL) XXX_Size() int

func (*NodeIL) XXX_Unmarshal

func (m *NodeIL) XXX_Unmarshal(b []byte) error

type NodeIL_DValue

type NodeIL_DValue struct {
	Kind                 NodeIL_DValue_Kind `protobuf:"varint,1,opt,name=kind,proto3,enum=machine.NodeIL_DValue_Kind" json:"kind,omitempty"`
	Str                  string             `protobuf:"bytes,2,opt,name=str,proto3" json:"str,omitempty"`
	Flt                  float64            `protobuf:"fixed64,3,opt,name=flt,proto3" json:"flt,omitempty"`
	Bool                 bool               `protobuf:"varint,4,opt,name=bool,proto3" json:"bool,omitempty"`
	XXX_NoUnkeyedLiteral struct{}           `json:"-"`
	XXX_unrecognized     []byte             `json:"-"`
	XXX_sizecache        int32              `json:"-"`
}

func (*NodeIL_DValue) Descriptor

func (*NodeIL_DValue) Descriptor() ([]byte, []int)

func (*NodeIL_DValue) GetBool

func (m *NodeIL_DValue) GetBool() bool

func (*NodeIL_DValue) GetFlt

func (m *NodeIL_DValue) GetFlt() float64

func (*NodeIL_DValue) GetKind

func (m *NodeIL_DValue) GetKind() NodeIL_DValue_Kind

func (*NodeIL_DValue) GetStr

func (m *NodeIL_DValue) GetStr() string

func (*NodeIL_DValue) ProtoMessage

func (*NodeIL_DValue) ProtoMessage()

func (*NodeIL_DValue) Reset

func (m *NodeIL_DValue) Reset()

func (*NodeIL_DValue) String

func (m *NodeIL_DValue) String() string

func (*NodeIL_DValue) XXX_DiscardUnknown

func (m *NodeIL_DValue) XXX_DiscardUnknown()

func (*NodeIL_DValue) XXX_Marshal

func (m *NodeIL_DValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NodeIL_DValue) XXX_Merge

func (m *NodeIL_DValue) XXX_Merge(src proto.Message)

func (*NodeIL_DValue) XXX_Size

func (m *NodeIL_DValue) XXX_Size() int

func (*NodeIL_DValue) XXX_Unmarshal

func (m *NodeIL_DValue) XXX_Unmarshal(b []byte) error

type NodeIL_DValue_Kind

type NodeIL_DValue_Kind int32
const (
	NodeIL_DValue_STR  NodeIL_DValue_Kind = 0
	NodeIL_DValue_FLT  NodeIL_DValue_Kind = 1
	NodeIL_DValue_BOOL NodeIL_DValue_Kind = 2
)

func (NodeIL_DValue_Kind) EnumDescriptor

func (NodeIL_DValue_Kind) EnumDescriptor() ([]byte, []int)

func (NodeIL_DValue_Kind) String

func (x NodeIL_DValue_Kind) String() string

type NodeIL_Kind

type NodeIL_Kind int32
const (
	NodeIL_NONE   NodeIL_Kind = 0
	NodeIL_ROOT   NodeIL_Kind = 1
	NodeIL_GROUP  NodeIL_Kind = 2
	NodeIL_FUNC   NodeIL_Kind = 3
	NodeIL_VALUE  NodeIL_Kind = 4
	NodeIL_ASSIGN NodeIL_Kind = 5
	NodeIL_VAR    NodeIL_Kind = 6
	NodeIL_NAT    NodeIL_Kind = 7
)

func (NodeIL_Kind) EnumDescriptor

func (NodeIL_Kind) EnumDescriptor() ([]byte, []int)

func (NodeIL_Kind) String

func (x NodeIL_Kind) String() string

type ProgramIL

type ProgramIL struct {
	Id                   []byte            `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Source               string            `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"`
	Entry                *NodeIL           `protobuf:"bytes,3,opt,name=entry,proto3" json:"entry,omitempty"`
	FuncCalls            map[string]uint64 `` /* 177-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func CompileSource

func CompileSource(src string) (*ProgramIL, error)

CompileSource takes source code and turns it into a machine program.

func (*ProgramIL) Descriptor

func (*ProgramIL) Descriptor() ([]byte, []int)

func (*ProgramIL) GetEntry

func (m *ProgramIL) GetEntry() *NodeIL

func (*ProgramIL) GetFuncCalls

func (m *ProgramIL) GetFuncCalls() map[string]uint64

func (*ProgramIL) GetId

func (m *ProgramIL) GetId() []byte

func (*ProgramIL) GetSource

func (m *ProgramIL) GetSource() string

func (*ProgramIL) IR

func (p *ProgramIL) IR() ([]byte, error)

IR returns the Intermediate Language Representation of the program

func (*ProgramIL) LoadIR

func (p *ProgramIL) LoadIR(ir []byte) error

LoadIR re-creates the program from IR

func (*ProgramIL) ProtoMessage

func (*ProgramIL) ProtoMessage()

func (*ProgramIL) Reset

func (m *ProgramIL) Reset()

func (*ProgramIL) String

func (m *ProgramIL) String() string

func (*ProgramIL) XXX_DiscardUnknown

func (m *ProgramIL) XXX_DiscardUnknown()

func (*ProgramIL) XXX_Marshal

func (m *ProgramIL) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ProgramIL) XXX_Merge

func (m *ProgramIL) XXX_Merge(src proto.Message)

func (*ProgramIL) XXX_Size

func (m *ProgramIL) XXX_Size() int

func (*ProgramIL) XXX_Unmarshal

func (m *ProgramIL) XXX_Unmarshal(b []byte) error

type RuntimeError

type RuntimeError struct {
	Code    string
	Message string
	Loc     uintptr
}

RuntimeError represents and error raised when the machine encounters something it doesn't expect.

func (RuntimeError) Error

func (e RuntimeError) Error() string

type SourceError

type SourceError struct {
	Message string
	Line    uint32
	Column  uint32
}

SourceError is returned when the source code reader encounters and error

func (*SourceError) Error

func (e *SourceError) Error() string

type SyntaxError

type SyntaxError struct {
	Token   *TokenIL
	Message string
	Node    *NodeIL
}

SyntaxError is thrown when the parser encounters a token that it is not expecting.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type TokenIL

type TokenIL struct {
	Kind                 TokenIL_Kind `protobuf:"varint,1,opt,name=kind,proto3,enum=machine.TokenIL_Kind" json:"kind,omitempty"`
	Value                string       `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	Line                 uint32       `protobuf:"varint,3,opt,name=line,proto3" json:"line,omitempty"`
	Column               uint32       `protobuf:"varint,4,opt,name=column,proto3" json:"column,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*TokenIL) Descriptor

func (*TokenIL) Descriptor() ([]byte, []int)

func (*TokenIL) GetColumn

func (m *TokenIL) GetColumn() uint32

func (*TokenIL) GetKind

func (m *TokenIL) GetKind() TokenIL_Kind

func (*TokenIL) GetLine

func (m *TokenIL) GetLine() uint32

func (*TokenIL) GetValue

func (m *TokenIL) GetValue() string

func (*TokenIL) ProtoMessage

func (*TokenIL) ProtoMessage()

func (*TokenIL) Reset

func (m *TokenIL) Reset()

func (*TokenIL) String

func (m *TokenIL) String() string

func (*TokenIL) XXX_DiscardUnknown

func (m *TokenIL) XXX_DiscardUnknown()

func (*TokenIL) XXX_Marshal

func (m *TokenIL) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TokenIL) XXX_Merge

func (m *TokenIL) XXX_Merge(src proto.Message)

func (*TokenIL) XXX_Size

func (m *TokenIL) XXX_Size() int

func (*TokenIL) XXX_Unmarshal

func (m *TokenIL) XXX_Unmarshal(b []byte) error

type TokenIL_Kind

type TokenIL_Kind int32
const (
	TokenIL_NONE   TokenIL_Kind = 0
	TokenIL_VALUE  TokenIL_Kind = 1
	TokenIL_OPEN   TokenIL_Kind = 2
	TokenIL_CLOSE  TokenIL_Kind = 3
	TokenIL_END    TokenIL_Kind = 4
	TokenIL_DOT    TokenIL_Kind = 5
	TokenIL_PIPE   TokenIL_Kind = 6
	TokenIL_ASSIGN TokenIL_Kind = 7
	TokenIL_VAR    TokenIL_Kind = 8
)

func (TokenIL_Kind) EnumDescriptor

func (TokenIL_Kind) EnumDescriptor() ([]byte, []int)

func (TokenIL_Kind) String

func (x TokenIL_Kind) String() string

Jump to

Keyboard shortcuts

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