asyncpi

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

asyncpi Build Status GoDoc

An implementation of asynchronous π-calculus in Go.

The basic syntax accept is given below, for details (including syntactic sugar), see godoc.

P,Q ::= 0           nil process
      | P|Q         parallel composition of P and Q
      | (new a)P    generation of a with scope P
      | !P          replication of P, i.e. infinite parallel composition  P|P|P...
      | u<v>        output of v on channel u
      | u(x).P      input of distinct variables x on u, with continuation P

Install

go get go.nickng.io/asyncpi

License

asyncpi is licensed under the Apache License

Documentation

Overview

Package asyncpi provides a simple library to work with π-calculus.

The asyncpi package consists of a parser of asynchronous π-calculus and Go code generator to execute the calculus.

Syntax

The basic syntax of the input language is as follows:

P,Q ::= 0           nil process
      | P|Q         parallel composition of P and Q
      | (new a)P    generation of a with scope P
      | !P          replication of P, i.e. infinite parallel composition  P|P|P...
      | u<v>        output of v on channel u
      | u(x).P      input of distinct variables x on u, with continuation P

The input language accepted is slightly more flexible with some syntactic sugar. For instance, consecutive new scope can be grouped together, for example:

(new a,b,c)P

Which is equivalent to:

(new a)(new b)(new c)P

Another optional syntax accepted in the input language is type annotations on the names being created. This feature is mainly designed for code generation. The following annotation attaches the type int to the name i.

(new i:int)P

However, the annotation is only a hint, the type inference may assign i with a different type if its usage does not match the annotation.

(new i:int)i<>

Since i is used as a channel, i cannot be of type int, the annotation is therefore ignored.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid argument")

Functions

func Bind

func Bind(p *Process) error

Bind takes a parsed process p and returned a process with valid binding.

func IsFreeName

func IsFreeName(x Name) bool

func IsSameName

func IsSameName(x, y Name) bool

IsSameName is a simple comparison operator for Name. A Name x is equal with another Name y when x and y has the same name. This comparison ignores the underlying representation (sort, type, etc.).

func Reduce1

func Reduce1(p Process) (changed bool, err error)

Reduce1 performs a single step of reduction for Process p.

func Subst

func Subst(p Process, vs, xs []Name) error

Subst is the substitution of variables xs by names vs in Process p.

The caller must ensure that the size of xs and vs are the same such that xs[i] is substituted by vs[i] in 0 <= i < len(xs).

Types

type ImmutableNameError

type ImmutableNameError struct {
	Name Name
}

ImmutableNameError is the type of error when trying to modify a name without setter methods.

func (ImmutableNameError) Error

func (e ImmutableNameError) Error() string

type Name

type Name interface {
	Ident() string
	String() string
}

Name is channel or value.

func FreeNames

func FreeNames(n Name) []Name

FreeNames returns the free names in a give Name n.

func FreeVars

func FreeVars(n Name) []Name

FreeVars returns the free variables in a give Name n.

type NilProcess

type NilProcess struct{}

NilProcess is the inaction process.

func NewNilProcess

func NewNilProcess() *NilProcess

NewNilProcess creates a new inaction process.

func (*NilProcess) Calculi

func (p *NilProcess) Calculi() string

func (*NilProcess) FreeNames

func (n *NilProcess) FreeNames() []Name

FreeNames of NilProcess is defined to be empty.

func (*NilProcess) FreeVars

func (n *NilProcess) FreeVars() []Name

FreeVars of NilProcess is defined to be empty.

func (*NilProcess) String

func (n *NilProcess) String() string

type Par

type Par struct {
	Procs []Process
}

Par is parallel composition of P and Q.

func NewPar

func NewPar(P, Q Process) *Par

NewPar creates a new parallel composition.

func (*Par) Calculi

func (p *Par) Calculi() string

func (*Par) FreeNames

func (p *Par) FreeNames() []Name

FreeNames of Par is the free names of composed processes.

func (*Par) FreeVars

func (p *Par) FreeVars() []Name

FreeVars of Par is the free names of composed processes.

func (*Par) String

func (p *Par) String() string

type ParseError

type ParseError struct {
	Pos TokenPos
	Err string // Error string returned from parser.
}

ParseError is the type of error when parsing an asyncpi process.

func (*ParseError) Error

func (e *ParseError) Error() string

type Process

type Process interface {
	FreeNames() []Name
	FreeVars() []Name

	// Calculi returns the calculi representation.
	Calculi() string
	String() string
}

Process is process prefixed with action.

func Parse

func Parse(r io.Reader) (Process, error)

Parse is the entry point to the asyncpi calculus parser.

Example

This example shows how the parser should be invoked.

proc, err := Parse(strings.NewReader("(new a) (a<v> | a(x).b(y).0 | b<u>)"))
if err != nil {
	fmt.Println(err) // Parse failed
}
fmt.Println(proc.String())
Output:

