From 447fd937ded857b74d611a188308dfb81937f0d7 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sat, 23 Dec 2023 10:04:43 +0100 Subject: [PATCH] Be less restrictive when writing function calls --- src/Visp.Compiler/Syntax/SynWriter.fs | 4 ++- .../ParsingTests.generated.fs | 5 ++++ ...s_macros_up-macro-0.can parse.verified.txt | 28 +++++++++++++++++++ .../ExecutionTests.generated.fs | 5 ++++ ...macros_up-macro-0.can execute.verified.txt | 4 +++ visp/tests/macros/up-macro-0.visp | 17 +++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_up-macro-0.can parse.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_up-macro-0.can execute.verified.txt create mode 100644 visp/tests/macros/up-macro-0.visp diff --git a/src/Visp.Compiler/Syntax/SynWriter.fs b/src/Visp.Compiler/Syntax/SynWriter.fs index 2877039..ea4754e 100644 --- a/src/Visp.Compiler/Syntax/SynWriter.fs +++ b/src/Visp.Compiler/Syntax/SynWriter.fs @@ -910,7 +910,9 @@ module Write = writeExpr w st ex writeCallArgs w args - | _ -> failwithf "not callable %O" expr + | it -> + writeExpr w WriteState.Inline it + writeCallArgs w args | SynExpr.Symbol sym -> diff --git a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs index a557edf..6770e6d 100644 --- a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs @@ -310,6 +310,11 @@ module ``tests_builtin-macros_cond-0`` = [] let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" +[] +module ``tests_macros_up-macro-0`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/macros/up-macro-0.visp" + [] module ``tests_macros_nested-macro-expansion-0`` = [] diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_up-macro-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_up-macro-0.can parse.verified.txt new file mode 100644 index 0000000..76c3041 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_up-macro-0.can parse.verified.txt @@ -0,0 +1,28 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"up-macro-0.visp" +let DoingThings () = + // line 9 @"up-macro-0.visp" + let mutable items = + // line 9 @"up-macro-0.visp" + [] |> Set.ofList + // line 11 @"up-macro-0.visp" + for i = 0 to 5 do + // line 12 @"up-macro-0.visp" + + // line 12 @"up-macro-0.visp" + items <- Set.add i items + items + +// line 17 @"up-macro-0.visp" +let visp_result_todo = + // line 17 @"up-macro-0.visp" + printfn "%A" (DoingThings ()) +// line 17 @"up-macro-0.visp" +printfn "%A" visp_result_todo + diff --git a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs index 2d31c84..8c459cf 100644 --- a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs +++ b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs @@ -310,6 +310,11 @@ module ``tests_builtin-macros_cond-0`` = [] let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" +[] +module ``tests_macros_up-macro-0`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/macros/up-macro-0.visp" + [] module ``tests_macros_nested-macro-expansion-0`` = [] diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_up-macro-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_up-macro-0.can execute.verified.txt new file mode 100644 index 0000000..a44223f --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_up-macro-0.can execute.verified.txt @@ -0,0 +1,4 @@ +set [0; 1; 2; 3; 4; 5] +() + +ExitCode: 0 diff --git a/visp/tests/macros/up-macro-0.visp b/visp/tests/macros/up-macro-0.visp new file mode 100644 index 0000000..b0ea91a --- /dev/null +++ b/visp/tests/macros/up-macro-0.visp @@ -0,0 +1,17 @@ +;; Copyright 2023 Ville Penttinen +;; Distributed under the MIT License. +;; https://github.com/vipentti/visp-fs/blob/main/LICENSE.md +;; +;; for basic syntax highlighting +;; vim: set syntax=clojure: + +(fn DoingThings () + (mut items (!set)) + + (for/to [i (0 to 5)] + (up! items (Set.add i))) + + items) + + +(printfn "%A" (DoingThings))