sourcecode

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package defines source code entities - abstractions that end-user (a programmer) operates on. For convenience these structures have json tags. This is not clean architecture but it's very handy for LSP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayBypassConnection

type ArrayBypassConnection struct {
	SenderOutport  PortAddr `json:"senderOutport,omitempty"`
	ReceiverInport PortAddr `json:"receiverOutport,omitempty"`
}

type Binary added in v0.26.0

type Binary struct {
	Left     ConnectionSender `json:"left,omitempty"`
	Right    ConnectionSender `json:"right,omitempty"`
	Operator BinaryOperator   `json:"operator,omitempty"`
	Meta     core.Meta        `json:"meta,omitempty"`
	// This field is result of semantic analysis and is unknown at parsing time.
	// It's used by desugarer to correctly handle overloaded components.
	AnalyzedType ts.Expr `json:"type,omitempty"`
}

func (Binary) String added in v0.28.2

func (b Binary) String() string

type BinaryOperator added in v0.26.0

type BinaryOperator string
const (
	// Arithmetic
	AddOp BinaryOperator = "+"
	SubOp BinaryOperator = "-"
	MulOp BinaryOperator = "*"
	DivOp BinaryOperator = "/"
	ModOp BinaryOperator = "%"
	PowOp BinaryOperator = "**"
	// Comparison
	EqOp BinaryOperator = "=="
	NeOp BinaryOperator = "!="
	GtOp BinaryOperator = ">"
	LtOp BinaryOperator = "<"
	GeOp BinaryOperator = ">="
	LeOp BinaryOperator = "<="
	// Logical
	AndOp BinaryOperator = "&&"
	OrOp  BinaryOperator = "||"
	// Bitwise
	BitAndOp BinaryOperator = "&"
	BitOrOp  BinaryOperator = "|"
	BitXorOp BinaryOperator = "^"
	BitLshOp BinaryOperator = "<<"
	BitRshOp BinaryOperator = ">>"
)

type Build

type Build struct {
	EntryModRef core.ModuleRef            `json:"entryModRef,omitempty"`
	Modules     map[core.ModuleRef]Module `json:"modules,omitempty"`
}

Build represents all the information in source code, that must be compiled. User usually don't interacts with this abstraction, but it's important for compiler.

type Component

type Component struct {
	Interface  `json:"interface,omitempty"`
	Directives map[Directive][]string `json:"directives,omitempty"`
	Nodes      map[string]Node        `json:"nodes,omitempty"`
	Net        []Connection           `json:"net,omitempty"`
	Meta       core.Meta              `json:"meta,omitempty"`
}

Component is unit of computation.

type Connection

type Connection struct {
	Normal      *NormalConnection      `json:"normal,omitempty"`
	ArrayBypass *ArrayBypassConnection `json:"arrayBypass,omitempty"`
	Meta        core.Meta              `json:"meta,omitempty"`
}

type ConnectionReceiver

type ConnectionReceiver struct {
	PortAddr           *PortAddr   `json:"portAddr,omitempty"`
	DeferredConnection *Connection `json:"deferredConnection,omitempty"` // TODO rename to Defer
	ChainedConnection  *Connection `json:"chainedConnection,omitempty"`  // TODO rename to Chain
	Switch             *Switch     `json:"switch,omitempty"`
	Meta               core.Meta   `json:"meta,omitempty"`
}

type ConnectionSender added in v0.26.0

type ConnectionSender struct {
	PortAddr       *PortAddr `json:"portAddr,omitempty"`
	Const          *Const    `json:"const,omitempty"`
	Range          *Range    `json:"range,omitempty"`
	Unary          *Unary    `json:"unary,omitempty"`
	Binary         *Binary   `json:"binary,omitempty"`
	Ternary        *Ternary  `json:"ternary,omitempty"`
	StructSelector []string  `json:"selector,omitempty"`
	Meta           core.Meta `json:"meta,omitempty"`
}

func (ConnectionSender) String added in v0.26.0

func (s ConnectionSender) String() string

type ConnectionSideSelectors

type ConnectionSideSelectors []string

func (ConnectionSideSelectors) String

func (c ConnectionSideSelectors) String() string

type Const

type Const struct {
	TypeExpr ts.Expr    `json:"typeExpr,omitempty"`
	Value    ConstValue `json:"value,omitempty"`
	Meta     core.Meta  `json:"meta,omitempty"`
}

Const represents abstraction that allow to define reusable message value.