restrict(a,par[ par[ send(a,[v]) | recv(a,[x]).recv(b,[y]).inact ] | send(b,[u]) ])

func SimplifyBySC

func SimplifyBySC(p Process) (Process, error)

SimplifyBySC simplifies a Process p by structural congruence rules.

It applies functions to (1) remove unnecessary Restrict, and (2) remove superfluous inact.

type Recv

type Recv struct {
	Chan Name    // Channel to receive from.
	Vars []Name  // Variable expressions.
	Cont Process // Continuation.
}

Recv is input of Vars on channel Chan, with continuation Cont.

func NewRecv

func NewRecv(u Name, P Process) *Recv

NewRecv creates a new Recv with given channel.

func (*Recv) Calculi

func (p *Recv) Calculi() string

func (*Recv) FreeNames

func (r *Recv) FreeNames() []Name

FreeNames of Recv is the channel and FreeNames of the continuation.

func (*Recv) FreeVars

func (r *Recv) FreeVars() []Name

FreeVars of Recv is the channel and FreeVars in continuation minus received variables.

func (*Recv) SetVars

func (r *Recv) SetVars(vars []Name)

SetVars give name to what is received.

func (*Recv) String

func (r *Recv) String() string

type Repeat

type Repeat struct {
	Proc Process
}

Repeat is a replicated Process.

func NewRepeat

func NewRepeat(P Process) *Repeat

NewRepeat creates a new replicated process.

func (*Repeat) Calculi

func (p *Repeat) Calculi() string

func (*Repeat) FreeNames

func (r *Repeat) FreeNames() []Name

FreeNames of Repeat are FreeNames in Proc.

func (*Repeat) FreeVars

func (r *Repeat) FreeVars() []Name

FreeVars of Repeat are FreeVars in Proc.

func (*Repeat) String

func (r *Repeat) String() string

type Restrict

type Restrict struct {
	Name Name
	Proc Process
}

Restrict is scope of Process.

func NewRestrict

func NewRestrict(a Name, P Process) *Restrict

NewRestrict creates a new restriction.

func NewRestricts

func NewRestricts(a []Name, p Process) *Restrict

NewRestricts creates consecutive restrictions from a slice of Names.

func (*Restrict) Calculi

func (p *Restrict) Calculi() string

func (*Restrict) FreeNames

func (r *Restrict) FreeNames() []Name

FreeNames of Restrict are FreeNames in Proc excluding Name.

func (*Restrict) FreeVars

func (r *Restrict) FreeVars() []Name

FreeVars of Restrict are FreeVars in Proc.

func (*Restrict) String

func (r *Restrict) String() string

type Send

type Send struct {
	Chan Name   // Channel to send to.
	Vals []Name // Values to send.
}

Send is output of Vals on channel Chan.

func NewSend

func NewSend(u Name) *Send

NewSend creates a new Send with given channel.

func (*Send) Calculi

func (p *Send) Calculi() string

func (*Send) FreeNames

func (s *Send) FreeNames() []Name

FreeNames of Send is the channel and the Vals.

func (*Send) FreeVars

func (s *Send) FreeVars() []Name

FreeVars of Send is the Vals.

func (*Send) SetVals

func (s *Send) SetVals(vals []Name)

SetVals determine what to send.

func (*Send) String

func (s *Send) String() string

type TokenPos

type TokenPos struct {
	Char  int
	Lines []int
}

TokenPos is a pair of coordinate to identify start of token.

func (TokenPos) CaretDiag

func (pos TokenPos) CaretDiag(b []byte) []byte

CaretDiag returns the input b with caret to locate error position for diagnosis.

func (TokenPos) String

func (p TokenPos) String() string

type UnknownProcessError

type UnknownProcessError struct {
	Proc Process
}

UnknownProcessError is the type of error when a type switch encounters an unknown Process implementation.

The Process implementation may be valid but the caller does not anticipate or handle it.

func (UnknownProcessError) Error

func (e UnknownProcessError) Error() string

Directories

Path Synopsis
cmd
asyncpi
Command asyncpi is a REPL frontend for the asyncpi package.
Command asyncpi is a REPL frontend for the asyncpi package.
codegen
golang
Package golang provides a golang codegen backend for the asyncpi package.
Package golang provides a golang codegen backend for the asyncpi package.
internal
errors
Package errors provides internal error handlign routines.
Package errors provides internal error handlign routines.
name
Package name provides internal default implementations of the asyncpi Names.
Package name provides internal default implementations of the asyncpi Names.
Package name contains support functions for working with Name.
Package name contains support functions for working with Name.
sortedname
Package sortedname provides a specialised Name implementation associating sorts with a Name.
Package sortedname provides a specialised Name implementation associating sorts with a Name.
Package types declares the types and implements the algorithms for type inference for programs written using the asyncpi package.
Package types declares the types and implements the algorithms for type inference for programs written using the asyncpi package.

Jump to

Keyboard shortcuts

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