* Convert a canonically boxed skeleton to matcher IR. `parentOp` / * `argIndex` give the canonical context that determines optional defaults.
( ce: ComputeEngine, expr: Expression, parentOp: string | null, _argIndex: number )
| 74 | return expr; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Convert a canonically boxed skeleton to matcher IR. `parentOp` / |
| 79 | * `argIndex` give the canonical context that determines optional defaults. |
| 80 | */ |
| 81 | function toPat( |
| 82 | ce: ComputeEngine, |
| 83 | expr: Expression, |
| 84 | parentOp: string | null, |
| 85 | _argIndex: number |
| 86 | ): Pat { |
| 87 | if (expr.symbol) { |
| 88 | if (expr.symbol === VAR) return { kind: 'var' }; |
| 89 | if (expr.symbol.startsWith(SLOT)) |
| 90 | return { kind: 'slot', name: expr.symbol.slice(SLOT.length) }; |
| 91 | if (expr.symbol.startsWith(OPT)) { |
| 92 | const dflt = parentOp === 'Add' ? ce.Zero : ce.One; |
| 93 | return { |
| 94 | kind: 'optslot', |
| 95 | name: expr.symbol.slice(OPT.length), |
| 96 | default: dflt, |
| 97 | }; |
| 98 | } |
| 99 | return { kind: 'const', value: expr }; |
| 100 | } |
| 101 | if (!expr.ops || expr.ops.length === 0 || !hasPlaceholder(expr)) |
| 102 | return { kind: 'const', value: expr }; |
| 103 | return { |
| 104 | kind: 'node', |
| 105 | op: expr.operator, |
| 106 | ops: expr.ops.map((op, i) => toPat(ce, op, expr.operator, i)), |
| 107 | ac: expr.operator === 'Add' || expr.operator === 'Multiply', |
no test coverage detected