Skip to content

Commit

Permalink
Be less restrictive when writing function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 23, 2023
1 parent 432b262 commit 447fd93
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Visp.Compiler/Syntax/SynWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
5 changes: 5 additions & 0 deletions tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ module ``tests_builtin-macros_cond-0`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_macros_up-macro-0`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/macros/up-macro-0.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_macros_nested-macro-expansion-0`` =
[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions tests/Visp.ExecutionTests/ExecutionTests.generated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ module ``tests_builtin-macros_cond-0`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_macros_up-macro-0`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/macros/up-macro-0.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_macros_nested-macro-expansion-0`` =
[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set [0; 1; 2; 3; 4; 5]
()

ExitCode: 0
17 changes: 17 additions & 0 deletions visp/tests/macros/up-macro-0.visp
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 447fd93

Please sign in to comment.