type ConstValue added in v0.26.0

type ConstValue struct {
	Ref     *core.EntityRef `json:"ref,omitempty"`
	Message *MsgLiteral     `json:"value,omitempty"` // literal
}

func (ConstValue) String added in v0.26.0

func (c ConstValue) String() string

type Directive

type Directive string

Directive is an explicit instruction for compiler.

type EntitiesResult added in v0.26.0

type EntitiesResult struct {
	EntityName string
	FileName   string
	Entity     Entity
}

type Entity

type Entity struct {
	IsPublic  bool       `json:"exported,omitempty"`
	Kind      EntityKind `json:"kind,omitempty"`
	Const     Const      `json:"const,omitempty"`
	Type      ts.Def     `json:"type,omitempty"`
	Interface Interface  `json:"interface,omitempty"`
	Component Component  `json:"component,omitempty"`
}

func (Entity) Meta

func (e Entity) Meta() *core.Meta

type EntityKind

type EntityKind string // It's handy to transmit strings enum instead of digital
const (
	ComponentEntity EntityKind = "component_entity"
	ConstEntity     EntityKind = "const_entity"
	TypeEntity      EntityKind = "type_entity"
	InterfaceEntity EntityKind = "interface_entity"
)

type EnumMessage

type EnumMessage struct {
	EnumRef    core.EntityRef
	MemberName string
}

type File

type File struct {
	Imports  map[string]Import `json:"imports,omitempty"`
	Entities map[string]Entity `json:"entities,omitempty"`
}

type IO

type IO struct {
	In   map[string]Port `json:"in,omitempty"`
	Out  map[string]Port `json:"out,omitempty"`
	Meta core.Meta       `json:"meta,omitempty"`
}

type Import

type Import struct {
	Module  string    `json:"moduleName,omitempty"`
	Package string    `json:"pkgName,omitempty"`
	Meta    core.Meta `json:"meta,omitempty"`
}

type Interface

type Interface struct {
	TypeParams TypeParams `json:"typeParams,omitempty"`
	IO         IO         `json:"io,omitempty,"`
	Meta       core.Meta  `json:"meta,omitempty"`
}

Interface describes abstract component.

type Module

type Module struct {
	Manifest ModuleManifest     `json:"manifest,omitempty"`
	Packages map[string]Package `json:"packages,omitempty"`
}

Module is unit of distribution.

func (Module) Entity

func (mod Module) Entity(entityRef core.EntityRef) (entity Entity, filename string, err error)

type ModuleManifest

type ModuleManifest struct {
	LanguageVersion string                    `json:"neva,omitempty" yaml:"neva,omitempty"`
	Deps            map[string]core.ModuleRef `json:"deps,omitempty" yaml:"deps,omitempty"`
}

type MsgLiteral added in v0.26.0

type MsgLiteral struct {
	Bool         *bool                 `json:"bool,omitempty"`
	Int          *int                  `json:"int,omitempty"`
	Float        *float64              `json:"float,omitempty"`
	Str          *string               `json:"str,omitempty"`
	List         []ConstValue          `json:"vec,omitempty"`
	DictOrStruct map[string]ConstValue `json:"dict,omitempty"` // TODO separate map and struct
	Enum         *EnumMessage          `json:"enum,omitempty"`
	Meta         core.Meta             `json:"meta,omitempty"`
}

func (MsgLiteral) String added in v0.26.0

func (m MsgLiteral) String() string

type Node

type Node struct {
	Directives map[Directive][]string `json:"directives,omitempty"`
	EntityRef  core.EntityRef         `json:"entityRef,omitempty"`
	TypeArgs   TypeArgs               `json:"typeArgs,omitempty"`
	ErrGuard   bool                   `json:"errGuard,omitempty"` // ErrGuard explains if node is used with `?` operator.
	DIArgs     map[string]Node        `json:"diArgs,omitempty"`   // Dependency Injection.
	Meta       core.Meta              `json:"meta,omitempty"`
}

func (Node) String

func (n Node) String() string

type NormalConnection

type NormalConnection struct {
	Senders   []ConnectionSender   `json:"sender,omitempty"`
	Receivers []ConnectionReceiver `json:"receiver,omitempty"`
	Meta      core.Meta            `json:"meta,omitempty"`
}

type Package

type Package map[string]File

func (Package) Entities

func (pkg Package) Entities() func(func(EntitiesResult) bool)

