@@ -41,7 +41,7 @@ const result = expr({ sum, product })("sum + product");
4141
4242// 编译表达式(可序列化为 JSON)
4343const compiled = compile (result , { x , y });
44- // => [["x", "y"], "$0+$1 ", "$0*$1 ", "$2+$3 "]
44+ // => [["x", "y"], "$[0]+$[1] ", "$[0]*$[1] ", "$[2]+$[3] "]
4545
4646// 执行编译后的表达式
4747const value = evaluate (compiled , { x: 2 , y: 3 });
@@ -102,7 +102,7 @@ const array = expr({ x, y })("[x, y].filter(v => v > 0)");
102102// 其中 $N 用于引用之前的变量或表达式
103103
104104const compiled = compile (result , { x , y });
105- // [["x", "y"], "$0+$1 ", "$0*$1 ", "$2+$3 "]
105+ // [["x", "y"], "$[0]+$[1] ", "$[0]*$[1] ", "$[2]+$[3] "]
106106```
107107
108108## API 参考
@@ -169,11 +169,11 @@ const product = expr({ x, y })("x * y");
169169const result = expr ({ sum , product })(" sum + product" );
170170
171171const compiled = compile (result , { x , y });
172- // [["x", "y"], "$0+$1 ", "$0*$1 ", "$2+$3 "]
172+ // [["x", "y"], "$[0]+$[1] ", "$[0]*$[1] ", "$[2]+$[3] "]
173173
174174// 禁用内联优化
175175const noInline = compile (result , { x , y }, { inline: false });
176- // [["x", "y"], "$0+$1 ", "$0*$1 ", "$2+$3 "]
176+ // [["x", "y"], "$[0]+$[1] ", "$[0]*$[1] ", "$[2]+$[3] "]
177177```
178178
179179### ` evaluate<TResult>(data: CompiledData, values: Record<string, unknown>): TResult `
@@ -600,7 +600,7 @@ const compiled = compile(orExpr, { a, b });
600600
601601// 当 a 为 true 时,b 不会被求值
602602// 编译数据包含控制流节点:
603- // [["a", "b"], ["br", "$0 ", 1], "$1 ", ["phi"]]
603+ // [["a", "b"], ["br", "$[0] ", 1], "$[1] ", ["phi"]]
604604
605605// 空值合并
606606const x = variable <number | null >();
@@ -627,8 +627,8 @@ const product = expr({ x, y })("x * y");
627627const result = expr ({ sum , product })(" sum + product" );
628628
629629// 自动内联后,编译结果为:
630- // [["x", "y"], "($0+$1 )+($0*$1 )"]
631- // 而不是 [["x", "y"], "$0+$1 ", "$0*$1 ", "$2+$3 "]
630+ // [["x", "y"], "($[0]+$[1] )+($[0]*$[1] )"]
631+ // 而不是 [["x", "y"], "$[0]+$[1] ", "$[0]*$[1] ", "$[2]+$[3] "]
632632
633633const compiled = compile (result , { x , y });
634634const value = evaluate (compiled , { x: 2 , y: 3 });
@@ -665,7 +665,7 @@ const compiled = compile(result, { x, y });
665665
666666// 序列化
667667const json = JSON .stringify (compiled );
668- // "[["x","y"],"$0+$1 ","$0*$1 ","$2+$3 "]"
668+ // "[["x","y"],"$[0]+$[1] ","$[0]*$[1] ","$[2]+$[3] "]"
669669
670670// 存储或传输...
671671
@@ -688,8 +688,8 @@ const sum = expr({ x, y })("x + y");
688688const compiled = compile (sum , { x , y });
689689
690690// 输出
691- // [["x", "y"], "$0+$1 "]
692- // $0 引用 x,$1 引用 y
691+ // [["x", "y"], "$[0]+$[1] "]
692+ // $[0] 引用 x,$[1] 引用 y
693693```
694694
695695### V2 格式(控制流节点)
@@ -704,8 +704,8 @@ const compiled = compile(result, { a, b });
704704// 输出
705705// [
706706// ["a", "b"],
707- // ["br", "$0 ", 1], // 如果 $0 为 truthy,跳过 1 条指令
708- // "$1 ", // 否则求值 $1
707+ // ["br", "$[0] ", 1], // 如果 $[0] 为 truthy,跳过 1 条指令
708+ // "$[1] ", // 否则求值 $[1]
709709// ["phi"] // 取最近求值结果
710710// ]
711711```
@@ -736,7 +736,7 @@ const xy = variable<number>();
736736const conflict = expr ({ xy , x })(" xy + x" );
737737// 正确处理:编译器能区分 xy 和 x
738738const compiled = compile (conflict , { xy , x });
739- // => [["xy", "x"], "$0+$1 "]
739+ // => [["xy", "x"], "$[0]+$[1] "]
740740```
741741
742742### 运行时错误
0 commit comments