engine

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine is an in-process engine over SysML text. It serves the execution RPCs of SysMLService — ParseSources, Evaluate, Instantiate, ExecuteAction and ExecuteState — with the same proto3 JSON answers as default-capabilities sysml-grpc, and also serves RenderView. The engine's RenderView JSON keeps its drawing shape (flattened fill/border and optional x/y/width/height), not the protojson of RenderViewResponse. WebAssembly clients decode the execution results with generated types they already hold, and no protobuf runtime is linked in, which keeps the js/wasm build small.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine serves the execution RPCs of SysMLService over protojson-shaped JSON. Calls are handled sequentially in the caller's goroutine — deterministic and free of locking — so an Engine is not safe for concurrent use.

func New

func New() (*Engine, error)

New builds an engine over the frozen standard library snapshot, under the runtime budgets a default sysml-grpc NewService runs with.

func NewWithLibrary

func NewWithLibrary(index *symbols.Index, src libs.Source, maxModels int) (*Engine, error)

NewWithLibrary builds an engine over a shared standard library snapshot. A nonpositive maxModels disables automatic eviction.

func (*Engine) Call

func (e *Engine) Call(ctx context.Context, method string, params []byte) (result []byte, err error)

Call runs the method named — a method name of SysMLService — on params, the protojson request body, and returns the protojson response body. A name the engine does not serve is refused Unimplemented, and a request that does not decode InvalidArgument, matching what stdiorpc's DiscardUnknown decode means by each.

func (*Engine) Evict

func (e *Engine) Evict(hash string)

Evict removes a cached model; absent hashes are ignored.

func (*Engine) Serve

func (e *Engine) Serve(ctx context.Context, r io.Reader, w io.Writer) error

Serve reads Content-Length-delimited frames from r and writes answers to w until r reaches its end, speaking the JSON half of stdiorpc's protocol: the same framing, envelope and error codes, with a protobuf frame refused since this product carries no protobuf. Calls are handled sequentially and answered in order.

type Error

type Error = jsonrpc.Error

Error is a refused call: the canonical status code and its message.

type F64

type F64 float64

F64 is a proto3 double under protojson: a number, or the strings "NaN", "Infinity" and "-Infinity" that protojson uses where JSON has no spelling.

func (F64) MarshalJSON

func (v F64) MarshalJSON() ([]byte, error)

MarshalJSON writes the number, or the protojson string for a non-finite one.

func (*F64) UnmarshalJSON

func (v *F64) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the number, or one of the protojson non-finite spellings.

type I64

type I64 int64

I64 is a proto3 int64/uint64 under protojson: on the wire a decimal string. Input accepts the string or, as protojson does, the bare number.

func (I64) MarshalJSON

func (v I64) MarshalJSON() ([]byte, error)

MarshalJSON writes the decimal string protojson writes.

func (*I64) UnmarshalJSON

func (v *I64) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the decimal string, or the bare number.

type JArray

type JArray struct {
	Dimensions []I64     `json:"dimensions,omitempty"`
	Elements   []*JValue `json:"elements,omitempty"`
}

type JComplex

type JComplex struct {
	Real      F64 `json:"real,omitempty"`
	Imaginary F64 `json:"imaginary,omitempty"`
}

type JDiagnostic

type JDiagnostic = fsyntax.Diagnostic

JDiagnostic is the Diagnostic message, shaped in frontend/syntax where the syntactic command answers with it too.

type JDocumentEvent added in v0.11.0

type JDocumentEvent struct {
	Kind         string           `json:"kind"`
	Time         *JDocumentValue  `json:"time,omitempty"`
	Object       *JDocumentObject `json:"object,omitempty"`
	Machine      string           `json:"machine,omitempty"`
	State        string           `json:"state,omitempty"`
	From         string           `json:"from,omitempty"`
	To           string           `json:"to,omitempty"`
	Target       *JDocumentObject `json:"target,omitempty"`
	Event        string           `json:"event,omitempty"`
	Payload      []string         `json:"payload,omitempty"`
	Alternatives []string         `json:"alternatives,omitempty"`
	Taken        string           `json:"taken,omitempty"`
	Text         string           `json:"text"`
	Token        I64              `json:"token,omitempty"`
	Step         int              `json:"step,omitempty"`
	Feature      string           `json:"feature,omitempty"`
	Value        *JValue          `json:"value,omitempty"`
}