Entities iterates over all entities in the package using the range-func protocol.

func (Package) Entity

func (p Package) Entity(entityName string) (entity Entity, filename string, ok bool)

Just like program's Entity

type Port

type Port struct {
	TypeExpr ts.Expr   `json:"typeExpr,omitempty"`
	IsArray  bool      `json:"isArray,omitempty"`
	Meta     core.Meta `json:"meta,omitempty"`
}

type PortAddr

type PortAddr struct {
	Node string    `json:"node,omitempty"`
	Port string    `json:"port,omitempty"`
	Idx  *uint8    `json:"idx,omitempty"` // TODO use bool flag instead of pointer to avoid problems with equality
	Meta core.Meta `json:"meta,omitempty"`
}

func (PortAddr) String

func (p PortAddr) String() string

type Range added in v0.26.0

type Range struct {
	From int64     `json:"from"`
	To   int64     `json:"to"`
	Meta core.Meta `json:"meta,omitempty"`
}

func (Range) String added in v0.26.0

func (r Range) String() string

type Scope

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

Scope is entity reference resolver

func NewScope added in v0.27.0

func NewScope(build Build, location core.Location) Scope

NewScope returns a new scope with a given location

func (Scope) Entity

func (s Scope) Entity(entityRef core.EntityRef) (Entity, core.Location, error)

Entity returns entity by reference

func (Scope) GetComponent added in v0.29.0

func (s Scope) GetComponent(entityRef core.EntityRef) (Component, error)

func (Scope) GetEntityKind added in v0.29.0

func (s Scope) GetEntityKind(entityRef core.EntityRef) (EntityKind, error)

func (Scope) GetFirstInportName added in v0.29.0

func (s Scope) GetFirstInportName(nodes map[string]Node, portAddr PortAddr) (string, error)

func (Scope) GetFirstOutportName added in v0.29.0

func (s Scope) GetFirstOutportName(nodes map[string]Node, portAddr PortAddr) (string, error)

func (Scope) GetInterface added in v0.29.0

func (s Scope) GetInterface(ref core.EntityRef) (Interface, error)

func (Scope) GetType

func (s Scope) GetType(ref core.EntityRef) (ts.Def, ts.Scope, error)

GetType returns type definition by reference

func (Scope) IsTopType

func (s Scope) IsTopType(expr ts.Expr) bool

IsTopType returns true if expr is a top type (any)

func (Scope) Location

func (s Scope) Location() *core.Location

Location returns a location of the current scope

func (Scope) Relocate added in v0.26.0

func (s Scope) Relocate(location core.Location) Scope

Relocate returns a new scope with a given location

type Switch added in v0.26.0

type Switch struct {
	Cases   []NormalConnection   `json:"case,omitempty"`
	Default []ConnectionReceiver `json:"default,omitempty"`
	Meta    core.Meta            `json:"meta,omitempty"`
}

type Ternary added in v0.26.0

type Ternary struct {
	Condition ConnectionSender `json:"condition,omitempty"`
	Left      ConnectionSender `json:"left,omitempty"`
	Right     ConnectionSender `json:"right,omitempty"`
	Meta      core.Meta        `json:"meta,omitempty"`
}

func (Ternary) String added in v0.28.2

func (t Ternary) String() string

type TypeArgs

type TypeArgs []ts.Expr

func (TypeArgs) String

func (t TypeArgs) String() string

type TypeParams

type TypeParams struct {
	Params []ts.Param `json:"params,omitempty"`
	Meta   core.Meta  `json:"meta,omitempty"`
}

func (TypeParams) String

func (t TypeParams) String() string

func (TypeParams) ToFrame

func (t TypeParams) ToFrame() map[string]ts.Def

type Unary added in v0.26.0

type Unary struct {
	Operand  ConnectionSender `json:"expr,omitempty"`
	Operator UnaryOperator    `json:"operator,omitempty"`
	Meta     core.Meta        `json:"meta,omitempty"`
}

func (Unary) String added in v0.28.2

func (u Unary) String() string

type UnaryOperator added in v0.26.0

type UnaryOperator string
const (
	NotOp UnaryOperator = "!"
	IncOp UnaryOperator = "++"
	DecOp UnaryOperator = "--"
	NegOp UnaryOperator = "-"
)

Directories

Path Synopsis
Package typesystem implements type-system with generics and structural subtyping.
Package typesystem implements type-system with generics and structural subtyping.

Jump to

Keyboard shortcuts

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