MCPcopy
hub / github.com/expr-lang/expr / TestCompile_optimizes_jumps

Function TestCompile_optimizes_jumps

compiler/compiler_test.go:462–647  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

460}
461
462func TestCompile_optimizes_jumps(t *testing.T) {
463 env := map[string]any{
464 "a": true,
465 "b": true,
466 "c": true,
467 "d": true,
468 "i64": int64(1),
469 }
470 tests := []struct {
471 code string
472 want string
473 }{
474 {
475 `let foo = true; let bar = false; let baz = true; foo || bar || baz`,
476 `0 OpTrue
4771 OpStore <0> foo
4782 OpFalse
4793 OpStore <1> bar
4804 OpTrue
4815 OpStore <2> baz
4826 OpLoadVar <0> foo
4837 OpJumpIfTrue <5> (13)
4848 OpPop
4859 OpLoadVar <1> bar
48610 OpJumpIfTrue <2> (13)
48711 OpPop
48812 OpLoadVar <2> baz
489`,
490 },
491 {
492 `a && b && c`,
493 `0 OpLoadFast <0> a
4941 OpJumpIfFalse <5> (7)
4952 OpPop
4963 OpLoadFast <1> b
4974 OpJumpIfFalse <2> (7)
4985 OpPop
4996 OpLoadFast <2> c
500`,
501 },
502 {
503 `a && b || c && d`,
504 `0 OpLoadFast <0> a
5051 OpJumpIfFalse <2> (4)
5062 OpPop
5073 OpLoadFast <1> b
5084 OpJumpIfTrue <5> (10)
5095 OpPop
5106 OpLoadFast <2> c
5117 OpJumpIfFalse <2> (10)
5128 OpPop
5139 OpLoadFast <3> d
514`,
515 },
516 {
517 `filter([1, 2, 3, 4, 5], # > 3 && # != 4 && # != 5)`,
518 `0 OpPush <0> [1 2 3 4 5]
5191 OpBegin

Callers

nothing calls this directly

Calls 6

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80
DisassembleMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…