MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / toPat

Function toPat

src/compute-engine/rubi/compile.ts:76–104  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

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 */
81function 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',

Callers 1

compileRuleFunction · 0.85

Calls 3

hasPlaceholderFunction · 0.85
sliceMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected