vm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EndOfStream = errors.New("end of stream")

The constant value reports that End Of Stream

Functions

This section is empty.

Types

type Addr

type Addr uint32

Addr is data type on defining heap addresses

func (Addr) IsWritable

func (addr Addr) IsWritable() bool

func (Addr) ReadOnly

func (addr Addr) ReadOnly() Addr

func (Addr) String

func (addr Addr) String() string

func (Addr) Value

func (addr Addr) Value() uint32

type Generator

type Generator func([]Addr) Stream

Generator is σ-expressions that define ground facts for the application context. Typically, Generator fetches ground facts from external storage.

type Heap

type Heap []xsd.Value

Heap of VM

func (*Heap) Dump

func (heap *Heap) Dump()

Dump heaps on console

func (*Heap) Get

func (heap *Heap) Get(addr Addr) xsd.Value

Get reads value from heap

func (*Heap) Put

func (heap *Heap) Put(addr Addr, val xsd.Value)

Put writes value to heap by the address

func (*Heap) UnsafeGet

func (heap *Heap) UnsafeGet(addr Addr) xsd.Value

type Reader

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

VM returns Reader as a result of σ-application. VM associates reader object with goal of the application (σ-stream) that allows a client to use `interface{ Read([]any) error }` as lazy consumer of the relation.

func (*Reader) Read

func (reader *Reader) Read(seq []xsd.Value) error

Read "car" (head of the stream) into container

func (*Reader) ToSeq

func (reader *Reader) ToSeq() [][]xsd.Value

ToSeq evaluates the stream and copy context into sequence of relation

type Stream

type Stream interface {
	// init stream & read head
	Init(*Heap) error
	// continue stream reading
	Read(*Heap) error
}

Stream of relations is core abstraction used by the VM. Stream produces lazy sequence of relations (tuples).

for err := stream.Init(&h); err == nil; err = stream.Read(&h) {
 ...
}

func Eq

func Eq(x, y []Addr, stream Stream) Stream

func Horn

func Horn(seq ...Stream) Stream

Horn clause corresponds to join (⨝) operator

func Join

func Join(lhs, rhs Stream) Stream

Join is a fundamental stream combinator, it builds a new stream by evaluating a tail stream for each element of head stream.

for err := head.Init(&h); err == nil; err = head.Read(&h) {
  for err := tail.Init(&h); err == nil; err = tail.Read(&h) {
    ...
  }
}

type VM

type VM struct {
	Heap Heap
}

Sigma VM

func New

func New(memSize int) *VM

New creates new instance of VM

func (*VM) Run

func (vm *VM) Run(head []Addr, stream Stream) [][]xsd.Value

Evaluates Stream, return sequence of relations

func (*VM) Stream

func (vm *VM) Stream(head []Addr, stream Stream) *Reader

Creates Reader for given Stream and evaluates its goals

Jump to

Keyboard shortcuts

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