From 8d63b98212cbf92b1e67a16c1e4f1909e97d207c Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 25 Sep 2023 16:16:33 -0400 Subject: [PATCH] lang: Add a bunch of new language tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These test both graph shape consistency and single value outputs. Eventually we want to make the graph shape tests more precise, and also verify specific outputs how it used to be. For now, this is okay. Co-authored-by: Samuel Gélineau --- .../TestAstFunc1/changing-func.txtar | 50 ++--- .../TestAstFunc1/classes-polyfuncs.txtar | 33 ++-- .../TestAstFunc1/doubleclass.txtar | 117 +++++------- .../TestAstFunc1/doubleinclude.txtar | 15 +- .../TestAstFunc1/duplicate_resource.txtar | 21 ++- .../TestAstFunc1/efficient-lambda.txtar | 38 +--- .../TestAstFunc1/empty-res-list-1.txtar | 20 +- lang/interpret_test/TestAstFunc1/graph0.txtar | 2 + lang/interpret_test/TestAstFunc1/graph1.txtar | 5 + .../interpret_test/TestAstFunc1/graph10.txtar | 13 ++ .../interpret_test/TestAstFunc1/graph11.txtar | 14 ++ .../interpret_test/TestAstFunc1/graph12.txtar | 19 ++ .../interpret_test/TestAstFunc1/graph13.txtar | 14 ++ .../interpret_test/TestAstFunc1/graph14.txtar | 7 + lang/interpret_test/TestAstFunc1/graph2.txtar | 6 + lang/interpret_test/TestAstFunc1/graph3.txtar | 11 ++ lang/interpret_test/TestAstFunc1/graph4.txtar | 7 + lang/interpret_test/TestAstFunc1/graph5.txtar | 13 ++ lang/interpret_test/TestAstFunc1/graph6.txtar | 18 ++ lang/interpret_test/TestAstFunc1/graph7.txtar | 18 ++ lang/interpret_test/TestAstFunc1/graph8.txtar | 9 + lang/interpret_test/TestAstFunc1/graph9.txtar | 6 + lang/interpret_test/TestAstFunc1/hello0.txtar | 14 +- .../TestAstFunc1/importscope0.txtar | 20 +- .../TestAstFunc1/importscope1.txtar | 2 +- .../TestAstFunc1/importscope2.txtar | 20 +- .../TestAstFunc1/lambda-chained.txtar | 56 ++---- .../TestAstFunc1/module_search1.txtar | 103 ++++------- .../TestAstFunc1/polydoubleinclude.txtar | 57 +++--- .../TestAstFunc1/recursive_module1.txtar | 103 ++++------- .../TestAstFunc1/resdupefields5.txtar | 82 +++++--- .../TestAstFunc1/returned-func.txtar | 16 +- .../TestAstFunc1/returned-lambda.txtar | 16 +- .../TestAstFunc1/shadowing1.txtar | 6 +- .../TestAstFunc1/shadowing2.txtar | 6 +- .../TestAstFunc1/simple-func1.txtar | 10 +- .../TestAstFunc1/simple-func2.txtar | 26 +-- .../TestAstFunc1/simple-lambda1.txtar | 10 +- .../TestAstFunc1/simple-lambda2.txtar | 26 +-- .../TestAstFunc1/slow_unification0.txtar | 175 +++++++++--------- .../TestAstFunc1/static-function0.txtar | 24 +-- .../TestAstFunc1/static-function1.txtar | 68 ++----- .../TestAstFunc2/chained-vars.txtar | 10 + .../TestAstFunc2/class-capture8.txtar | 1 + .../TestAstFunc2/complex-example.txtar | 25 +++ .../TestAstFunc2/definition-site-scope.txtar | 19 ++ .../TestAstFunc2/func-duplicate-arg.txtar | 11 ++ .../TestAstFunc2/func-math1.txtar | 18 +- .../TestAstFunc2/func-math2.txtar | 17 ++ .../TestAstFunc2/func-one-arg.txtar | 13 ++ .../TestAstFunc2/func-unused-arg.txtar | 13 ++ .../identity-function-statement.txtar | 9 + lang/interpret_test/TestAstFunc2/if-0.txtar | 10 + .../TestAstFunc2/if-in-func-0.txtar | 15 ++ .../TestAstFunc2/invalid-function-call.txtar | 2 +- .../TestAstFunc2/lambda-duplicate-arg.txtar | 13 ++ .../TestAstFunc2/lambda-no-args1.txtar | 8 + .../TestAstFunc2/lambda-one-arg.txtar | 13 ++ .../TestAstFunc2/lambda-one-func.txtar | 6 + .../TestAstFunc2/lambda-unused-arg.txtar | 13 ++ .../TestAstFunc2/map-ignore-arg.txtar | 10 + ...erator0.txtar.TODO => map-iterator0.txtar} | 0 ...erator1.txtar.TODO => map-iterator1.txtar} | 0 ...erator2.txtar.TODO => map-iterator2.txtar} | 0 ...erator3.txtar.TODO => map-iterator3.txtar} | 0 ...erator4.txtar.TODO => map-iterator4.txtar} | 0 .../TestAstFunc2/map-numbered.txtar | 13 ++ lang/interpret_test/TestAstFunc2/res0.txtar | 2 + lang/interpret_test/TestAstFunc2/res1.txtar | 6 + lang/interpret_test/TestAstFunc2/res2.txtar | 8 + lang/interpret_test/TestAstFunc2/res3.txtar | 13 ++ lang/interpret_test/TestAstFunc2/res4.txtar | 37 ++++ .../TestAstFunc2/template-1.txtar | 8 + .../TestAstFunc2/very-complex-example.txtar | 78 ++++++++ 74 files changed, 1001 insertions(+), 686 deletions(-) create mode 100644 lang/interpret_test/TestAstFunc1/graph0.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph1.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph10.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph11.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph12.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph13.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph14.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph2.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph3.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph4.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph5.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph6.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph7.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph8.txtar create mode 100644 lang/interpret_test/TestAstFunc1/graph9.txtar create mode 100644 lang/interpret_test/TestAstFunc2/chained-vars.txtar create mode 100644 lang/interpret_test/TestAstFunc2/complex-example.txtar create mode 100644 lang/interpret_test/TestAstFunc2/definition-site-scope.txtar create mode 100644 lang/interpret_test/TestAstFunc2/func-duplicate-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/func-math2.txtar create mode 100644 lang/interpret_test/TestAstFunc2/func-one-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/func-unused-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/identity-function-statement.txtar create mode 100644 lang/interpret_test/TestAstFunc2/if-0.txtar create mode 100644 lang/interpret_test/TestAstFunc2/if-in-func-0.txtar create mode 100644 lang/interpret_test/TestAstFunc2/lambda-duplicate-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/lambda-no-args1.txtar create mode 100644 lang/interpret_test/TestAstFunc2/lambda-one-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/lambda-one-func.txtar create mode 100644 lang/interpret_test/TestAstFunc2/lambda-unused-arg.txtar create mode 100644 lang/interpret_test/TestAstFunc2/map-ignore-arg.txtar rename lang/interpret_test/TestAstFunc2/{map-iterator0.txtar.TODO => map-iterator0.txtar} (100%) rename lang/interpret_test/TestAstFunc2/{map-iterator1.txtar.TODO => map-iterator1.txtar} (100%) rename lang/interpret_test/TestAstFunc2/{map-iterator2.txtar.TODO => map-iterator2.txtar} (100%) rename lang/interpret_test/TestAstFunc2/{map-iterator3.txtar.TODO => map-iterator3.txtar} (100%) rename lang/interpret_test/TestAstFunc2/{map-iterator4.txtar.TODO => map-iterator4.txtar} (100%) create mode 100644 lang/interpret_test/TestAstFunc2/map-numbered.txtar create mode 100644 lang/interpret_test/TestAstFunc2/res0.txtar create mode 100644 lang/interpret_test/TestAstFunc2/res1.txtar create mode 100644 lang/interpret_test/TestAstFunc2/res2.txtar create mode 100644 lang/interpret_test/TestAstFunc2/res3.txtar create mode 100644 lang/interpret_test/TestAstFunc2/res4.txtar create mode 100644 lang/interpret_test/TestAstFunc2/template-1.txtar create mode 100644 lang/interpret_test/TestAstFunc2/very-complex-example.txtar diff --git a/lang/interpret_test/TestAstFunc1/changing-func.txtar b/lang/interpret_test/TestAstFunc1/changing-func.txtar index 0e4360c8..eb4d8238 100644 --- a/lang/interpret_test/TestAstFunc1/changing-func.txtar +++ b/lang/interpret_test/TestAstFunc1/changing-func.txtar @@ -21,41 +21,15 @@ $out2 = $fn2() test $out1 {} test $out2 {} -- OUTPUT -- -Edge: bool(false) -> call:funcgen(bool(false)) # b -Edge: bool(false) -> var(b) # var:b -Edge: bool(true) -> call:funcgen(bool(true)) # b -Edge: bool(true) -> var(b) # var:b -Edge: call:fn1() -> var(out1) # var:out1 -Edge: call:fn2() -> var(out2) # var:out2 -Edge: call:funcgen(bool(false)) -> call:fn2() # call:fn2 -Edge: call:funcgen(bool(true)) -> call:fn1() # call:fn1 -Edge: func() { str("hello") } -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # a -Edge: func() { str("hello") } -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # a -Edge: func() { str("world") } -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # b -Edge: func() { str("world") } -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # b -Edge: func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } -> call:funcgen(bool(false)) # call:funcgen -Edge: func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } -> call:funcgen(bool(true)) # call:funcgen -Edge: if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } -> func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } # body -Edge: if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } -> func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } # body -Edge: str("hello") -> func() { str("hello") } # body -Edge: str("world") -> func() { str("world") } # body -Edge: var(b) -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # c -Edge: var(b) -> if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } # c -Vertex: bool(false) -Vertex: bool(true) -Vertex: call:fn1() -Vertex: call:fn2() -Vertex: call:funcgen(bool(false)) -Vertex: call:funcgen(bool(true)) -Vertex: func() { str("hello") } -Vertex: func() { str("world") } -Vertex: func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } -Vertex: func(b) { if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } } -Vertex: if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } -Vertex: if( var(b) ) { func() { str("hello") } } else { func() { str("world") } } -Vertex: str("hello") -Vertex: str("world") -Vertex: var(b) -Vertex: var(b) -Vertex: var(out1) -Vertex: var(out2) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: call -> call # fn +Edge: call -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar b/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar index 7143bab2..7a571096 100644 --- a/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar +++ b/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar @@ -6,20 +6,19 @@ class c1($b) { test fmt.printf("len is: %d", len($b)) {} # len is 4 } -- OUTPUT -- -Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a -Edge: int(-37) -> list(int(13), int(42), int(0), int(-37)) # 3 -Edge: int(0) -> list(int(13), int(42), int(0), int(-37)) # 2 -Edge: int(13) -> list(int(13), int(42), int(0), int(-37)) # 0 -Edge: int(42) -> list(int(13), int(42), int(0), int(-37)) # 1 -Edge: list(int(13), int(42), int(0), int(-37)) -> var(b) # var:b -Edge: str("len is: %d") -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # format -Edge: var(b) -> call:len(var(b)) # 0 -Vertex: call:fmt.printf(str("len is: %d"), call:len(var(b))) -Vertex: call:len(var(b)) -Vertex: int(-37) -Vertex: int(0) -Vertex: int(13) -Vertex: int(42) -Vertex: list(int(13), int(42), int(0), int(-37)) -Vertex: str("len is: %d") -Vertex: var(b) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: const -> composite # 0 +Edge: const -> composite # 1 +Edge: const -> composite # 2 +Edge: const -> composite # 3 +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: composite +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/doubleclass.txtar b/lang/interpret_test/TestAstFunc1/doubleclass.txtar index 339c27a2..96b7398e 100644 --- a/lang/interpret_test/TestAstFunc1/doubleclass.txtar +++ b/lang/interpret_test/TestAstFunc1/doubleclass.txtar @@ -15,72 +15,51 @@ include foo(1) include foo(2) include foo(3) -- OUTPUT -- -Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside -Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside -Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside -Edge: call:_operator(str("+"), var(some_value1), var(some_value2)) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # a -Edge: call:_operator(str("+"), var(some_value1), var(some_value2)) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # a -Edge: call:_operator(str("+"), var(some_value1), var(some_value2)) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # a -Edge: int(1) -> var(num) # var:num -Edge: int(13) -> var(some_value2) # var:some_value2 -Edge: int(13) -> var(some_value2) # var:some_value2 -Edge: int(13) -> var(some_value2) # var:some_value2 -Edge: int(2) -> var(num) # var:num -Edge: int(3) -> var(num) # var:num -Edge: int(4) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # b -Edge: int(4) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # b -Edge: int(4) -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # b -Edge: int(42) -> var(some_value1) # var:some_value1 -Edge: int(42) -> var(some_value1) # var:some_value1 -Edge: int(42) -> var(some_value1) # var:some_value1 -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # op -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # op -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) # op -Edge: str("+") -> call:_operator(str("+"), var(some_value1), var(some_value2)) # op -Edge: str("+") -> call:_operator(str("+"), var(some_value1), var(some_value2)) # op -Edge: str("+") -> call:_operator(str("+"), var(some_value1), var(some_value2)) # op -Edge: str("test-%d-%d") -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # format -Edge: str("test-%d-%d") -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # format -Edge: str("test-%d-%d") -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # format -Edge: var(inside) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # b -Edge: var(inside) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # b -Edge: var(inside) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # b -Edge: var(num) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # a -Edge: var(num) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # a -Edge: var(num) -> call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) # a -Edge: var(some_value1) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # a -Edge: var(some_value1) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # a -Edge: var(some_value1) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # a -Edge: var(some_value2) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # b -Edge: var(some_value2) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # b -Edge: var(some_value2) -> call:_operator(str("+"), var(some_value1), var(some_value2)) # b -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -Vertex: call:_operator(str("+"), var(some_value1), var(some_value2)) -Vertex: call:_operator(str("+"), var(some_value1), var(some_value2)) -Vertex: call:_operator(str("+"), var(some_value1), var(some_value2)) -Vertex: call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) -Vertex: call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) -Vertex: call:fmt.printf(str("test-%d-%d"), var(num), var(inside)) -Vertex: int(1) -Vertex: int(13) -Vertex: int(2) -Vertex: int(3) -Vertex: int(4) -Vertex: int(42) -Vertex: str("+") -Vertex: str("+") -Vertex: str("test-%d-%d") -Vertex: var(inside) -Vertex: var(inside) -Vertex: var(inside) -Vertex: var(num) -Vertex: var(num) -Vertex: var(num) -Vertex: var(some_value1) -Vertex: var(some_value1) -Vertex: var(some_value1) -Vertex: var(some_value2) -Vertex: var(some_value2) -Vertex: var(some_value2) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/doubleinclude.txtar b/lang/interpret_test/TestAstFunc1/doubleinclude.txtar index 7585f481..0be2e1b4 100644 --- a/lang/interpret_test/TestAstFunc1/doubleinclude.txtar +++ b/lang/interpret_test/TestAstFunc1/doubleinclude.txtar @@ -8,14 +8,7 @@ class c1($a) { } $foo = "hey" -- OUTPUT -- -Edge: str("hey") -> var(foo) # var:foo -Edge: str("hey") -> var(foo) # var:foo -Edge: str("t1") -> var(a) # var:a -Edge: str("t2") -> var(a) # var:a -Vertex: str("hey") -Vertex: str("t1") -Vertex: str("t2") -Vertex: var(a) -Vertex: var(a) -Vertex: var(foo) -Vertex: var(foo) +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar b/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar index ec9988dc..5a6fc402 100644 --- a/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar +++ b/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar @@ -17,13 +17,14 @@ pkg "cowsay" { state => "newest", } -- OUTPUT -- -Edge: str("hello world") -> call:fmt.printf(str("hello world")) # format -Vertex: call:fmt.printf(str("hello world")) -Vertex: str("/tmp/foo") -Vertex: str("/tmp/foo") -Vertex: str("cowsay") -Vertex: str("cowsay") -Vertex: str("hello world") -Vertex: str("hello world") -Vertex: str("installed") -Vertex: str("newest") +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar b/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar index 63ced61a..e6249fc9 100644 --- a/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar +++ b/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar @@ -10,33 +10,11 @@ $out2 = $prefixer("b") test $out1 {} # helloa test $out2 {} # hellob -- OUTPUT -- -Edge: call:_operator(str("+"), str("hello"), var(x)) -> func(x) { call:_operator(str("+"), str("hello"), var(x)) } # body -Edge: call:_operator(str("+"), str("hello"), var(x)) -> func(x) { call:_operator(str("+"), str("hello"), var(x)) } # body -Edge: call:prefixer(str("a")) -> var(out1) # var:out1 -Edge: call:prefixer(str("b")) -> var(out2) # var:out2 -Edge: func(x) { call:_operator(str("+"), str("hello"), var(x)) } -> call:prefixer(str("a")) # call:prefixer -Edge: func(x) { call:_operator(str("+"), str("hello"), var(x)) } -> call:prefixer(str("b")) # call:prefixer -Edge: str("+") -> call:_operator(str("+"), str("hello"), var(x)) # op -Edge: str("+") -> call:_operator(str("+"), str("hello"), var(x)) # op -Edge: str("a") -> call:prefixer(str("a")) # x -Edge: str("a") -> var(x) # var:x -Edge: str("b") -> call:prefixer(str("b")) # x -Edge: str("b") -> var(x) # var:x -Edge: str("hello") -> call:_operator(str("+"), str("hello"), var(x)) # a -Edge: str("hello") -> call:_operator(str("+"), str("hello"), var(x)) # a -Edge: var(x) -> call:_operator(str("+"), str("hello"), var(x)) # b -Edge: var(x) -> call:_operator(str("+"), str("hello"), var(x)) # b -Vertex: call:_operator(str("+"), str("hello"), var(x)) -Vertex: call:_operator(str("+"), str("hello"), var(x)) -Vertex: call:prefixer(str("a")) -Vertex: call:prefixer(str("b")) -Vertex: func(x) { call:_operator(str("+"), str("hello"), var(x)) } -Vertex: func(x) { call:_operator(str("+"), str("hello"), var(x)) } -Vertex: str("+") -Vertex: str("a") -Vertex: str("b") -Vertex: str("hello") -Vertex: var(out1) -Vertex: var(out2) -Vertex: var(x) -Vertex: var(x) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar b/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar index b8ddff70..eb2cbf44 100644 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar +++ b/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar @@ -9,14 +9,12 @@ test $names {} # multiples resources, defined by list test ["hello", "world",] {} -- OUTPUT -- -Edge: list(str("hey")) -> var(names) # var:names -Edge: str("hello") -> list(str("hello"), str("world")) # 0 -Edge: str("hey") -> list(str("hey")) # 0 -Edge: str("world") -> list(str("hello"), str("world")) # 1 -Vertex: list(str("hello"), str("world")) -Vertex: list(str("hey")) -Vertex: str("hello") -Vertex: str("hey") -Vertex: str("name") -Vertex: str("world") -Vertex: var(names) +Edge: const -> composite # 0 +Edge: const -> composite # 0 +Edge: const -> composite # 1 +Vertex: composite +Vertex: composite +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph0.txtar b/lang/interpret_test/TestAstFunc1/graph0.txtar new file mode 100644 index 00000000..54ed6098 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph0.txtar @@ -0,0 +1,2 @@ +-- main.mcl -- +-- OUTPUT -- diff --git a/lang/interpret_test/TestAstFunc1/graph1.txtar b/lang/interpret_test/TestAstFunc1/graph1.txtar new file mode 100644 index 00000000..01bfd8e5 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph1.txtar @@ -0,0 +1,5 @@ +-- main.mcl -- +# TODO: this should fail with an unused variable error! +$x = 42 +$y = $x +-- OUTPUT -- diff --git a/lang/interpret_test/TestAstFunc1/graph10.txtar b/lang/interpret_test/TestAstFunc1/graph10.txtar new file mode 100644 index 00000000..029cbbc1 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph10.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +# this should be okay, because var is shadowed +$x = "hello" +if true { + $x = "world" # shadowed +} +test "t" { + stringptr => $x, +} +-- OUTPUT -- +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph11.txtar b/lang/interpret_test/TestAstFunc1/graph11.txtar new file mode 100644 index 00000000..8af1f616 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph11.txtar @@ -0,0 +1,14 @@ +-- main.mcl -- +# variable shadowing inner +# this should be okay, because var is shadowed +$x = "hello" +if true { + $x = "world" # shadowed + test "t" { + stringptr => $x, + } +} +-- OUTPUT -- +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph12.txtar b/lang/interpret_test/TestAstFunc1/graph12.txtar new file mode 100644 index 00000000..4d908687 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph12.txtar @@ -0,0 +1,19 @@ +-- main.mcl -- +# variable shadowing both +# this should be okay, because var is shadowed +$x = "hello" +if true { + $x = "world" # shadowed + test "t2" { + stringptr => $x, + } +} +test "t1" { + stringptr => $x, +} +-- OUTPUT -- +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph13.txtar b/lang/interpret_test/TestAstFunc1/graph13.txtar new file mode 100644 index 00000000..6bb23cad --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph13.txtar @@ -0,0 +1,14 @@ +-- main.mcl -- +# duplicate resource +# these two are allowed because they are compatible +pkg "cowsay" { + state => "installed", +} +pkg "cowsay" { + state => "newest", +} +-- OUTPUT -- +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph14.txtar b/lang/interpret_test/TestAstFunc1/graph14.txtar new file mode 100644 index 00000000..270188fd --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph14.txtar @@ -0,0 +1,7 @@ +-- main.mcl -- +# variable re-declaration and type change error +# this should fail b/c of variable re-declaration +$x = "wow" +$x = 99 # woops, but also a change of type :P +-- OUTPUT -- +# err: errSetScope: var `x` already exists in this scope diff --git a/lang/interpret_test/TestAstFunc1/graph2.txtar b/lang/interpret_test/TestAstFunc1/graph2.txtar new file mode 100644 index 00000000..b5b83af2 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph2.txtar @@ -0,0 +1,6 @@ +-- main.mcl -- +# self-referential vars +$x = $y +$y = $x +-- OUTPUT -- +# err: errSetScope: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc1/graph3.txtar b/lang/interpret_test/TestAstFunc1/graph3.txtar new file mode 100644 index 00000000..7f7cd0a5 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph3.txtar @@ -0,0 +1,11 @@ +-- main.mcl -- +# chained vars +test "t" { + int64ptr => $c, +} +$c = $b +$b = $a +$a = 42 +-- OUTPUT -- +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph4.txtar b/lang/interpret_test/TestAstFunc1/graph4.txtar new file mode 100644 index 00000000..532467e7 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph4.txtar @@ -0,0 +1,7 @@ +-- main.mcl -- +# simple bool +if $b { +} +$b = true +-- OUTPUT -- +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph5.txtar b/lang/interpret_test/TestAstFunc1/graph5.txtar new file mode 100644 index 00000000..831e09bd --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph5.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +# simple operator +test "t" { + int64ptr => 42 + 13, +} +-- OUTPUT -- +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph6.txtar b/lang/interpret_test/TestAstFunc1/graph6.txtar new file mode 100644 index 00000000..2fcc17ba --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph6.txtar @@ -0,0 +1,18 @@ +-- main.mcl -- +# simple operators +test "t" { + int64ptr => 42 + 13 - 99, +} +-- OUTPUT -- +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph7.txtar b/lang/interpret_test/TestAstFunc1/graph7.txtar new file mode 100644 index 00000000..f98331f5 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph7.txtar @@ -0,0 +1,18 @@ +-- main.mcl -- +# nested resource and scoped var +if true { + test "t" { + int64ptr => $x, + } + $x = 42 + $i +} +$i = 13 +-- OUTPUT -- +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/graph8.txtar b/lang/interpret_test/TestAstFunc1/graph8.txtar new file mode 100644 index 00000000..e0766e85 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph8.txtar @@ -0,0 +1,9 @@ +-- main.mcl -- +# should be out of scope, and a compile error! +if $b { +} +if true { + $b = true +} +-- OUTPUT -- +# err: errSetScope: variable b not in scope diff --git a/lang/interpret_test/TestAstFunc1/graph9.txtar b/lang/interpret_test/TestAstFunc1/graph9.txtar new file mode 100644 index 00000000..3fb117aa --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/graph9.txtar @@ -0,0 +1,6 @@ +-- main.mcl -- +# this should fail b/c of variable re-declaration +$x = "hello" +$x = "world" # woops +-- OUTPUT -- +# err: errSetScope: var `x` already exists in this scope diff --git a/lang/interpret_test/TestAstFunc1/hello0.txtar b/lang/interpret_test/TestAstFunc1/hello0.txtar index cf353196..0129a4fc 100644 --- a/lang/interpret_test/TestAstFunc1/hello0.txtar +++ b/lang/interpret_test/TestAstFunc1/hello0.txtar @@ -7,11 +7,9 @@ test "greeting" { anotherstr => fmt.printf("hello: %s", $s), } -- OUTPUT -- -Edge: str("hello: %s") -> call:fmt.printf(str("hello: %s"), var(s)) # format -Edge: str("world") -> var(s) # var:s -Edge: var(s) -> call:fmt.printf(str("hello: %s"), var(s)) # a -Vertex: call:fmt.printf(str("hello: %s"), var(s)) -Vertex: str("greeting") -Vertex: str("hello: %s") -Vertex: str("world") -Vertex: var(s) +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/importscope0.txtar b/lang/interpret_test/TestAstFunc1/importscope0.txtar index f3edfbc3..c057e5fc 100644 --- a/lang/interpret_test/TestAstFunc1/importscope0.txtar +++ b/lang/interpret_test/TestAstFunc1/importscope0.txtar @@ -16,13 +16,13 @@ class xclass { } } -- OUTPUT -- -Edge: call:os.is_debian() -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # c -Edge: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -> var(aaa) # var:aaa -Edge: str("bbb") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # a -Edge: str("ccc") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # b -Vertex: call:os.is_debian() -Vertex: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -Vertex: str("bbb") -Vertex: str("ccc") -Vertex: str("hello") -Vertex: var(aaa) +Edge: FuncValue -> call # fn +Edge: call -> if # c +Edge: const -> if # a +Edge: const -> if # b +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: if diff --git a/lang/interpret_test/TestAstFunc1/importscope1.txtar b/lang/interpret_test/TestAstFunc1/importscope1.txtar index 99fbd285..c57de890 100644 --- a/lang/interpret_test/TestAstFunc1/importscope1.txtar +++ b/lang/interpret_test/TestAstFunc1/importscope1.txtar @@ -16,4 +16,4 @@ class xclass { } } -- OUTPUT -- -# err: errSetScope: import scope `second.mcl` failed: local import of `second.mcl` failed: could not set scope from import: func `os.is_debian` does not exist in this scope +# err: errSetScope: func `os.is_debian` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc1/importscope2.txtar b/lang/interpret_test/TestAstFunc1/importscope2.txtar index 9985611e..bf9b8bdf 100644 --- a/lang/interpret_test/TestAstFunc1/importscope2.txtar +++ b/lang/interpret_test/TestAstFunc1/importscope2.txtar @@ -15,13 +15,13 @@ class xclass { } } -- OUTPUT -- -Edge: call:os.is_debian() -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # c -Edge: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -> var(aaa) # var:aaa -Edge: str("bbb") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # a -Edge: str("ccc") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # b -Vertex: call:os.is_debian() -Vertex: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -Vertex: str("bbb") -Vertex: str("ccc") -Vertex: str("hello") -Vertex: var(aaa) +Edge: FuncValue -> call # fn +Edge: call -> if # c +Edge: const -> if # a +Edge: const -> if # b +Vertex: FuncValue +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: if diff --git a/lang/interpret_test/TestAstFunc1/lambda-chained.txtar b/lang/interpret_test/TestAstFunc1/lambda-chained.txtar index df91e05d..e4b299d2 100644 --- a/lang/interpret_test/TestAstFunc1/lambda-chained.txtar +++ b/lang/interpret_test/TestAstFunc1/lambda-chained.txtar @@ -12,48 +12,14 @@ $out2 = $prefixer($out1) test $out1 {} test $out2 {} -- OUTPUT -- -Edge: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -> func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } # body -Edge: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -> func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } # body -Edge: call:_operator(str("+"), var(prefix), str(":")) -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # a -Edge: call:_operator(str("+"), var(prefix), str(":")) -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # a -Edge: call:prefixer(str("world")) -> var(out1) # var:out1 -Edge: call:prefixer(str("world")) -> var(out1) # var:out1 -Edge: call:prefixer(var(out1)) -> var(out2) # var:out2 -Edge: func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } -> call:prefixer(str("world")) # call:prefixer -Edge: func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } -> call:prefixer(var(out1)) # call:prefixer -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # op -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # op -Edge: str("+") -> call:_operator(str("+"), var(prefix), str(":")) # op -Edge: str("+") -> call:_operator(str("+"), var(prefix), str(":")) # op -Edge: str(":") -> call:_operator(str("+"), var(prefix), str(":")) # b -Edge: str(":") -> call:_operator(str("+"), var(prefix), str(":")) # b -Edge: str("hello") -> var(prefix) # var:prefix -Edge: str("hello") -> var(prefix) # var:prefix -Edge: str("world") -> call:prefixer(str("world")) # x -Edge: str("world") -> var(x) # var:x -Edge: var(out1) -> call:prefixer(var(out1)) # x -Edge: var(out1) -> var(x) # var:x -Edge: var(prefix) -> call:_operator(str("+"), var(prefix), str(":")) # a -Edge: var(prefix) -> call:_operator(str("+"), var(prefix), str(":")) # a -Edge: var(x) -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # b -Edge: var(x) -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # b -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -Vertex: call:_operator(str("+"), var(prefix), str(":")) -Vertex: call:_operator(str("+"), var(prefix), str(":")) -Vertex: call:prefixer(str("world")) -Vertex: call:prefixer(var(out1)) -Vertex: func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } -Vertex: func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } -Vertex: str("+") -Vertex: str("+") -Vertex: str(":") -Vertex: str("hello") -Vertex: str("world") -Vertex: var(out1) -Vertex: var(out1) -Vertex: var(out2) -Vertex: var(prefix) -Vertex: var(prefix) -Vertex: var(x) -Vertex: var(x) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/module_search1.txtar b/lang/interpret_test/TestAstFunc1/module_search1.txtar index 8edd9b5a..fa0f51e2 100644 --- a/lang/interpret_test/TestAstFunc1/module_search1.txtar +++ b/lang/interpret_test/TestAstFunc1/module_search1.txtar @@ -62,67 +62,42 @@ $ex1 = $example1.name $name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 -- OUTPUT -- -Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # var:h2g2.answer -Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name -Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name -Edge: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -> var(mod1.name) # var:mod1.name -Edge: int(3) -> var(third.three) # var:third.three -Edge: int(42) -> call:_operator(str("+"), int(42), var(third.three)) # a -Edge: str("+") -> call:_operator(str("+"), int(42), var(third.three)) # op -Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op -Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op -Edge: str("+") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # op -Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a -Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a -Edge: str("i imported local: %s") -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # format -Edge: str("i imported remote: %s and %s") -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # format -Edge: str("the answer is: %d") -> call:fmt.printf(str("the answer is: %d"), var(answer)) # format -Edge: str("this is module mod1 which contains: ") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # a -Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name -Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name -Edge: str("this is the nested local module mod1") -> var(mod1.name) # var:mod1.name -Edge: var(answer) -> call:fmt.printf(str("the answer is: %d"), var(answer)) # a -Edge: var(example1.name) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # a -Edge: var(example1.name) -> var(example2.ex1) # var:example2.ex1 -Edge: var(example2.ex1) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # b -Edge: var(h2g2.answer) -> var(answer) # var:answer -Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # a -Edge: var(third.three) -> call:_operator(str("+"), int(42), var(third.three)) # b -Vertex: call:_operator(str("+"), int(42), var(third.three)) -Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -Vertex: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -Vertex: call:fmt.printf(str("i imported local: %s"), var(mod1.name)) -Vertex: call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) -Vertex: call:fmt.printf(str("the answer is: %d"), var(answer)) -Vertex: int(3) -Vertex: int(42) -Vertex: str("+") -Vertex: str("+") -Vertex: str("+") -Vertex: str("+") -Vertex: str("hello") -Vertex: str("hello2") -Vertex: str("hello3") -Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -Vertex: str("i imported local: %s") -Vertex: str("i imported remote: %s and %s") -Vertex: str("the answer is: %d") -Vertex: str("this is module mod1 which contains: ") -Vertex: str("this is the nested git module mod1") -Vertex: str("this is the nested git module mod1") -Vertex: str("this is the nested local module mod1") -Vertex: var(answer) -Vertex: var(example1.name) -Vertex: var(example1.name) -Vertex: var(example2.ex1) -Vertex: var(h2g2.answer) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(third.three) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar b/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar index 364141b6..2eaa7ee4 100644 --- a/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar +++ b/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar @@ -10,34 +10,29 @@ class c1($a, $b) { } } -- OUTPUT -- -Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a -Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a -Edge: int(-37) -> list(int(13), int(42), int(0), int(-37)) # 3 -Edge: int(0) -> list(int(13), int(42), int(0), int(-37)) # 2 -Edge: int(13) -> list(int(13), int(42), int(0), int(-37)) # 0 -Edge: int(42) -> list(int(13), int(42), int(0), int(-37)) # 1 -Edge: list(int(13), int(42), int(0), int(-37)) -> var(b) # var:b -Edge: str("hello") -> var(b) # var:b -Edge: str("len is: %d") -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # format -Edge: str("len is: %d") -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # format -Edge: str("t1") -> var(a) # var:a -Edge: str("t2") -> var(a) # var:a -Edge: var(b) -> call:len(var(b)) # 0 -Edge: var(b) -> call:len(var(b)) # 0 -Vertex: call:fmt.printf(str("len is: %d"), call:len(var(b))) -Vertex: call:fmt.printf(str("len is: %d"), call:len(var(b))) -Vertex: call:len(var(b)) -Vertex: call:len(var(b)) -Vertex: int(-37) -Vertex: int(0) -Vertex: int(13) -Vertex: int(42) -Vertex: list(int(13), int(42), int(0), int(-37)) -Vertex: str("hello") -Vertex: str("len is: %d") -Vertex: str("t1") -Vertex: str("t2") -Vertex: var(a) -Vertex: var(a) -Vertex: var(b) -Vertex: var(b) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: const -> composite # 0 +Edge: const -> composite # 1 +Edge: const -> composite # 2 +Edge: const -> composite # 3 +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: composite +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1.txtar b/lang/interpret_test/TestAstFunc1/recursive_module1.txtar index 4f67f9d9..b1fcecb2 100644 --- a/lang/interpret_test/TestAstFunc1/recursive_module1.txtar +++ b/lang/interpret_test/TestAstFunc1/recursive_module1.txtar @@ -60,67 +60,42 @@ $ex1 = $example1.name $name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 -- OUTPUT -- -Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # var:h2g2.answer -Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name -Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name -Edge: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -> var(mod1.name) # var:mod1.name -Edge: int(3) -> var(third.three) # var:third.three -Edge: int(42) -> call:_operator(str("+"), int(42), var(third.three)) # a -Edge: str("+") -> call:_operator(str("+"), int(42), var(third.three)) # op -Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op -Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # op -Edge: str("+") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # op -Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a -Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a -Edge: str("i imported local: %s") -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # format -Edge: str("i imported remote: %s and %s") -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # format -Edge: str("the answer is: %d") -> call:fmt.printf(str("the answer is: %d"), var(answer)) # format -Edge: str("this is module mod1 which contains: ") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # a -Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name -Edge: str("this is the nested git module mod1") -> var(mod1.name) # var:mod1.name -Edge: str("this is the nested local module mod1") -> var(mod1.name) # var:mod1.name -Edge: var(answer) -> call:fmt.printf(str("the answer is: %d"), var(answer)) # a -Edge: var(example1.name) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # a -Edge: var(example1.name) -> var(example2.ex1) # var:example2.ex1 -Edge: var(example2.ex1) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # b -Edge: var(h2g2.answer) -> var(answer) # var:answer -Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # b -Edge: var(mod1.name) -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # a -Edge: var(third.three) -> call:_operator(str("+"), int(42), var(third.three)) # b -Vertex: call:_operator(str("+"), int(42), var(third.three)) -Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -Vertex: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -Vertex: call:fmt.printf(str("i imported local: %s"), var(mod1.name)) -Vertex: call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) -Vertex: call:fmt.printf(str("the answer is: %d"), var(answer)) -Vertex: int(3) -Vertex: int(42) -Vertex: str("+") -Vertex: str("+") -Vertex: str("+") -Vertex: str("+") -Vertex: str("hello") -Vertex: str("hello2") -Vertex: str("hello3") -Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -Vertex: str("i imported local: %s") -Vertex: str("i imported remote: %s and %s") -Vertex: str("the answer is: %d") -Vertex: str("this is module mod1 which contains: ") -Vertex: str("this is the nested git module mod1") -Vertex: str("this is the nested git module mod1") -Vertex: str("this is the nested local module mod1") -Vertex: var(answer) -Vertex: var(example1.name) -Vertex: var(example1.name) -Vertex: var(example2.ex1) -Vertex: var(h2g2.answer) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(mod1.name) -Vertex: var(third.three) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/resdupefields5.txtar b/lang/interpret_test/TestAstFunc1/resdupefields5.txtar index 16d65106..acbbbbc9 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields5.txtar +++ b/lang/interpret_test/TestAstFunc1/resdupefields5.txtar @@ -1,24 +1,62 @@ -- main.mcl -- -# XXX: should error at graph unification, but we have a type unification bug -#test "test" { -# anotherstr => "test", -# -# Meta => true ?: struct{ -# noop => false, -# retry => -1, -# delay => 0, -# poll => 5, -# limit => 4.2, -# burst => 3, -# sema => ["foo:1", "bar:3",], -# rewatch => false, -# realize => true, -# reverse => true, -# autoedge => true, -# autogroup => true, -# }, -# Meta => true ?: struct{ -# noop => false, -# }, -#} +test "test" { + anotherstr => "test", + + Meta => true ?: struct{ + noop => false, + retry => -1, + retryreset => false, + delay => 0, + poll => 5, + limit => 4.2, + burst => 3, + reset => false, + sema => ["foo:1", "bar:3",], + rewatch => false, + realize => true, + reverse => true, + autoedge => true, + autogroup => true, + }, + # XXX: should error at graph unification, but we have a type unification bug + #Meta => true ?: struct{ + # noop => false, + #}, +} -- OUTPUT -- +Edge: composite -> composite # sema +Edge: const -> composite # 0 +Edge: const -> composite # 1 +Edge: const -> composite # autoedge +Edge: const -> composite # autogroup +Edge: const -> composite # burst +Edge: const -> composite # delay +Edge: const -> composite # limit +Edge: const -> composite # noop +Edge: const -> composite # poll +Edge: const -> composite # realize +Edge: const -> composite # reset +Edge: const -> composite # retry +Edge: const -> composite # retryreset +Edge: const -> composite # reverse +Edge: const -> composite # rewatch +Vertex: composite +Vertex: composite +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/returned-func.txtar b/lang/interpret_test/TestAstFunc1/returned-func.txtar index 305c45dc..146786da 100644 --- a/lang/interpret_test/TestAstFunc1/returned-func.txtar +++ b/lang/interpret_test/TestAstFunc1/returned-func.txtar @@ -11,14 +11,8 @@ $out = $fn() test $out {} -- OUTPUT -- -Edge: call:fn() -> var(out) # var:out -Edge: call:funcgen() -> call:fn() # call:fn -Edge: func() { func() { str("hello") } } -> call:funcgen() # call:funcgen -Edge: func() { str("hello") } -> func() { func() { str("hello") } } # body -Edge: str("hello") -> func() { str("hello") } # body -Vertex: call:fn() -Vertex: call:funcgen() -Vertex: func() { func() { str("hello") } } -Vertex: func() { str("hello") } -Vertex: str("hello") -Vertex: var(out) +Edge: FuncValue -> call # fn +Edge: call -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: call diff --git a/lang/interpret_test/TestAstFunc1/returned-lambda.txtar b/lang/interpret_test/TestAstFunc1/returned-lambda.txtar index a5654107..93b17fb6 100644 --- a/lang/interpret_test/TestAstFunc1/returned-lambda.txtar +++ b/lang/interpret_test/TestAstFunc1/returned-lambda.txtar @@ -10,14 +10,8 @@ $out = $fn() test $out {} -- OUTPUT -- -Edge: call:fn() -> var(out) # var:out -Edge: call:funcgen() -> call:fn() # call:fn -Edge: func() { func() { str("hello") } } -> call:funcgen() # call:funcgen -Edge: func() { str("hello") } -> func() { func() { str("hello") } } # body -Edge: str("hello") -> func() { str("hello") } # body -Vertex: call:fn() -Vertex: call:funcgen() -Vertex: func() { func() { str("hello") } } -Vertex: func() { str("hello") } -Vertex: str("hello") -Vertex: var(out) +Edge: FuncValue -> call # fn +Edge: call -> call # fn +Vertex: FuncValue +Vertex: call +Vertex: call diff --git a/lang/interpret_test/TestAstFunc1/shadowing1.txtar b/lang/interpret_test/TestAstFunc1/shadowing1.txtar index 7ee95026..22fe868b 100644 --- a/lang/interpret_test/TestAstFunc1/shadowing1.txtar +++ b/lang/interpret_test/TestAstFunc1/shadowing1.txtar @@ -6,7 +6,5 @@ if true { } test $x {} -- OUTPUT -- -Edge: str("hello") -> var(x) # var:x -Vertex: bool(true) -Vertex: str("hello") -Vertex: var(x) +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/shadowing2.txtar b/lang/interpret_test/TestAstFunc1/shadowing2.txtar index 34f5dd9c..3b297a6f 100644 --- a/lang/interpret_test/TestAstFunc1/shadowing2.txtar +++ b/lang/interpret_test/TestAstFunc1/shadowing2.txtar @@ -6,7 +6,5 @@ if true { test $x {} } -- OUTPUT -- -Edge: str("world") -> var(x) # var:x -Vertex: bool(true) -Vertex: str("world") -Vertex: var(x) +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/simple-func1.txtar b/lang/interpret_test/TestAstFunc1/simple-func1.txtar index 5cc59bc7..72a0cee0 100644 --- a/lang/interpret_test/TestAstFunc1/simple-func1.txtar +++ b/lang/interpret_test/TestAstFunc1/simple-func1.txtar @@ -7,10 +7,6 @@ $out1 = answer() test $out1 {} -- OUTPUT -- -Edge: call:answer() -> var(out1) # var:out1 -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body -Vertex: call:answer() -Vertex: func() { str("the answer is 42") } -Vertex: str("the answer is 42") -Vertex: var(out1) +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call diff --git a/lang/interpret_test/TestAstFunc1/simple-func2.txtar b/lang/interpret_test/TestAstFunc1/simple-func2.txtar index d0c1976c..e697c857 100644 --- a/lang/interpret_test/TestAstFunc1/simple-func2.txtar +++ b/lang/interpret_test/TestAstFunc1/simple-func2.txtar @@ -8,19 +8,13 @@ $out2 = answer() test $out1 + $out2 {} -- OUTPUT -- -Edge: call:answer() -> var(out1) # var:out1 -Edge: call:answer() -> var(out2) # var:out2 -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: str("+") -> call:_operator(str("+"), var(out1), var(out2)) # op -Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body -Edge: var(out1) -> call:_operator(str("+"), var(out1), var(out2)) # a -Edge: var(out2) -> call:_operator(str("+"), var(out1), var(out2)) # b -Vertex: call:_operator(str("+"), var(out1), var(out2)) -Vertex: call:answer() -Vertex: call:answer() -Vertex: func() { str("the answer is 42") } -Vertex: str("+") -Vertex: str("the answer is 42") -Vertex: var(out1) -Vertex: var(out2) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar b/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar index 43176316..965be038 100644 --- a/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar +++ b/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar @@ -10,10 +10,6 @@ $out = $answer() test $out {} -- OUTPUT -- -Edge: call:answer() -> var(out) # var:out -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body -Vertex: call:answer() -Vertex: func() { str("the answer is 42") } -Vertex: str("the answer is 42") -Vertex: var(out) +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: call diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar b/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar index b879b30f..c5c3b052 100644 --- a/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar +++ b/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar @@ -11,19 +11,13 @@ $out2 = $answer() test $out1 + $out2 {} -- OUTPUT -- -Edge: call:answer() -> var(out1) # var:out1 -Edge: call:answer() -> var(out2) # var:out2 -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: func() { str("the answer is 42") } -> call:answer() # call:answer -Edge: str("+") -> call:_operator(str("+"), var(out1), var(out2)) # op -Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body -Edge: var(out1) -> call:_operator(str("+"), var(out1), var(out2)) # a -Edge: var(out2) -> call:_operator(str("+"), var(out1), var(out2)) # b -Vertex: call:_operator(str("+"), var(out1), var(out2)) -Vertex: call:answer() -Vertex: call:answer() -Vertex: func() { str("the answer is 42") } -Vertex: str("+") -Vertex: str("the answer is 42") -Vertex: var(out1) -Vertex: var(out2) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/slow_unification0.txtar b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar index e5203254..adc5a4db 100644 --- a/lang/interpret_test/TestAstFunc1/slow_unification0.txtar +++ b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar @@ -52,91 +52,90 @@ if $state == "three" { Exec["timer"] -> Kv["${ns}"] } -- OUTPUT -- -Edge: call:_operator(str("=="), var(state), str("default")) -> call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) # b -Edge: call:_operator(str("=="), var(state), str("one")) -> call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) # a -Edge: call:maplookup(var(exchanged), var(hostname), str("default")) -> var(state) # var:state -Edge: call:maplookup(var(exchanged), var(hostname), str("default")) -> var(state) # var:state -Edge: call:maplookup(var(exchanged), var(hostname), str("default")) -> var(state) # var:state -Edge: call:maplookup(var(exchanged), var(hostname), str("default")) -> var(state) # var:state -Edge: call:world.kvlookup(var(ns)) -> var(exchanged) # var:exchanged -Edge: str("") -> var(hostname) # var:hostname -Edge: str("==") -> call:_operator(str("=="), var(state), str("default")) # op -Edge: str("==") -> call:_operator(str("=="), var(state), str("one")) # op -Edge: str("==") -> call:_operator(str("=="), var(state), str("three")) # op -Edge: str("==") -> call:_operator(str("=="), var(state), str("two")) # op -Edge: str("default") -> call:_operator(str("=="), var(state), str("default")) # b -Edge: str("default") -> call:maplookup(var(exchanged), var(hostname), str("default")) # default -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("estate") -> var(ns) # var:ns -Edge: str("one") -> call:_operator(str("=="), var(state), str("one")) # b -Edge: str("three") -> call:_operator(str("=="), var(state), str("three")) # b -Edge: str("two") -> call:_operator(str("=="), var(state), str("two")) # b -Edge: str("||") -> call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) # op -Edge: var(exchanged) -> call:maplookup(var(exchanged), var(hostname), str("default")) # map -Edge: var(hostname) -> call:maplookup(var(exchanged), var(hostname), str("default")) # key -Edge: var(ns) -> call:world.kvlookup(var(ns)) # namespace -Edge: var(state) -> call:_operator(str("=="), var(state), str("default")) # a -Edge: var(state) -> call:_operator(str("=="), var(state), str("one")) # a -Edge: var(state) -> call:_operator(str("=="), var(state), str("three")) # a -Edge: var(state) -> call:_operator(str("=="), var(state), str("two")) # a -Vertex: call:_operator(str("=="), var(state), str("default")) -Vertex: call:_operator(str("=="), var(state), str("one")) -Vertex: call:_operator(str("=="), var(state), str("three")) -Vertex: call:_operator(str("=="), var(state), str("two")) -Vertex: call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) -Vertex: call:maplookup(var(exchanged), var(hostname), str("default")) -Vertex: call:world.kvlookup(var(ns)) -Vertex: str("") -Vertex: str("/tmp/mgmt/state") -Vertex: str("/tmp/mgmt/state") -Vertex: str("/tmp/mgmt/state") -Vertex: str("/usr/bin/sleep 1s") -Vertex: str("/usr/bin/sleep 1s") -Vertex: str("/usr/bin/sleep 1s") -Vertex: str("==") -Vertex: str("==") -Vertex: str("==") -Vertex: str("==") -Vertex: str("default") -Vertex: str("default") -Vertex: str("estate") -Vertex: str("one") -Vertex: str("one") -Vertex: str("state: one\n") -Vertex: str("state: three\n") -Vertex: str("state: two\n") -Vertex: str("three") -Vertex: str("three") -Vertex: str("timer") -Vertex: str("timer") -Vertex: str("timer") -Vertex: str("timer") -Vertex: str("timer") -Vertex: str("timer") -Vertex: str("two") -Vertex: str("two") -Vertex: str("||") -Vertex: var(exchanged) -Vertex: var(hostname) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(ns) -Vertex: var(state) -Vertex: var(state) -Vertex: var(state) -Vertex: var(state) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/static-function0.txtar b/lang/interpret_test/TestAstFunc1/static-function0.txtar index 4adeaeea..9e824c8e 100644 --- a/lang/interpret_test/TestAstFunc1/static-function0.txtar +++ b/lang/interpret_test/TestAstFunc1/static-function0.txtar @@ -16,15 +16,15 @@ test "greeting3" { anotherstr => $fn(), } -- OUTPUT -- -Edge: func() { str("hello world") } -> call:fn() # call:fn -Edge: func() { str("hello world") } -> call:fn() # call:fn -Edge: func() { str("hello world") } -> call:fn() # call:fn -Edge: str("hello world") -> func() { str("hello world") } # body -Vertex: call:fn() -Vertex: call:fn() -Vertex: call:fn() -Vertex: func() { str("hello world") } -Vertex: str("greeting1") -Vertex: str("greeting2") -Vertex: str("greeting3") -Vertex: str("hello world") +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc1/static-function1.txtar b/lang/interpret_test/TestAstFunc1/static-function1.txtar index a2b2dc4d..da23a96a 100644 --- a/lang/interpret_test/TestAstFunc1/static-function1.txtar +++ b/lang/interpret_test/TestAstFunc1/static-function1.txtar @@ -18,59 +18,15 @@ test "greeting3" { anotherstr => $fn(), } -- OUTPUT -- -Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body -Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body -Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body -Edge: call:_operator(str("+"), var(s1), str(" ")) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # a -Edge: call:_operator(str("+"), var(s1), str(" ")) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # a -Edge: call:_operator(str("+"), var(s1), str(" ")) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # a -Edge: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -> call:fn() # call:fn -Edge: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -> call:fn() # call:fn -Edge: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -> call:fn() # call:fn -Edge: str(" ") -> call:_operator(str("+"), var(s1), str(" ")) # b -Edge: str(" ") -> call:_operator(str("+"), var(s1), str(" ")) # b -Edge: str(" ") -> call:_operator(str("+"), var(s1), str(" ")) # b -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # op -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # op -Edge: str("+") -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # op -Edge: str("+") -> call:_operator(str("+"), var(s1), str(" ")) # op -Edge: str("+") -> call:_operator(str("+"), var(s1), str(" ")) # op -Edge: str("+") -> call:_operator(str("+"), var(s1), str(" ")) # op -Edge: str("hello") -> var(s1) # var:s1 -Edge: str("hello") -> var(s1) # var:s1 -Edge: str("hello") -> var(s1) # var:s1 -Edge: str("world") -> var(s2) # var:s2 -Edge: str("world") -> var(s2) # var:s2 -Edge: str("world") -> var(s2) # var:s2 -Edge: var(s1) -> call:_operator(str("+"), var(s1), str(" ")) # a -Edge: var(s1) -> call:_operator(str("+"), var(s1), str(" ")) # a -Edge: var(s1) -> call:_operator(str("+"), var(s1), str(" ")) # a -Edge: var(s2) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # b -Edge: var(s2) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # b -Edge: var(s2) -> call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) # b -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -Vertex: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -Vertex: call:_operator(str("+"), var(s1), str(" ")) -Vertex: call:_operator(str("+"), var(s1), str(" ")) -Vertex: call:_operator(str("+"), var(s1), str(" ")) -Vertex: call:fn() -Vertex: call:fn() -Vertex: call:fn() -Vertex: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -Vertex: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -Vertex: func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } -Vertex: str(" ") -Vertex: str("+") -Vertex: str("+") -Vertex: str("greeting1") -Vertex: str("greeting2") -Vertex: str("greeting3") -Vertex: str("hello") -Vertex: str("world") -Vertex: var(s1) -Vertex: var(s1) -Vertex: var(s1) -Vertex: var(s2) -Vertex: var(s2) -Vertex: var(s2) +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Edge: FuncValue -> call # fn +Vertex: FuncValue +Vertex: FuncValue +Vertex: FuncValue +Vertex: call +Vertex: call +Vertex: call +Vertex: const +Vertex: const +Vertex: const diff --git a/lang/interpret_test/TestAstFunc2/chained-vars.txtar b/lang/interpret_test/TestAstFunc2/chained-vars.txtar new file mode 100644 index 00000000..72ffdcf2 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/chained-vars.txtar @@ -0,0 +1,10 @@ +-- main.mcl -- +import "fmt" + +$zero = 0 +$one = $zero + 1 +$two = $one + 1 # needs a chain to panic + +test fmt.printf("%d%d%d", $zero, $one, $two) {} +-- OUTPUT -- +Vertex: test[012] diff --git a/lang/interpret_test/TestAstFunc2/class-capture8.txtar b/lang/interpret_test/TestAstFunc2/class-capture8.txtar index 7d82d6b8..b19d726b 100644 --- a/lang/interpret_test/TestAstFunc2/class-capture8.txtar +++ b/lang/interpret_test/TestAstFunc2/class-capture8.txtar @@ -1,5 +1,6 @@ -- main.mcl -- $x1 = "bad1" +$x2 = "also bad" include defs.foo import "defs.mcl" # out of order for fun diff --git a/lang/interpret_test/TestAstFunc2/complex-example.txtar b/lang/interpret_test/TestAstFunc2/complex-example.txtar new file mode 100644 index 00000000..197e7612 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/complex-example.txtar @@ -0,0 +1,25 @@ +-- main.mcl -- +import "fmt" +import "iter" + +# function expression +$id1 = func($x str) { # definition site + $x +} +$id2 = func($x str) { + $x + $x +} + +$generate = func($idn) { + $idn("foo") # 1 call site, 2 calls +} + +$foo = iter.map([$id1, $id2,], $generate) + +#test $foo[0] {} +#test $foo[1] {} +test listlookup($foo, 0, "fail") {} # TODO: add syntactic sugar for listlookup +test listlookup($foo, 1, "fail") {} # TODO: add syntactic sugar for listlookup +-- OUTPUT -- +Vertex: test[foo] +Vertex: test[foofoo] diff --git a/lang/interpret_test/TestAstFunc2/definition-site-scope.txtar b/lang/interpret_test/TestAstFunc2/definition-site-scope.txtar new file mode 100644 index 00000000..f3d4979b --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/definition-site-scope.txtar @@ -0,0 +1,19 @@ +-- main.mcl -- +$x = "top-level" +func f1() { + $x + "1" +} +$f2 = func() { + $x + "2" +} +$call_f1 = func($x) { + f1() + $x +} +$call_f2 = func($x) { + $f2() + $x +} +test $call_f1("!") {} +test $call_f2("?") {} +-- OUTPUT -- +Vertex: test[top-level1!] +Vertex: test[top-level2?] diff --git a/lang/interpret_test/TestAstFunc2/func-duplicate-arg.txtar b/lang/interpret_test/TestAstFunc2/func-duplicate-arg.txtar new file mode 100644 index 00000000..da81f2d2 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/func-duplicate-arg.txtar @@ -0,0 +1,11 @@ +-- main.mcl -- +# function statement +func stradd($x) { + $x + $x +} + +$x1 = stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[heyhey] diff --git a/lang/interpret_test/TestAstFunc2/func-math1.txtar b/lang/interpret_test/TestAstFunc2/func-math1.txtar index 0c50de85..bf06d8b7 100644 --- a/lang/interpret_test/TestAstFunc2/func-math1.txtar +++ b/lang/interpret_test/TestAstFunc2/func-math1.txtar @@ -2,20 +2,14 @@ import "fmt" # function statement -func sq1($x, $y) { - $y + $x * $x +func sq1($x) { + $x + $x + #$x + 3 + #6 } -# function expression -$sq2 = func($x, $y) { - $y + $x * $x -} - -$x1 = sq1(3, 4) # 3^2 + 4 = 13 -$x2 = $sq2(7, -7) # 7^2 + 2 = 42 +$x1 = sq1(3) # 3^2 + 4 = 13 test fmt.printf("sq1: %d", $x1) {} -test fmt.printf("sq2: %d", $x2) {} -- OUTPUT -- -Vertex: test[sq1: 13] -Vertex: test[sq2: 42] +Vertex: test[sq1: 6] diff --git a/lang/interpret_test/TestAstFunc2/func-math2.txtar b/lang/interpret_test/TestAstFunc2/func-math2.txtar new file mode 100644 index 00000000..7f797c8d --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/func-math2.txtar @@ -0,0 +1,17 @@ +-- main.mcl -- +import "fmt" +import "math" + +# XXX: do the input nodes to _operator look weird here? in my testing I saw +# fortytwo appear, and then disappear before we finished running... +# function statement +func sq1($x) { + $x + 3 +} + +$x1 = sq1(math.fortytwo()) + +test fmt.printf("sq1: %d", $x1) {} + +-- OUTPUT -- +Vertex: test[sq1: 45] diff --git a/lang/interpret_test/TestAstFunc2/func-one-arg.txtar b/lang/interpret_test/TestAstFunc2/func-one-arg.txtar new file mode 100644 index 00000000..7f43aa63 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/func-one-arg.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" + +# function statement +func stradd($x) { + $x + "there" +} + +$x1 = stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[heythere] diff --git a/lang/interpret_test/TestAstFunc2/func-unused-arg.txtar b/lang/interpret_test/TestAstFunc2/func-unused-arg.txtar new file mode 100644 index 00000000..912d5746 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/func-unused-arg.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" + +# function statement +func stradd($x) { + "nothing" +} + +$x1 = stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[nothing] diff --git a/lang/interpret_test/TestAstFunc2/identity-function-statement.txtar b/lang/interpret_test/TestAstFunc2/identity-function-statement.txtar new file mode 100644 index 00000000..215088f6 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/identity-function-statement.txtar @@ -0,0 +1,9 @@ +-- main.mcl -- +# function statement +func identity($x) { + $x +} + +test identity("hey") {} +-- OUTPUT -- +Vertex: test[hey] diff --git a/lang/interpret_test/TestAstFunc2/if-0.txtar b/lang/interpret_test/TestAstFunc2/if-0.txtar new file mode 100644 index 00000000..4a38952a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/if-0.txtar @@ -0,0 +1,10 @@ +-- main.mcl -- +$out1 = if true { + "hello" +} else { + "world" +} + +test $out1 {} +-- OUTPUT -- +Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/if-in-func-0.txtar b/lang/interpret_test/TestAstFunc2/if-in-func-0.txtar new file mode 100644 index 00000000..7d3c1dc0 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/if-in-func-0.txtar @@ -0,0 +1,15 @@ +-- main.mcl -- +# this can return changing functions, and could be optimized, too +$fn = func($b) { + if true { + "hello" + } else { + "world" + } +} + +$out1 = $fn(true) + +test $out1 {} +-- OUTPUT -- +Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar b/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar index 92d1a3b2..4be4c38a 100644 --- a/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar +++ b/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar @@ -10,4 +10,4 @@ print "msg" { msg => fmt.printf("notfn: %d", $x), } -- OUTPUT -- -# err: errUnify: expected: Func, got: Int +# err: errUnify: func arg count differs diff --git a/lang/interpret_test/TestAstFunc2/lambda-duplicate-arg.txtar b/lang/interpret_test/TestAstFunc2/lambda-duplicate-arg.txtar new file mode 100644 index 00000000..67ca8114 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/lambda-duplicate-arg.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" + +# function statement +$stradd = func($x) { + $x + $x +} + +$x1 = $stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[heyhey] diff --git a/lang/interpret_test/TestAstFunc2/lambda-no-args1.txtar b/lang/interpret_test/TestAstFunc2/lambda-no-args1.txtar new file mode 100644 index 00000000..5b55d9bb --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/lambda-no-args1.txtar @@ -0,0 +1,8 @@ +-- main.mcl -- +$hey = func() { + "hello" +} + +test $hey() {} +-- OUTPUT -- +Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/lambda-one-arg.txtar b/lang/interpret_test/TestAstFunc2/lambda-one-arg.txtar new file mode 100644 index 00000000..bae4706c --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/lambda-one-arg.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" + +# function statement +$stradd = func($x) { + $x + "there" +} + +$x1 = $stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[heythere] diff --git a/lang/interpret_test/TestAstFunc2/lambda-one-func.txtar b/lang/interpret_test/TestAstFunc2/lambda-one-func.txtar new file mode 100644 index 00000000..7421121a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/lambda-one-func.txtar @@ -0,0 +1,6 @@ +-- main.mcl -- +import "fmt" + +test fmt.printf("hello: %d", 42) {} +-- OUTPUT -- +Vertex: test[hello: 42] diff --git a/lang/interpret_test/TestAstFunc2/lambda-unused-arg.txtar b/lang/interpret_test/TestAstFunc2/lambda-unused-arg.txtar new file mode 100644 index 00000000..9c1743ed --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/lambda-unused-arg.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" + +# function statement +$stradd = func($x) { + "nothing" +} + +$x1 = $stradd("hey") + +test $x1 {} +-- OUTPUT -- +Vertex: test[nothing] diff --git a/lang/interpret_test/TestAstFunc2/map-ignore-arg.txtar b/lang/interpret_test/TestAstFunc2/map-ignore-arg.txtar new file mode 100644 index 00000000..d78a3034 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/map-ignore-arg.txtar @@ -0,0 +1,10 @@ +-- main.mcl -- +import "iter" + +$fn = func($x) { # ignore arg + "hey" +} + +test iter.map([1, 2, 3,], $fn) {} +-- OUTPUT -- +Vertex: test[hey] diff --git a/lang/interpret_test/TestAstFunc2/map-iterator0.txtar.TODO b/lang/interpret_test/TestAstFunc2/map-iterator0.txtar similarity index 100% rename from lang/interpret_test/TestAstFunc2/map-iterator0.txtar.TODO rename to lang/interpret_test/TestAstFunc2/map-iterator0.txtar diff --git a/lang/interpret_test/TestAstFunc2/map-iterator1.txtar.TODO b/lang/interpret_test/TestAstFunc2/map-iterator1.txtar similarity index 100% rename from lang/interpret_test/TestAstFunc2/map-iterator1.txtar.TODO rename to lang/interpret_test/TestAstFunc2/map-iterator1.txtar diff --git a/lang/interpret_test/TestAstFunc2/map-iterator2.txtar.TODO b/lang/interpret_test/TestAstFunc2/map-iterator2.txtar similarity index 100% rename from lang/interpret_test/TestAstFunc2/map-iterator2.txtar.TODO rename to lang/interpret_test/TestAstFunc2/map-iterator2.txtar diff --git a/lang/interpret_test/TestAstFunc2/map-iterator3.txtar.TODO b/lang/interpret_test/TestAstFunc2/map-iterator3.txtar similarity index 100% rename from lang/interpret_test/TestAstFunc2/map-iterator3.txtar.TODO rename to lang/interpret_test/TestAstFunc2/map-iterator3.txtar diff --git a/lang/interpret_test/TestAstFunc2/map-iterator4.txtar.TODO b/lang/interpret_test/TestAstFunc2/map-iterator4.txtar similarity index 100% rename from lang/interpret_test/TestAstFunc2/map-iterator4.txtar.TODO rename to lang/interpret_test/TestAstFunc2/map-iterator4.txtar diff --git a/lang/interpret_test/TestAstFunc2/map-numbered.txtar b/lang/interpret_test/TestAstFunc2/map-numbered.txtar new file mode 100644 index 00000000..9edbb4b2 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/map-numbered.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +import "fmt" +import "iter" + +$fn = func($x) { + fmt.printf("hey%d", $x) +} + +test iter.map([1, 2, 3,], $fn) {} +-- OUTPUT -- +Vertex: test[hey1] +Vertex: test[hey2] +Vertex: test[hey3] diff --git a/lang/interpret_test/TestAstFunc2/res0.txtar b/lang/interpret_test/TestAstFunc2/res0.txtar new file mode 100644 index 00000000..54ed6098 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/res0.txtar @@ -0,0 +1,2 @@ +-- main.mcl -- +-- OUTPUT -- diff --git a/lang/interpret_test/TestAstFunc2/res1.txtar b/lang/interpret_test/TestAstFunc2/res1.txtar new file mode 100644 index 00000000..6a2f0e61 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/res1.txtar @@ -0,0 +1,6 @@ +-- main.mcl -- +test "t1" { + stringptr => 42, # int, not str +} +-- OUTPUT -- +# err: errUnify: can't unify, invariant illogicality with equals: base kind does not match (Int != Str) diff --git a/lang/interpret_test/TestAstFunc2/res2.txtar b/lang/interpret_test/TestAstFunc2/res2.txtar new file mode 100644 index 00000000..a27e04a1 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/res2.txtar @@ -0,0 +1,8 @@ +-- main.mcl -- +test "t1" { + int64ptr => 42, + stringptr => "okay cool", + int8ptrptrptr => 127, # super nested +} +-- OUTPUT -- +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/res3.txtar b/lang/interpret_test/TestAstFunc2/res3.txtar new file mode 100644 index 00000000..d22ebb2e --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/res3.txtar @@ -0,0 +1,13 @@ +-- main.mcl -- +test "t1" { + int64ptr => 42, +} +test "t2" { + int64ptr => 13, +} + +Test["t1"].hello -> Test["t2"].stringptr # send/recv +-- OUTPUT -- +Edge: test[t1] -> test[t2] # test[t1] -> test[t2] +Vertex: test[t1] +Vertex: test[t2] diff --git a/lang/interpret_test/TestAstFunc2/res4.txtar b/lang/interpret_test/TestAstFunc2/res4.txtar new file mode 100644 index 00000000..59d6757f --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/res4.txtar @@ -0,0 +1,37 @@ +-- main.mcl -- +test "t1" { + stringptr => "this is meta", + + #Meta => struct{ + # noop => false, + # retry => -1, + # retryreset => false, + # delay => 0, + # poll => 5, + # limit => 4.2, + # burst => 3, + # reset => false, + # sema => ["foo:1", "bar:3",], + # rewatch => false, + # realize => true, + # reverse => true, + # autoedge => true, + # autogroup => true, + #}, + Meta:noop => false, + Meta:retry => -1, + Meta:retryreset => false, + Meta:delay => 0, + Meta:poll => 5, + Meta:limit => 4.2, + Meta:burst => 3, + Meta:reset => false, + Meta:sema => ["foo:1", "bar:3",], + Meta:rewatch => false, + Meta:realize => true, + Meta:reverse => true, + Meta:autoedge => true, + Meta:autogroup => true, +} +-- OUTPUT -- +Vertex: test[t1] diff --git a/lang/interpret_test/TestAstFunc2/template-1.txtar b/lang/interpret_test/TestAstFunc2/template-1.txtar new file mode 100644 index 00000000..0c98aba3 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/template-1.txtar @@ -0,0 +1,8 @@ +-- main.mcl -- +$v = 42 +$x = template("hello", $v) # redirect var for harder unification +test $x { + #anotherstr => $x, +} +-- OUTPUT -- +Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/very-complex-example.txtar b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar new file mode 100644 index 00000000..94843f0a --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar @@ -0,0 +1,78 @@ +-- main.mcl -- +# This code should fail during type-checking. +# +# $id1 and $id2 are both polymorphic functions, which can be specialized to a +# different monomorphic type at every use site. In simple code, this +# specialization happens when the polymorphic function is called, but in more +# complex code, the specialization happens earlier, when the polymorphic +# function is passed as an argument to higher-order functions such as $generate +# and iter.map. +# +# In: +# +# $id1 = func($x str) { # definition site +# $x +# } +# $id2 = func($x str) { +# $x + $x +# } +# +# $generate = func($idn) { +# $idn("foo") # 1 call site, 2 calls +# } +# +# $foo = iter.map([$id1, $id2,], $generate) +# +# $generate is specialized to `func(func(str) str) str`, and $id1 and $id2 are +# specialized to `func(str) str`. +# +# In: +# +# $id1 = func($x) { # definition site +# $x +# } +# $id2 = func($x) { +# $x + $x +# } +# +# $generate = func($idn) { +# fmt.printf("%s %d", +# $idn("foo"), # 1 call site, 2 calls +# $idn(42) +# ) +# } +# +# $foo = iter.map([$id1, $id2,], $generate) +# +# $idn cannot be given a monomorphic type, since it is used both as a +# `func(str) str` and as a `func(int) int`. Therefore, $generate cannot be +# given a monomorphic type either, and neither can the call to iter.map. + +import "fmt" +import "iter" + +# function expression +$id1 = func($x) { # definition site + $x +} +$id2 = func($x) { + $x + $x +} + +#$str = $id1("foo") +#$int = $id1(42) + +$generate = func($idn) { + fmt.printf("%s %d", + $idn("foo"), # 1 call site, 2 calls + $idn(42) + ) +} + +# this code should be rejected during type unification +$foo = iter.map([$id1, $id2,], $generate) + +#test $foo[0] {} +test listlookup($foo, 0, "fail") {} # TODO: add syntactic sugar for listlookup +-- OUTPUT -- +# err: errUnify: can't unify, invariant illogicality with equals: base kind does not match (Str != Int)