JDocumentEvent is the DocumentEvent message: one documented record of a traced run, as the service's ExecuteState and ExecuteAction answer it.

type JDocumentObject added in v0.11.0

type JDocumentObject struct {
	InstanceId I64             `json:"instanceId,omitempty"`
	Path       string          `json:"path,omitempty"`
	Element    *JDocumentValue `json:"element,omitempty"`
}

JDocumentObject is the DocumentObject message: an object Instantiate created, by id, by the label it is reached under, and by the element declaring it.

type JDocumentValue added in v0.11.0

type JDocumentValue struct {
	ElementId     *string          `json:"elementId,omitempty"`
	StringValue   *string          `json:"stringValue,omitempty"`
	IntValue      *I64             `json:"intValue,omitempty"`
	RealValue     *F64             `json:"realValue,omitempty"`
	BoolValue     *bool            `json:"boolValue,omitempty"`
	Infinity      *bool            `json:"infinity,omitempty"`
	Quantity      *JQuantity       `json:"quantity,omitempty"`
	Object        *JDocumentObject `json:"object,omitempty"`
	BigIntValue   *string          `json:"bigIntValue,omitempty"`
	RationalValue *JRational       `json:"rationalValue,omitempty"`
	ElementType   string           `json:"elementType,omitempty"`
}

JDocumentValue is the DocumentValue message: a oneof, so at most one arm is set.

type JEnumLiteral

type JEnumLiteral struct {
	LiteralId     string  `json:"literalId,omitempty"`
	EnumerationId string  `json:"enumerationId,omitempty"`
	Name          string  `json:"name,omitempty"`
	Value         *JValue `json:"value,omitempty"`
}

type JEvaluateRequest

type JEvaluateRequest struct {
	ModelHash       string `json:"modelHash,omitempty"`
	Expression      string `json:"expression,omitempty"`
	ContextSymbolId string `json:"contextSymbolId,omitempty"`
	SubjectSymbolId string `json:"subjectSymbolId,omitempty"`
}

type JEvaluateResponse

type JEvaluateResponse struct {
	Result      *JValue        `json:"result,omitempty"`
	Error       string         `json:"error,omitempty"`
	Diagnostics []*JDiagnostic `json:"diagnostics,omitempty"`
}

type JExecuteActionRequest

type JExecuteActionRequest struct {
	ModelHash         string             `json:"modelHash,omitempty"`
	ActionSymbolId    string             `json:"actionSymbolId,omitempty"`
	Inputs            map[string]*JValue `json:"inputs,omitempty"`
	Schedule          string             `json:"schedule,omitempty"`
	PerformerSymbolId string             `json:"performerSymbolId,omitempty"`
	Trace             bool               `json:"trace,omitempty"`
	Events            []string           `json:"events,omitempty"`
	// Advance is the simulated time, in seconds, to run for; nil runs to completion.
	Advance *float64 `json:"advance,omitempty"`
}

type JExecuteActionResponse

type JExecuteActionResponse struct {
	Outputs             map[string]*JValue `json:"outputs,omitempty"`
	Error               string             `json:"error,omitempty"`
	Diagnostics         []*JDiagnostic     `json:"diagnostics,omitempty"`
	FinalTime           F64                `json:"finalTime,omitempty"`
	PerformerAttributes map[string]*JValue `json:"performerAttributes,omitempty"`
	Trace               []JDocumentEvent   `json:"trace,omitempty"`
	TraceDropped        int                `json:"traceDropped,omitempty"`
}

type JExecuteStateRequest

type JExecuteStateRequest struct {
	ModelHash            string   `json:"modelHash,omitempty"`
	StateMachineSymbolId string   `json:"stateMachineSymbolId,omitempty"`
	Events               []string `json:"events,omitempty"`
	Schedule             string   `json:"schedule,omitempty"`
	PerformerSymbolId    string   `json:"performerSymbolId,omitempty"`
	Trace                bool     `json:"trace,omitempty"`
	// Advance is the simulated time, in seconds, to run for after the events; nil runs to quiescence.
	Advance *float64 `json:"advance,omitempty"`
}

