@informalsystems/quint
Version:
Core tool for the Quint specification language
75 lines (74 loc) • 3.69 kB
TypeScript
/**
* Definitions on how to evaluate Quint builtin operators and values.
*
* The definitions are heavily based on the original `compilerImpl.ts` file written by Igor Konnov.
*
* @author Igor Konnov, Gabriela Moreira
*
* @module
*/
import { Either } from '@sweet-monads/either';
import { QuintError } from '../../quintError';
import { Context } from './Context';
import { RuntimeValue } from './runtimeValue';
import { EvalFunction } from './builder';
/**
* Evaluates the given Quint builtin value by its name.
*
* This function is responsible for handling the evaluation of builtin values
* (operators that do not take parameters). It returns an `EvalFunction`
* which, when executed, provides the corresponding `RuntimeValue` or an error.
*
* The supported builtin values are:
* - 'Bool': Returns a set containing boolean values `true` and `false`.
* - 'Int': Returns an infinite set representing all integers.
* - 'Nat': Returns an infinite set representing all natural numbers.
* - 'q::lastTrace': Returns the list of the last trace from the context.
*
* If the provided name does not match any of the supported builtin values,
* it returns an error indicating the unknown builtin.
*
* @param name - The name of the builtin value to evaluate.
* @returns An `EvalFunction` that evaluates to the corresponding `RuntimeValue` or an error.
*/
export declare function builtinValue(name: string): EvalFunction;
/**
* A list of operators that must be evaluated lazily.
* These operators cannot have their arguments evaluated before their own evaluation for various reasons:
* - Short-circuit operators (e.g., `and`, `or`, `implies`) where evaluation stops as soon as the result is determined.
* - Conditional operators (e.g., `ite`, `matchVariant`) where only certain arguments are evaluated based on conditions.
* - Repetition operators (e.g., `reps`) where the number of repetitions is unknown before evaluation.
* - Operators that interact with state variables in a special way (e.g., `assign`, `next`).
* - Operators where we can save resources (e.g., using `#pick()` in `oneOf` instead of enumerating the set).
*/
export declare const lazyOps: string[];
/**
* Evaluates the given lazy builtin operator by its name.
*
* This function handles the evaluation of lazy builtin operators,
* which require special handling as described in the `lazyOps` documentation.
* It returns a function that takes a context and a list of evaluation functions,
* and returns the result of evaluating the operator.
*
* If the provided operator does not match any of the supported lazy operators,
* it returns an error indicating the unknown operator.
*
* @param op - The name of the lazy builtin operator to evaluate.
* @returns A function that evaluates the operator with the given context and arguments.
*/
export declare function lazyBuiltinLambda(op: string): (ctx: Context, args: EvalFunction[]) => Either<QuintError, RuntimeValue>;
/**
* Evaluates the given builtin operator by its name.
*
* This function handles the evaluation of builtin operators,
* which require the arguments to be pre-evaluated. It returns
* a function that takes a context and a list of runtime values,
* and returns the result of evaluating the operator.
*
* If the provided operator does not match any of the supported operators,
* it returns an error indicating the unknown operator.
*
* @param op - The name of the builtin operator to evaluate.
* @returns A function that evaluates the operator with the given context and arguments.
*/
export declare function builtinLambda(op: string): (ctx: Context, args: RuntimeValue[]) => Either<QuintError, RuntimeValue>;