Header menu logo issie

ParameterTypes Module

Types

Type Description

CompSlotName

A string marking a specific integer value in a case of ComponentType. The values here are arbitrary and ComponentType-case specific and all that matters is that each value is unique within the case.

ComponentSlotExpr

For Part A: alternatively you could store slot information in the component record as an extra field. This field should store all the Component's slot information where slots are bound to parameters.

ConstrainedExpr

A parameter expression and its corresponding constraints

NewParamCompSpec

Data for a new parameterised slot being created

ParamBindings

Map from name to expression for each parameter

ParamBoxDialogState

The Elmish Model state used to manage input boxes that can be used to define parameter expressions. Part of Model.PopupDialogData.DialogState.

ParamConstraint

For MVP could allow only PInt case constraints The Errors are human-readable explanations of why violating the constraint is not allowed. They should if possible be component-specific "constant MyConstName is 3 bit width so not allowed to be less than -4".

ParamError

ParamExpression

An arithmetic expression containing symbolic parameters For MVP this could be limited to PInt and PParameter only. However, it would be useful to have a more general type definition so that functions that manipulate constraints, parameters, etc can be written in a more general way. The actual parameter value is customisable so that the same code can be used for int parameters (normal) and BigInt parameters (needed for constant values in N bit components). For MVP set 'PINT = int TODO: refactor this to use an enumeration DU for operators to reduce cases.

ParamInt

Probably needs to be bigint eventually to deal with the value of an N bit constant for n > 32.

ParamName

A named parameter in a custom component type For MVP this is ok but maybe names need to be qualified by the design sheet they are in to make functions support parameter inheritance.

ParamSlot

A slot in a component instance that can be bound to a parameter expression CompId should be a ComponentId but then we would need these types to be defined after CommonTypes. That is not possible, because we will wnat to modify CommonTypes types to use these! eventually these types can be folded into CommonTypes, and that could if need be be made recursive so solving the problem. In practice this is OK because ParamSlot is strongly typed and we will not be likely to confused CompID with any other string.

ParameterDefs

The state used per design sheet to define integer slots that have values defined with parameter expressions LoadedComponent.LCParameterSlots (also used in SheetInfo - to save / load files - but the LoadedComponent field is the only one used by HLP Teams)

Functions and values

Function or value Description

compId_

Full Usage: compId_

Returns: Lens<ParamSlot, string>

Lenses for ParamSlot

Returns: Lens<ParamSlot, string>

compSlot_

Full Usage: compSlot_

Returns: Lens<ParamSlot, CompSlotName>
Returns: Lens<ParamSlot, CompSlotName>

constraints_

Full Usage: constraints_

Returns: Lens<ConstrainedExpr, ParamConstraint list>
Returns: Lens<ConstrainedExpr, ParamConstraint list>

defaultBindings_

Full Usage: defaultBindings_

Returns: Lens<ParameterDefs, ParamBindings>

Lenses for ParamDefs

Returns: Lens<ParameterDefs, ParamBindings>

evaluateParamExpression paramBindings paramExpr

Full Usage: evaluateParamExpression paramBindings paramExpr

Parameters:
    paramBindings : ParamBindings - Map from parameter names to their bound expressions
    paramExpr : ParamExpression - The parameter expression to evaluate

Returns: Result<ParamInt, ParamError> Success: The evaluated integer value if all parameters can be resolved to constants Error: A human-readable error message listing any unresolved parameters

Evaluates a parameter expression given a set of parameter bindings.

This function recursively evaluates the expression tree, substituting parameter values from the bindings and performing arithmetic operations. Parameters are resolved to their bound expressions, which are then recursively evaluated. If any parameters remain unresolved after full evaluation, an error is returned listing them.

paramBindings : ParamBindings

Map from parameter names to their bound expressions

paramExpr : ParamExpression

The parameter expression to evaluate

Returns: Result<ParamInt, ParamError>

Success: The evaluated integer value if all parameters can be resolved to constants Error: A human-readable error message listing any unresolved parameters

exprContainsParams expression

Full Usage: exprContainsParams expression

Parameters:
Returns: bool True if the expression contains at least one PParameter, false if it only contains constants

Checks if a parameter expression contains any parameter references.

This function recursively traverses the expression tree to find any PParameter nodes. Useful for determining if an expression can be fully evaluated without parameter bindings.

expression : ParamExpression

The expression to check

Returns: bool

True if the expression contains at least one PParameter, false if it only contains constants

expression_

Full Usage: expression_

Returns: Lens<ConstrainedExpr, ParamExpression>

Lenses for ConstrainedExpr

Returns: Lens<ConstrainedExpr, ParamExpression>

newParamCompSlot_

Full Usage: newParamCompSlot_

Returns: Lens<NewParamCompSpec, CompSlotName>

Lenses for NewParamCompSpec

Returns: Lens<NewParamCompSpec, CompSlotName>

newParamConstraints_

Full Usage: newParamConstraints_

Returns: Lens<NewParamCompSpec, ParamConstraint list>
Returns: Lens<NewParamCompSpec, ParamConstraint list>

newParamExpression_

Full Usage: newParamExpression_

Returns: Lens<NewParamCompSpec, ParamExpression>
Returns: Lens<NewParamCompSpec, ParamExpression>

newParamValue_

Full Usage: newParamValue_

Returns: Lens<NewParamCompSpec, ParamInt>
Returns: Lens<NewParamCompSpec, ParamInt>

paramSlots_

Full Usage: paramSlots_

Returns: Lens<ParameterDefs, ComponentSlotExpr>
Returns: Lens<ParameterDefs, ComponentSlotExpr>

parseExpression text

Full Usage: parseExpression text

Parameters:
    text : string - The input string to parse

Returns: Result<ParamExpression, ParamError> Success: The parsed parameter expression Error: A human-readable error message describing the parsing failure

Parses a string into a parameter expression AST.

Supports arithmetic expressions with: - Integer constants - Parameter names (alphanumeric identifiers) - Binary operators: +, -, *, /, % - Parentheses for grouping Operator precedence (higher binds tighter): - *, /, %: Higher precedence - +, -: Lower precedence The parser uses recursive descent with separate functions for each precedence level.

text : string

The input string to parse

Returns: Result<ParamExpression, ParamError>

Success: The parsed parameter expression Error: A human-readable error message describing the parsing failure

renderParamExpression expr precedence

Full Usage: renderParamExpression expr precedence

Parameters:
    expr : ParamExpression - The parameter expression to render
    precedence : int - The precedence context (higher values require more parentheses)

Returns: string A string representation of the expression with minimal parentheses

Converts a parameter expression to its string representation with proper operator precedence.

Precedence levels: - Addition/Subtraction: 1 - Multiplication/Division: 2 - Remainder: 3 (always parenthesized) Parentheses are added when the current operator has lower precedence than the context.

expr : ParamExpression

The parameter expression to render

precedence : int

The precedence context (higher values require more parentheses)

Returns: string

A string representation of the expression with minimal parentheses

Type something to start searching.