type JExecuteStateResponse

type JExecuteStateResponse struct {
	StatesVisited []string           `json:"statesVisited,omitempty"`
	FinalContext  map[string]*JValue `json:"finalContext,omitempty"`
	Error         string             `json:"error,omitempty"`
	Diagnostics   []*JDiagnostic     `json:"diagnostics,omitempty"`
	FinalTime     F64                `json:"finalTime,omitempty"`
	Trace         []JDocumentEvent   `json:"trace,omitempty"`
	TraceDropped  int                `json:"traceDropped,omitempty"`
}

type JFeatureValue

type JFeatureValue struct {
	FeatureName  string    `json:"featureName,omitempty"`
	Value        *JValue   `json:"value,omitempty"`
	Values       []*JValue `json:"values,omitempty"`
	Materialized bool      `json:"materialized,omitempty"`
	Error        string    `json:"error,omitempty"`
}

JFeatureValue is the FeatureValue message.

type JFunction

type JFunction struct {
	CalcId string `json:"calcId,omitempty"`
	SelfId I64    `json:"selfId,omitempty"`
}

type JInstance

type JInstance struct {
	Id            I64                       `json:"id,omitempty"`
	TypeSymbolId  string                    `json:"typeSymbolId,omitempty"`
	FeatureValues map[string]*JFeatureValue `json:"featureValues,omitempty"`
}

JInstance is the Instance message.

type JInstantiateRequest

type JInstantiateRequest struct {
	ModelHash string `json:"modelHash,omitempty"`
	SymbolId  string `json:"symbolId,omitempty"`
}

type JInstantiateResponse

type JInstantiateResponse struct {
	Instance    *JInstance     `json:"instance,omitempty"`
	Error       string         `json:"error,omitempty"`
	Diagnostics []*JDiagnostic `json:"diagnostics,omitempty"`
	Instances   []*JInstance   `json:"instances,omitempty"`
}

type JMeasurementRef

type JMeasurementRef struct {
	Unit     string     `json:"unit,omitempty"`
	UnitTerm *JUnitTerm `json:"unitTerm,omitempty"`
	UnitId   string     `json:"unitId,omitempty"`
}

type JMetaobject

type JMetaobject struct {
	ElementId   string `json:"elementId,omitempty"`
	MetaclassId string `json:"metaclassId,omitempty"`
}

type JMultiplicityInfo

type JMultiplicityInfo struct {
	Lower string `json:"lower,omitempty"`
	Upper string `json:"upper,omitempty"`
}

type JParseSourcesRequest

type JParseSourcesRequest struct {
	Documents         []*JSourceDocument `json:"documents,omitempty"`
	StrictConformance bool               `json:"strictConformance,omitempty"`
}

type JParseSourcesResponse

type JParseSourcesResponse struct {
	ModelHash   string         `json:"modelHash,omitempty"`
	Diagnostics []*JDiagnostic `json:"diagnostics,omitempty"`
}

type JQuantity

type JQuantity struct {
	IntMagnitude    *I64       `json:"intMagnitude,omitempty"`
	RealMagnitude   *F64       `json:"realMagnitude,omitempty"`
	Unit            string     `json:"unit,omitempty"`
	UnitTerm        *JUnitTerm `json:"unitTerm,omitempty"`
	BigIntMagnitude *string    `json:"bigIntMagnitude,omitempty"`

	RationalMagnitude *JRational `json:"rationalMagnitude,omitempty"`
}

JQuantity is the Quantity message; Magnitude is its oneof.

func (*JQuantity) UnmarshalJSON

func (q *JQuantity) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects a quantity setting both magnitude arms of its oneof.

type JRational

type JRational struct {
	Numerator   string `json:"numerator,omitempty"`
	Denominator string `json:"denominator,omitempty"`
}

JRational is the Rational message: an exact rational in lowest terms.

type JRenderCanvas

type JRenderCanvas struct {
	Unit    string  `json:"unit,omitempty"`
	Width   float64 `json:"width,omitempty"`
	Height  float64 `json:"height,omitempty"`
	HasSize bool    `json:"hasSize,omitempty"`
}

type JRenderEdge

