mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-30 16:18:58 +00:00
67 lines
2.3 KiB
Forth
67 lines
2.3 KiB
Forth
//------------------------------------------------------------------------------
|
|
// This code was generated by myriad.
|
|
// Changes to this file will be lost when the code is regenerated.
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
namespace ConsumePlugin
|
|
|
|
open WoofWare.Myriad.Plugins
|
|
|
|
/// Description of how to combine cases during a fold
|
|
type ExprCata<'Expr, 'ExprBuilder> =
|
|
/// How to operate on the Const case
|
|
abstract Const : Const -> 'Expr
|
|
/// How to operate on the Pair case
|
|
abstract Pair : 'Expr -> 'Expr -> PairOpKind -> 'Expr
|
|
/// How to operate on the Sequential case
|
|
abstract Sequential : 'Expr list -> 'Expr
|
|
/// How to operate on the Builder case
|
|
abstract Builder : 'Expr -> 'ExprBuilder -> 'Expr
|
|
|
|
/// Description of how to combine cases during a fold
|
|
type ExprBuilderCata<'Expr, 'ExprBuilder> =
|
|
/// How to operate on the Child case
|
|
abstract Child : 'ExprBuilder -> 'ExprBuilder
|
|
/// How to operate on the Parent case
|
|
abstract Parent : 'Expr -> 'ExprBuilder
|
|
|
|
/// Specifies how to perform a fold (catamorphism) over the type Expr.
|
|
type Cata<'Expr, 'ExprBuilder> =
|
|
{
|
|
/// TODO: doc
|
|
Expr : ExprCata<'Expr, 'ExprBuilder>
|
|
/// TODO: doc
|
|
ExprBuilder : ExprBuilderCata<'Expr, 'ExprBuilder>
|
|
}
|
|
|
|
/// Catamorphism
|
|
[<RequireQualifiedAccess>]
|
|
module ExprCata =
|
|
[<RequireQualifiedAccess>]
|
|
type private Instruction =
|
|
| ProcessExpr of Expr
|
|
| ProcessExprBuilder of ExprBuilder
|
|
| ExprPair of PairOpKind
|
|
| ExprSequential of int
|
|
| ExprBuilder
|
|
| ExprBuilderChild
|
|
| ExprBuilderParent
|
|
|
|
/// Execute the catamorphism.
|
|
let runExpr (cata : Cata<'ExprRet, 'ExprBuilderRet>) (x : Expr) : 'ExprRet =
|
|
let instructions = ResizeArray ()
|
|
instructions.Add (Instruction.ProcessExpr x)
|
|
let ExprRetStack, ExprBuilderRetStack = loop cata instructions
|
|
Seq.exactlyOne ExprRetStack
|
|
|
|
/// Execute the catamorphism.
|
|
let runExprBuilder (cata : Cata<'ExprRet, 'ExprBuilderRet>) (x : ExprBuilder) : 'ExprBuilderRet =
|
|
let instructions = ResizeArray ()
|
|
instructions.Add (Instruction.ProcessExprBuilder x)
|
|
let ExprRetStack, ExprBuilderRetStack = loop cata instructions
|
|
Seq.exactlyOne ExprBuilderRetStack
|