package smtml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Smtml.EvalSource

Operators and Evaluation Functions. This module defines types and functions for representing and evaluating various kinds of operations, including unary, binary, ternary, relational, conversion, and n-ary operations. It also defines exceptions for handling errors during evaluation.

Operation Types

Sourcetype op_type = [
  1. | `Unop of Ty.Unop.t
    (*

    Unary operation.

    *)
  2. | `Binop of Ty.Binop.t
    (*

    Binary operation.

    *)
  3. | `Relop of Ty.Relop.t
    (*

    Relational operation.

    *)
  4. | `Triop of Ty.Triop.t
    (*

    Ternary operation.

    *)
  5. | `Cvtop of Ty.Cvtop.t
    (*

    Conversion operation.

    *)
  6. | `Naryop of Ty.Naryop.t
    (*

    N-ary operation.

    *)
]

A type representing various kinds of operations.

Exceptions

Sourceexception DivideByZero

Exception raised when a division by zero occurs during evaluation.

Sourceexception Conversion_to_integer
Sourceexception Integer_overflow
Sourceexception Index_out_of_bounds
Sourceexception Value of Ty.t

Exception raised when an invalid value is encountered during evaluation.

Sourceexception TypeError of {
  1. index : int;
    (*

    The position of the erroneous value in the operation.

    *)
  2. value : Value.t;
    (*

    The actual value that caused the error.

    *)
  3. ty : Ty.t;
    (*

    The expected type.

    *)
  4. op : op_type;
    (*

    The operation that led to the error.

    *)
  5. msg : string;
}

Exception raised when a type error occurs during evaluation.

Evaluation Functions

Sourceval unop : Ty.t -> Ty.Unop.t -> Value.t -> Value.t

unop ty op v applies a unary operation op on the value v of type ty. Raises TypeError if the value does not match the expected type.

Sourceval binop : Ty.t -> Ty.Binop.t -> Value.t -> Value.t -> Value.t

binop ty op v1 v2 applies a binary operation op on the values v1 and v2 of type ty. Raises DivideByZero if the operation involves division by zero. Raises TypeError if the values do not match the expected type.

Sourceval triop : Ty.t -> Ty.Triop.t -> Value.t -> Value.t -> Value.t -> Value.t

triop ty op v1 v2 v3 applies a ternary operation op on the values v1, v2, and v3 of type ty. Raises TypeError if any value does not match the expected type.

Sourceval relop : Ty.t -> Ty.Relop.t -> Value.t -> Value.t -> bool

relop ty op v1 v2 applies a relational operation op on the values v1 and v2 of type ty. Returns true if the relation holds, otherwise false. Raises TypeError if the values do not match the expected type.

Sourceval cvtop : Ty.t -> Ty.Cvtop.t -> Value.t -> Value.t

cvtop ty op v applies a conversion operation op on the value v of type ty. Raises TypeError if the value does not match the expected type.

Sourceval naryop : Ty.t -> Ty.Naryop.t -> Value.t list -> Value.t

naryop ty op vs applies an n-ary operation op on the list of values vs of type ty. Raises TypeError if any value does not match the expected type.

OCaml

Innovation. Community. Security.