type JRenderEdge struct {
	From     string         `json:"from,omitempty"`
	To       string         `json:"to,omitempty"`
	FromPort string         `json:"fromPort,omitempty"`
	ToPort   string         `json:"toPort,omitempty"`
	Label    string         `json:"label,omitempty"`
	Name     string         `json:"name,omitempty"`
	Kind     string         `json:"kind,omitempty"`
	Origin   *JSpan         `json:"origin,omitempty"`
	Route    []JRenderPoint `json:"route,omitempty"`
	Style    *JRenderStyle  `json:"style,omitempty"`
}

type JRenderGeometry added in v0.11.0

type JRenderGeometry struct {
	X         float64 `json:"x,omitempty"`
	Y         float64 `json:"y,omitempty"`
	Width     float64 `json:"width,omitempty"`
	Height    float64 `json:"height,omitempty"`
	HasSize   bool    `json:"hasSize,omitempty"`
	Collapsed bool    `json:"collapsed,omitempty"`
	// Unplaced marks a layout that only folds or hides: x and y carry no position.
	Unplaced bool `json:"unplaced,omitempty"`
}

type JRenderNode

type JRenderNode struct {
	ID              string           `json:"id,omitempty"`
	Kind            string           `json:"kind,omitempty"`
	Name            string           `json:"name,omitempty"`
	NameSynthesized bool             `json:"nameSynthesized,omitempty"`
	Type            string           `json:"type,omitempty"`
	Detail          string           `json:"detail,omitempty"`
	Text            string           `json:"text,omitempty"`
	StandIn         bool             `json:"standIn,omitempty"`
	Parent          string           `json:"parent,omitempty"`
	Compartment     string           `json:"compartment,omitempty"`
	Ports           []JRenderPort    `json:"ports,omitempty"`
	Origin          *JSpan           `json:"origin,omitempty"`
	Geometry        *JRenderGeometry `json:"geometry,omitempty"`
	Style           *JRenderStyle    `json:"style,omitempty"`
	Inherited       bool             `json:"inherited,omitempty"`
}

type JRenderNote added in v0.11.0

type JRenderNote struct {
	Text     string  `json:"text,omitempty"`
	Anchor   string  `json:"anchor,omitempty"`
	EdgeFrom string  `json:"edgeFrom,omitempty"`
	EdgeTo   string  `json:"edgeTo,omitempty"`
	X        float64 `json:"x,omitempty"`
	Y        float64 `json:"y,omitempty"`
	Width    float64 `json:"width,omitempty"`
	Height   float64 `json:"height,omitempty"`
	HasSize  bool    `json:"hasSize,omitempty"`
	Origin   *JSpan  `json:"origin,omitempty"`
}

type JRenderPoint

type JRenderPoint struct {
	X float64 `json:"x,omitempty"`
	Y float64 `json:"y,omitempty"`
}

type JRenderPort

type JRenderPort struct {
	ID        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Type      string `json:"type,omitempty"`
	Direction string `json:"direction,omitempty"`
	Inherited bool   `json:"inherited,omitempty"`
}

type JRenderRow

type JRenderRow struct {
	Cells  []string `json:"cells,omitempty"`
	Origin *JSpan   `json:"origin,omitempty"`
}

type JRenderStyle

type JRenderStyle struct {
	Fill     string  `json:"fill,omitempty"`
	Line     string  `json:"line,omitempty"`
	Text     string  `json:"text,omitempty"`
	Font     string  `json:"font,omitempty"`
	FontSize float64 `json:"fontSize,omitempty"`
	Bold     bool    `json:"bold,omitempty"`
	Italic   bool    `json:"italic,omitempty"`
}

type JRenderViewRequest

type JRenderViewRequest struct {
	ModelHash string   `json:"modelHash,omitempty"`
	View      string   `json:"view,omitempty"`
	Ports     string   `json:"ports,omitempty"`
	Show      []string `json:"show,omitempty"`
	Depth     int      `json:"depth,omitempty"`
	// Compartments is the folding of a tree's owned members into compartment rows:
	// "" or "positioned" (the default), "most" or "ports".
	Compartments string `json:"compartments,omitempty"`
}

type JRenderViewResponse

