From 346a792b9234dc78ecf51800f866d99406653c6a Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 26 Dec 2023 11:50:00 +0100 Subject: [PATCH] Add byrefs-0.visp tests --- .../ParsingTests.generated.fs | 5 + .../StructuredOutputTests.generated.fs | 5 + .../TokenOutputTests.generated.fs | 5 + ...pe_byrefs-0.structured output.verified.txt | 135 ++++++++++ ...tests_type_byrefs-0.can parse.verified.txt | 113 +++++++++ ..._type_byrefs-0.returns tokens.verified.txt | 239 ++++++++++++++++++ .../ExecutionTests.generated.fs | 5 + ...sts_type_byrefs-0.can execute.verified.txt | 8 + visp/tests/type/byrefs-0.visp | 54 ++++ 9 files changed, 569 insertions(+) create mode 100644 tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_type_byrefs-0.structured output.verified.txt create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_type_byrefs-0.can parse.verified.txt create mode 100644 tests/Visp.Compiler.UnitTests/token-snapshots/tests_type_byrefs-0.returns tokens.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_type_byrefs-0.can execute.verified.txt create mode 100644 visp/tests/type/byrefs-0.visp diff --git a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs index d68b076..d62945f 100644 --- a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs @@ -65,6 +65,11 @@ module ``tests_type_custom-comparison-0`` = [] let ``can parse`` () = TestUtils.runTest "tests/type/custom-comparison-0.visp" +[] +module ``tests_type_byrefs-0`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/type/byrefs-0.visp" + [] module ``tests_type_static-members-0`` = [] diff --git a/tests/Visp.Compiler.UnitTests/StructuredOutputTests.generated.fs b/tests/Visp.Compiler.UnitTests/StructuredOutputTests.generated.fs index d4696d5..4d3bf35 100644 --- a/tests/Visp.Compiler.UnitTests/StructuredOutputTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/StructuredOutputTests.generated.fs @@ -65,6 +65,11 @@ module ``tests_type_custom-comparison-0`` = [] let ``structured output`` () = TestUtils.runStructuredOutputTest "tests/type/custom-comparison-0.visp" +[] +module ``tests_type_byrefs-0`` = + [] + let ``structured output`` () = TestUtils.runStructuredOutputTest "tests/type/byrefs-0.visp" + [] module ``tests_type_static-members-0`` = [] diff --git a/tests/Visp.Compiler.UnitTests/TokenOutputTests.generated.fs b/tests/Visp.Compiler.UnitTests/TokenOutputTests.generated.fs index 8fb6a1d..4d0f0fa 100644 --- a/tests/Visp.Compiler.UnitTests/TokenOutputTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/TokenOutputTests.generated.fs @@ -65,6 +65,11 @@ module ``tests_type_custom-comparison-0`` = [] let ``returns tokens`` () = TestUtils.runTokenTest "tests/type/custom-comparison-0.visp" +[] +module ``tests_type_byrefs-0`` = + [] + let ``returns tokens`` () = TestUtils.runTokenTest "tests/type/byrefs-0.visp" + [] module ``tests_type_static-members-0`` = [] diff --git a/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_type_byrefs-0.structured output.verified.txt b/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_type_byrefs-0.structured output.verified.txt new file mode 100644 index 0000000..cb9d3a0 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_type_byrefs-0.structured output.verified.txt @@ -0,0 +1,135 @@ +ParsedFile + [AnonModule + ([Open (SynSymbol System, (9,1--9,12)); + Expr + (Type + (SynSymbol C1, Args (Tuple [], (11,9--11,11)), + [Let + (Named (SynSymbol nums, (12,7--12,11)), + Collection + (SynCollection + (FsArray, + [Const (Int32 1, (12,15--12,16)); Const (Int32 3, (12,17--12,18)); + Const (Int32 7, (12,19--12,20)); Const (Int32 15, (12,21--12,23)); + Const (Int32 31, (12,24--12,26)); Const (Int32 63, (12,27--12,29)); + Const (Int32 127, (12,30--12,33)); Const (Int32 255, (12,34--12,37)); + Const (Int32 511, (12,38--12,41)); Const (Int32 1023, (12,42--12,46))], (12,12--12,49))), + Mutable, [], (12,3--12,49)); + MemberFn + (SynSymbol _.ToString, Args (List [], (13,26--13,28)), + [DotMethod + (Symbol (SynSymbol System.String), SynSymbol Join, + [Const (Char ' ', (13,50--13,57)); Symbol (SynSymbol nums)], Tuple, (13,30--13,62))], Override, [], + (13,3--13,63)); + MemberFn + (SynSymbol _.FindLargestSmallerThan, + Args (List [Named (SynSymbol target, (15,39--15,45))], (15,38--15,46)), + [LetOrUse + (Named (SynSymbol ctr, (16,9--16,12)), + FunctionCall + (Symbol (SynSymbol dec), + [DotProperty (Symbol (SynSymbol nums), SynSymbol Length, (16,19--16,31))], (16,14--16,32)), + Mutable, [], (16,5--16,33)); + While + (Op + (Infix + (SynSymbol &&, + [Op + (Infix + (SynSymbol >, [Symbol (SynSymbol ctr); Const (Int32 0, (18,22--18,23))], (18,16--18,23))); + Op + (Infix + (SynSymbol >=, + [DotIndex (Symbol (SynSymbol nums), [Symbol (SynSymbol ctr)], (18,30--18,41)); + Symbol (SynSymbol target)], (18,26--18,49)))], (18,11--18,50))), + [SyntaxMacroCall + (SynMacroCall + (SynSymbol up!, [Symbol (SynSymbol up!); Symbol (SynSymbol ctr); Symbol (SynSymbol dec)], + (19,7--19,18)))], (18,5--19,19)); + If + (Op (Infix (SynSymbol >, [Symbol (SynSymbol ctr); Const (Int32 0, (21,15--21,16))], (21,9--21,16))), + DotIndex (Symbol (SynSymbol &nums), [Symbol (SynSymbol ctr)], (22,7--22,19)), + Some (DotIndex (Symbol (SynSymbol &nums), [Const (Int32 0, (23,9--23,10))], (23,7--23,17))), + (21,5--23,18))], Default, [], (15,3--24,5))], [], (11,1--24,6)), (11,0--24,7)); + Expr + (FunctionDef + (SynSymbol C1Test, None, Args (List [], (26,11--26,13)), + [LetOrUse + (Named (SynSymbol c1, (27,7--27,9)), FunctionCall (Symbol (SynSymbol C1), [], (27,11--27,13)), None, [], + (27,3--27,14)); + FunctionCall + (Symbol (SynSymbol printfn), + [Const (String ("Original sequence: %O{c1}", Interpolated 1, (28,11--28,39)), (28,11--28,39))], + (28,3--28,39)); + LetOrUse + (Named (SynSymbol v, (29,7--29,8)), + DotMethod + (Symbol (SynSymbol &c1), SynSymbol FindLargestSmallerThan, [Const (Int32 16, (29,38--29,40))], Tuple, + (29,10--29,40)), None, [], (29,3--29,41)); + Set + (Symbol (SynSymbol v), + Op (Infix (SynSymbol *, [Symbol (SynSymbol v); Const (Int32 2, (30,15--30,16))], (30,11--30,16))), + (30,3--30,17)); + FunctionCall + (Symbol (SynSymbol printfn), + [Const (String ("New sequence: %O{c1}", Interpolated 1, (31,11--31,39)), (31,11--31,39))], + (31,3--31,39))], None, (26,1--31,40)), (26,0--31,41)); + Expr (FunctionCall (Symbol (SynSymbol C1Test), [], (33,1--33,7)), (33,0--33,8)); + Expr + (FunctionDef + (SynSymbol f_inref, None, + Args + (List + [Typed + (Named (SynSymbol dt, (35,14--35,16)), Generic (Ident inref, [Ident DateTime], (35,18--35,33)), + (35,13--35,34))], (35,12--35,35)), + [FunctionCall + (Symbol (SynSymbol printfn), + [Const (String ("Now: {dt:``yyyy-MM-dd``}", Interpolated 1, (36,11--36,38)), (36,11--36,38))], + (36,3--36,38))], None, (35,1--36,39)), (35,0--36,40)); + Expr + (FunctionDef + (SynSymbol f_byref, None, + Args + (List + [Typed + (Named (SynSymbol dt, (38,14--38,16)), Generic (Ident byref, [Ident DateTime], (38,18--38,33)), + (38,13--38,34))], (38,12--38,35)), + [FunctionCall + (Symbol (SynSymbol printfn), + [Const (String ("Now: {dt:``yyyy-MM-dd``}", Interpolated 1, (39,11--39,38)), (39,11--39,38))], + (39,3--39,38)); + Set + (Symbol (SynSymbol dt), + DotMethod + (Symbol (SynSymbol dt), SynSymbol AddDays, [Const (Int32 1, (40,24--40,25))], Tuple, (40,12--40,25)), + (40,3--40,26))], None, (38,1--40,27)), (38,0--40,28)); + Expr + (FunctionDef + (SynSymbol UsingByrefs, None, Args (List [], (42,16--42,18)), + [LetOrUse + (Named (SynSymbol dt, (43,7--43,9)), + New + (Ident DateTime, + [Const (Int32 2023, (43,24--43,28)); Const (Int32 12, (43,29--43,31)); + Const (Int32 26, (43,32--43,34))], (43,11--43,34)), None, [], (43,3--43,35)); + FunctionCall (Symbol (SynSymbol f_inref), [Symbol (SynSymbol &dt)], (44,3--44,14)); + LetOrUse + (Named (SynSymbol dt, (46,7--46,9)), + New + (Ident DateTime, + [Const (Int32 2023, (46,24--46,28)); Const (Int32 12, (46,29--46,31)); + Const (Int32 26, (46,32--46,34))], (46,11--46,34)), Mutable, [], (46,3--46,35)); + FunctionCall (Symbol (SynSymbol f_byref), [Symbol (SynSymbol &dt)], (47,3--47,14)); + FunctionCall (Symbol (SynSymbol f_inref), [Symbol (SynSymbol &dt)], (48,3--48,14)); + Const (Unit, (50,2--50,4))], None, (42,1--50,4)), (42,0--50,5)); + Expr (FunctionCall (Symbol (SynSymbol UsingByrefs), [], (52,1--52,12)), (52,0--52,13)); + Expr + (LetOrUse + (Named (SynSymbol visp_result_todo, (54,0--54,2)), Const (Unit, (54,0--54,2)), None, [], (54,0--54,2)), + (54,0--54,2)); + Expr + (FunctionCall + (Symbol (SynSymbol printfn), + [Const (String ("%A", Regular, (54,0--54,2)), (54,0--54,2)); Symbol (SynSymbol visp_result_todo)], + (54,0--54,2)), (54,0--54,2))], (9,0--54,2))] \ No newline at end of file diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_type_byrefs-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_type_byrefs-0.can parse.verified.txt new file mode 100644 index 0000000..31ae2a4 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_type_byrefs-0.can parse.verified.txt @@ -0,0 +1,113 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 28 @"byrefs-0.visp" +let inline ``LiftedString0_byrefs-0`` c1 : Printf.TextWriterFormat<_> = + $"Original sequence: %O{c1}" + +// line 31 @"byrefs-0.visp" +let inline ``LiftedString1_byrefs-0`` c1 : Printf.TextWriterFormat<_> = + $"New sequence: %O{c1}" + +// line 36 @"byrefs-0.visp" +let inline ``LiftedString2_byrefs-0`` dt : Printf.TextWriterFormat<_> = + $"Now: {dt:``yyyy-MM-dd``}" + +// line 39 @"byrefs-0.visp" +let inline ``LiftedString3_byrefs-0`` dt : Printf.TextWriterFormat<_> = + $"Now: {dt:``yyyy-MM-dd``}" + +// line 9 @"byrefs-0.visp" +open System + +// line 11 @"byrefs-0.visp" +type C1 () = + // line 12 @"byrefs-0.visp" + let mutable nums = + // line 12 @"byrefs-0.visp" + [|1;3;7;15;31;63;127;255;511;1023|] + // line 13 @"byrefs-0.visp" + override _.ToString () = + // line 13 @"byrefs-0.visp" + System.String.Join(' ', nums) + // line 15 @"byrefs-0.visp" + member _.FindLargestSmallerThan target = + // line 16 @"byrefs-0.visp" + let mutable ctr = + // line 16 @"byrefs-0.visp" + dec ((nums.Length)) + // line 18 @"byrefs-0.visp" + while CoreMethods.isTruthy(((ctr > 0) && ((nums.[ctr]) >= target))) do + // line 19 @"byrefs-0.visp" + + // line 19 @"byrefs-0.visp" + ctr <- dec ctr + // line 21 @"byrefs-0.visp" + if CoreMethods.isTruthy( + (ctr > 0)) + then + // line 22 @"byrefs-0.visp" + (&nums.[ctr]) + else + // line 23 @"byrefs-0.visp" + (&nums.[0]) +// line 26 @"byrefs-0.visp" +let C1Test () = + // line 27 @"byrefs-0.visp" + let c1 = + // line 27 @"byrefs-0.visp" + C1 () + // line 28 @"byrefs-0.visp" + printfn (``LiftedString0_byrefs-0`` c1) + // line 29 @"byrefs-0.visp" + let v = + // line 29 @"byrefs-0.visp" + &c1.FindLargestSmallerThan(16) + // line 30 @"byrefs-0.visp" + v <- (v * 2) + // line 31 @"byrefs-0.visp" + printfn (``LiftedString1_byrefs-0`` c1) + +// line 33 @"byrefs-0.visp" +C1Test () +// line 35 @"byrefs-0.visp" +let f_inref (dt: inref) = + // line 36 @"byrefs-0.visp" + printfn (``LiftedString2_byrefs-0`` dt) + +// line 38 @"byrefs-0.visp" +let f_byref (dt: byref) = + // line 39 @"byrefs-0.visp" + printfn (``LiftedString3_byrefs-0`` dt) + // line 40 @"byrefs-0.visp" + dt <- (dt.AddDays(1)) + +// line 42 @"byrefs-0.visp" +let UsingByrefs () = + // line 43 @"byrefs-0.visp" + let dt = + // line 43 @"byrefs-0.visp" + (new DateTime(2023, 12, 26)) + // line 44 @"byrefs-0.visp" + f_inref &dt + // line 46 @"byrefs-0.visp" + let mutable dt = + // line 46 @"byrefs-0.visp" + (new DateTime(2023, 12, 26)) + // line 47 @"byrefs-0.visp" + f_byref &dt + // line 48 @"byrefs-0.visp" + f_inref &dt + () + +// line 52 @"byrefs-0.visp" +UsingByrefs () +// line 54 @"byrefs-0.visp" +let visp_result_todo = () +// line 54 @"byrefs-0.visp" +printfn "%A" visp_result_todo + diff --git a/tests/Visp.Compiler.UnitTests/token-snapshots/tests_type_byrefs-0.returns tokens.verified.txt b/tests/Visp.Compiler.UnitTests/token-snapshots/tests_type_byrefs-0.returns tokens.verified.txt new file mode 100644 index 0000000..7fc1292 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/token-snapshots/tests_type_byrefs-0.returns tokens.verified.txt @@ -0,0 +1,239 @@ +LPAREN Default 0 1 LParen +OPEN Default 0 1 LParen +SYMBOL "System" Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +TYPE Default 0 1 Type +SYMBOL "C1" Default 0 1 Type +LPAREN Default 0 2 Type +RPAREN Default 0 1 Type +LPAREN Default 0 2 Type +MUT Default 0 2 Type +SYMBOL "nums" Default 0 2 Type +BRACKET_BAR Default 0 2 Type +INT32 (1, false) Default 0 2 Type +INT32 (3, false) Default 0 2 Type +INT32 (7, false) Default 0 2 Type +INT32 (15, false) Default 0 2 Type +INT32 (31, false) Default 0 2 Type +INT32 (63, false) Default 0 2 Type +INT32 (127, false) Default 0 2 Type +INT32 (255, false) Default 0 2 Type +INT32 (511, false) Default 0 2 Type +INT32 (1023, false) Default 0 2 Type +BAR_BRACKET Default 0 2 Type +RPAREN Default 0 1 Type +LPAREN Default 0 2 Type +OVERRIDE Default 0 2 Type +FN Default 0 2 Type +SYMBOL "_.ToString" Default 0 2 Type +LPAREN Default 0 3 Type +RPAREN Default 0 2 Type +LPAREN Default 0 3 Type +DOT_METHOD ".Join" Default 0 3 Type +SYMBOL "System.String" Default 0 3 Type +CHAR "#\space" Default 0 3 Type +SYMBOL "nums" Default 0 3 Type +RPAREN Default 0 2 Type +RPAREN Default 0 1 Type +LPAREN Default 0 2 Type +MEMBER Default 0 2 Member +FN Default 0 2 Member +SYMBOL "_.FindLargestSmallerThan" Default 0 2 Member +LPAREN Default 0 3 Member +SYMBOL "target" Default 0 3 Member +RPAREN Default 0 2 Member +LPAREN Default 0 3 Member +MUT Default 0 3 Member +SYMBOL "ctr" Default 0 3 Member +LPAREN Default 0 4 Member +SYMBOL "dec" Default 0 4 Member +LPAREN Default 0 5 Member +PROP_PLUS "+Length" Default 0 5 Member +SYMBOL "nums" Default 0 5 Member +RPAREN Default 0 4 Member +RPAREN Default 0 3 Member +RPAREN Default 0 2 Member +LPAREN Default 0 3 Member +WHILE Default 0 3 Member +LPAREN Default 0 4 Member +INFIX_OP "&&" Default 0 4 Member +LPAREN Default 0 5 Member +OP_GREATER Default 0 5 Member +SYMBOL "ctr" Default 0 5 Member +INT32 (0, false) Default 0 5 Member +RPAREN Default 0 4 Member +LPAREN Default 0 5 Member +GREATER_EQUALS Default 0 5 Member +LPAREN Default 0 6 Member +DOT_BRACKET Default 0 6 Member +SYMBOL "ctr" Default 0 6 Member +RBRACKET Default 0 6 Member +SYMBOL "nums" Default 0 6 Member +RPAREN Default 0 5 Member +SYMBOL "target" Default 0 5 Member +RPAREN Default 0 4 Member +RPAREN Default 0 3 Member +LPAREN Default 0 4 Member +MACRO_NAME "up!" TokenStream Macro 1 4 Member +SYMBOL "ctr" TokenStream Macro 1 4 Member +SYMBOL "dec" TokenStream Macro 1 4 Member +RPAREN Default 0 3 Member +RPAREN Default 0 2 Member +LPAREN Default 0 3 Member +IF_KW Default 0 3 Member +LPAREN Default 0 4 Member +OP_GREATER Default 0 4 Member +SYMBOL "ctr" Default 0 4 Member +INT32 (0, false) Default 0 4 Member +RPAREN Default 0 3 Member +LPAREN Default 0 4 Member +DOT_BRACKET Default 0 4 Member +SYMBOL "ctr" Default 0 4 Member +RBRACKET Default 0 4 Member +SYMBOL "&nums" Default 0 4 Member +RPAREN Default 0 3 Member +LPAREN Default 0 4 Member +DOT_BRACKET Default 0 4 Member +INT32 (0, false) Default 0 4 Member +RBRACKET Default 0 4 Member +SYMBOL "&nums" Default 0 4 Member +RPAREN Default 0 3 Member +RPAREN Default 0 2 Member +RPAREN Default 0 1 Type +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +FN Default 0 1 LParen +SYMBOL "C1Test" Default 0 1 LParen +LPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +LET Default 0 2 LParen +SYMBOL "c1" Default 0 2 LParen +LPAREN Default 0 3 LParen +SYMBOL "C1" Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "printfn" Default 0 2 LParen +STRING ("Original sequence: %O{c1}", Interpolated 1, Token []) Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +LET Default 0 2 LParen +SYMBOL "v" Default 0 2 LParen +LPAREN Default 0 3 LParen +DOT_METHOD ".FindLargestSmallerThan" Default 0 3 LParen +SYMBOL "&c1" Default 0 3 LParen +INT32 (16, false) Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SET Default 0 2 LParen +SYMBOL "v" Default 0 2 LParen +LPAREN Default 0 3 LParen +OP_MULT Default 0 3 LParen +SYMBOL "v" Default 0 3 LParen +INT32 (2, false) Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "printfn" Default 0 2 LParen +STRING ("New sequence: %O{c1}", Interpolated 1, Token []) Default 0 2 LParen +RPAREN Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +SYMBOL "C1Test" Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +FN Default 0 1 LParen +SYMBOL "f_inref" Default 0 1 LParen +LPAREN Default 0 2 LParen +LBRACKET Default 0 2 LParen +SYMBOL "dt" Default 0 2 LParen +COLON Default 0 2 LParen +SYMBOL "inref" Default 0 2 LParen +OP_LESS Default 0 2 LParen +SYMBOL "DateTime" Default 0 2 LParen +OP_GREATER Default 0 2 LParen +RBRACKET Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "printfn" Default 0 2 LParen +STRING ("Now: {dt:``yyyy-MM-dd``}", Interpolated 1, Token []) Default 0 2 LParen +RPAREN Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +FN Default 0 1 LParen +SYMBOL "f_byref" Default 0 1 LParen +LPAREN Default 0 2 LParen +LBRACKET Default 0 2 LParen +SYMBOL "dt" Default 0 2 LParen +COLON Default 0 2 LParen +SYMBOL "byref" Default 0 2 LParen +OP_LESS Default 0 2 LParen +SYMBOL "DateTime" Default 0 2 LParen +OP_GREATER Default 0 2 LParen +RBRACKET Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "printfn" Default 0 2 LParen +STRING ("Now: {dt:``yyyy-MM-dd``}", Interpolated 1, Token []) Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SET Default 0 2 LParen +SYMBOL "dt" Default 0 2 LParen +LPAREN Default 0 3 LParen +DOT_METHOD ".AddDays" Default 0 3 LParen +SYMBOL "dt" Default 0 3 LParen +INT32 (1, false) Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +FN Default 0 1 LParen +SYMBOL "UsingByrefs" Default 0 1 LParen +LPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +LET Default 0 2 LParen +SYMBOL "dt" Default 0 2 LParen +LPAREN Default 0 3 LParen +NEW Default 0 3 LParen +SYMBOL "DateTime" Default 0 3 LParen +INT32 (2023, false) Default 0 3 LParen +INT32 (12, false) Default 0 3 LParen +INT32 (26, false) Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "f_inref" Default 0 2 LParen +SYMBOL "&dt" Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +MUT Default 0 2 LParen +SYMBOL "dt" Default 0 2 LParen +LPAREN Default 0 3 LParen +NEW Default 0 3 LParen +SYMBOL "DateTime" Default 0 3 LParen +INT32 (2023, false) Default 0 3 LParen +INT32 (12, false) Default 0 3 LParen +INT32 (26, false) Default 0 3 LParen +RPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "f_byref" Default 0 2 LParen +SYMBOL "&dt" Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +SYMBOL "f_inref" Default 0 2 LParen +SYMBOL "&dt" Default 0 2 LParen +RPAREN Default 0 1 LParen +LPAREN Default 0 2 LParen +RPAREN Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +SYMBOL "UsingByrefs" Default 0 1 LParen +RPAREN Default 0 0 Default +LPAREN Default 0 1 LParen +RPAREN Default 0 0 Default +EOF Default 0 0 Default \ No newline at end of file diff --git a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs index 0f14cd3..d04c643 100644 --- a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs +++ b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs @@ -65,6 +65,11 @@ module ``tests_type_custom-comparison-0`` = [] let ``can execute`` () = TestUtils.runTest "tests/type/custom-comparison-0.visp" +[] +module ``tests_type_byrefs-0`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/type/byrefs-0.visp" + [] module ``tests_type_static-members-0`` = [] diff --git a/tests/Visp.ExecutionTests/snapshots/tests_type_byrefs-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_type_byrefs-0.can execute.verified.txt new file mode 100644 index 0000000..c335a3f --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_type_byrefs-0.can execute.verified.txt @@ -0,0 +1,8 @@ +Original sequence: 1 3 7 15 31 63 127 255 511 1023 +New sequence: 1 3 7 30 31 63 127 255 511 1023 +Now: 2023-12-26 +Now: 2023-12-26 +Now: 2023-12-27 +() + +ExitCode: 0 diff --git a/visp/tests/type/byrefs-0.visp b/visp/tests/type/byrefs-0.visp new file mode 100644 index 0000000..0e7703d --- /dev/null +++ b/visp/tests/type/byrefs-0.visp @@ -0,0 +1,54 @@ +;; 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: + +;; https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/byrefs +(open System) + +(type C1 () + (mut nums [| 1 3 7 15 31 63 127 255 511 1023 |]) + (override fn _.ToString () (.Join System.String #\space nums)) + + (member fn _.FindLargestSmallerThan (target) + (mut ctr (dec (+Length nums))) + + (while (&& (> ctr 0) (>= (.[ctr] nums) target)) + (up! ctr dec)) + + (if (> ctr 0) + (.[ctr] &nums) + (.[0] &nums) + ))) + +(fn C1Test () + (let c1 (C1)) + (printfn $"Original sequence: %O{c1}") + (let v (.FindLargestSmallerThan &c1 16)) + (set! v (* v 2)) + (printfn $"New sequence: %O{c1}")) + +(C1Test) + +(fn f_inref ([dt: inref]) + (printfn $"Now: {dt:``yyyy-MM-dd``}")) + +(fn f_byref ([dt: byref]) + (printfn $"Now: {dt:``yyyy-MM-dd``}") + (set! dt (.AddDays dt 1))) + +(fn UsingByrefs () + (let dt (new DateTime 2023 12 26)) + (f_inref &dt) + + (mut dt (new DateTime 2023 12 26)) + (f_byref &dt) + (f_inref &dt) + + ()) + +(UsingByrefs) + +()