Compiler
- class Compiler
A non-recursive compiler/virtual machine for KerML and SysML expressions.
Note that some patterns require cache of standard library elements to compute. See methods for more details.
Members defined in
Compiler(5 members)
RWMaximum number of steps an expression evaluation may take.
Evaluate an expression
expr. Note that complex custom functions and expressions, and most except a few standard library functions are not evaluatable. Constructor expressions evaluate as their return parameters because they conform to the constructed object implicitly. This primarily evaluates operator, metadata access, and feature reference expressions. If provided,stdlibis used to accelerate some common evaluations, e.g. checking forselfexpressions.
Evaluate
featureinscope, taking into account redefinitions.
Evaluate
filterexpression on the metadata oftarget. Attributes
- property max_steps: int
Maximum number of steps an expression evaluation may take.
When this is reached, evaluation stops with an error. Actual steps are an implementation detail.
Methods
- __init__(max_steps: int = 100000) None
- evaluate(expr: syside.Expression, stdlib: syside.Stdlib | None = None, scope: syside.Type | None | None = None, experimental_quantities: bool = False) tuple[syside.Value | None, syside.CompilationReport]
Evaluate an expression
expr. Note that complex custom functions and expressions, and most except a few standard library functions are not evaluatable. Constructor expressions evaluate as their return parameters because they conform to the constructed object implicitly. This primarily evaluates operator, metadata access, and feature reference expressions. If provided,stdlibis used to accelerate some common evaluations, e.g. checking forselfexpressions.Quantity Evaluation
Added in version 0.8.2.
If
experimental_quantitiesis enabled, compiler will additionally attempt to evaluate scalar quantity expressions in SI units, other systems of quantities are not supported. The results will be returned in scalarfloatand no type-checking will be performed. In the future, when typed quantities are implemented, this may be changed.Note that quantity evaluation requires
Stdlibto have found elements fromMeasurementReferenceslibrary. Additionally, evaluation is tested to work with standard library quantities and prefixes. Custom package-level prefixes and quantities are also expected to work, however any nested feature chaining may or may not work.Reflection
Added in version 0.8.5.
Reflection requires
stdlibto convert elements into reflectable values on metadata access expressions and to convert reflected elements back into reflectable values, just like they are defined in the standard metamodel classes. Any reflected elements will be returned asBoundMetaclassinstead, and reflection only works on them.Note that reflection (metadata access) is evaluated immediately on whatever symbol is referenced on the left. This means that inheritance and redefinitions have no effect - symbols will not be substituted based on scope during evaluation.
User-defined Function Evaluation
Added in version 0.8.5.
InvocationExpressionsof simple user-defined function are supported as long they have either aResultExpressionMembership, declared as the last expression inside the body without a trailing;, or areturnfeature. The former is preferred for performance reasons. As long the result or return expression is evaluatable by Syside and all input arguments have values, the invocation will be evaluated. Note that this does not add support for evaluating body expressions, like those used incollectandselectexpressions.
- evaluate_feature(feature: syside.Feature, scope: syside.Type, stdlib: syside.Stdlib | None = None, experimental_quantities: bool = False) tuple[syside.Value | None, syside.CompilationReport]
Evaluate
featureinscope, taking into account redefinitions.If
featureis anExpression, this effectively performsevaluate.
- evaluate_filter(target: syside.Element, filter: syside.Expression, stdlib: syside.Stdlib | None = None) tuple[syside.Value | None, syside.CompilationReport]
Evaluate
filterexpression on the metadata oftarget.Added in version 0.8.5.
Be aware that absolute feature references are resolved at the package level, thus if the filter expressions depends on a value of metadata attribute, use
ascast:metadata def Safety { attribute isMandatory; } filter (as Safety).isMandatory;
The cast automatically doubles as a classification test
@which can be omitted.Note that this does not support quantities because they are not model-level evaluable according to the specification, while filter expressions must be.