type JRenderViewResponse struct {
	View    string         `json:"view,omitempty"`
	Kind    string         `json:"kind,omitempty"`
	Stated  string         `json:"stated,omitempty"`
	Nodes   []JRenderNode  `json:"nodes,omitempty"`
	Edges   []JRenderEdge  `json:"edges,omitempty"`
	Columns []string       `json:"columns,omitempty"`
	Rows    []JRenderRow   `json:"rows,omitempty"`
	Canvas  *JRenderCanvas `json:"canvas,omitempty"`
	Notes   []JRenderNote  `json:"notes,omitempty"`
	Notices []string       `json:"notices,omitempty"`
	Shown   []string       `json:"shown,omitempty"`
}

type JSourceDocument

type JSourceDocument struct {
	FilePath *string `json:"filePath,omitempty"`
	Content  *string `json:"content,omitempty"`
	Language string  `json:"language,omitempty"`
	Name     string  `json:"name,omitempty"`
}

JSourceDocument is the SourceDocument message; Source is its oneof.

func (*JSourceDocument) UnmarshalJSON

func (d *JSourceDocument) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects a document naming both of its source arms.

type JSpan

type JSpan = fsyntax.Span

JSpan is the Span message.

type JTensorQuantity

type JTensorQuantity struct {
	Dimensions []I64        `json:"dimensions,omitempty"`
	Components []*JQuantity `json:"components,omitempty"`
}

type JUndetermined

type JUndetermined struct {
	Reason string             `json:"reason,omitempty"`
	Count  *JMultiplicityInfo `json:"count,omitempty"`
}

type JUnitFactor

type JUnitFactor struct {
	UnitId   string `json:"unitId,omitempty"`
	Exponent F64    `json:"exponent,omitempty"`
}

type JUnitTerm

type JUnitTerm struct {
	ScaleNum F64            `json:"scaleNum,omitempty"`
	ScaleDen F64            `json:"scaleDen,omitempty"`
	Factors  []*JUnitFactor `json:"factors,omitempty"`
}

type JValue

type JValue struct {
	IntValue       *I64             `json:"intValue,omitempty"`
	BigIntValue    *string          `json:"bigIntValue,omitempty"`
	RealValue      *F64             `json:"realValue,omitempty"`
	BoolValue      *bool            `json:"boolValue,omitempty"`
	StringValue    *string          `json:"stringValue,omitempty"`
	InstanceId     *I64             `json:"instanceId,omitempty"`
	Sequence       *JValueSequence  `json:"sequence,omitempty"`
	Null           *string          `json:"null,omitempty"`
	Quantity       *JQuantity       `json:"quantity,omitempty"`
	EnumLiteral    *JEnumLiteral    `json:"enumLiteral,omitempty"`
	Unset          *bool            `json:"unset,omitempty"`
	Complex        *JComplex        `json:"complex,omitempty"`
	Array          *JArray          `json:"array,omitempty"`
	Vector         *JVector         `json:"vector,omitempty"`
	VectorQuantity *JVectorQuantity `json:"vectorQuantity,omitempty"`
	MeasurementRef *JMeasurementRef `json:"measurementRef,omitempty"`
	Infinity       *bool            `json:"infinity,omitempty"`
	Function       *JFunction       `json:"function,omitempty"`
	Set            *JValueSet       `json:"set,omitempty"`
	TensorQuantity *JTensorQuantity `json:"tensorQuantity,omitempty"`
	Metaobject     *JMetaobject     `json:"metaobject,omitempty"`
	Undetermined   *JUndetermined   `json:"undetermined,omitempty"`
	RationalValue  *JRational       `json:"rationalValue,omitempty"`
}

JValue is the Value message: a oneof, so exactly one arm is ever set.

func (*JValue) UnmarshalJSON

func (v *JValue) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects a value setting two arms of the oneof, as protojson rejects it: a request naming more than one arm is ambiguous, not a pick.

type JValueSequence

type JValueSequence struct {
	Elements []*JValue `json:"elements,omitempty"`
}

type JValueSet

type JValueSet struct {
	Elements []*JValue `json:"elements,omitempty"`
}

type JVector

type JVector struct {
	Components []*JValue `json:"components,omitempty"`
}

type JVectorQuantity

type JVectorQuantity struct {
	Components []*JQuantity `json:"components,omitempty"`
}

Jump to

Keyboard shortcuts

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