From fcf81cb3148d108b69e4abf15267a722160a397e Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Wed, 6 Dec 2023 15:23:22 +0200 Subject: [PATCH] Use syntax-macros for builtin macros Additionally contains fixes to macro expansion which were discovered after the syntax-macros were in use. --- src/Visp.Compiler/CoreParser.fs | 2 + src/Visp.Compiler/Syntax/SynWriter.fs | 12 +- .../Transforms/BuiltinMacroExpander.fs | 3 - .../Transforms/SyntaxMacroExpander.fs | 92 ++++++- .../ParsingTests.generated.fs | 239 ++++++++++-------- ...iltin-macros_cond-0.can parse.verified.txt | 2 +- ...acros_and-example-0.can parse.verified.txt | 64 +++++ ...macros_cond-macro-0.can parse.verified.txt | 34 +++ ...macros_cond-macro-1.can parse.verified.txt | 50 ++++ ...macros_or-example-0.can parse.verified.txt | 126 +++++++++ ...os_struct-example-1.can parse.verified.txt | 2 +- ...cros_syntax-macro-1.can parse.verified.txt | 60 ----- .../ExecutionTests.generated.fs | 239 ++++++++++-------- ...ros_and-example-0.can execute.verified.txt | 10 + ...cros_cond-macro-0.can execute.verified.txt | 3 + ...cros_cond-macro-1.can execute.verified.txt | 5 + ...cros_or-example-0.can execute.verified.txt | 13 + ...os_syntax-macro-1.can execute.verified.txt | 7 - visp/lib/core-macros.visp | 39 +++ visp/tests/macros/and-example-0.visp | 23 ++ visp/tests/macros/cond-macro-0.visp | 23 ++ ...ip-cond-macro-0.visp => cond-macro-1.visp} | 21 +- visp/tests/macros/or-example-0.visp | 30 +++ visp/tests/macros/syntax-macro-1.visp | 26 -- visp/utils/test-generator.visp | 2 +- 25 files changed, 777 insertions(+), 350 deletions(-) create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_and-example-0.can parse.verified.txt create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-0.can parse.verified.txt create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-1.can parse.verified.txt create mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_or-example-0.can parse.verified.txt delete mode 100644 tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-1.can parse.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_and-example-0.can execute.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-0.can execute.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-1.can execute.verified.txt create mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_or-example-0.can execute.verified.txt delete mode 100644 tests/Visp.ExecutionTests/snapshots/tests_macros_syntax-macro-1.can execute.verified.txt create mode 100644 visp/tests/macros/and-example-0.visp create mode 100644 visp/tests/macros/cond-macro-0.visp rename visp/tests/macros/{skip-cond-macro-0.visp => cond-macro-1.visp} (54%) create mode 100644 visp/tests/macros/or-example-0.visp delete mode 100644 visp/tests/macros/syntax-macro-1.visp diff --git a/src/Visp.Compiler/CoreParser.fs b/src/Visp.Compiler/CoreParser.fs index 6483502..63d5e60 100644 --- a/src/Visp.Compiler/CoreParser.fs +++ b/src/Visp.Compiler/CoreParser.fs @@ -35,6 +35,7 @@ module CoreParser = fileWriter.Write(template.Trim()) fileWriter.WriteLine() let writer = Visp.Syntax.SynWriter.mkSynWriter fileWriter + let file = transformFile file Visp.Syntax.SynWriter.Write.writeParsedFile writer file fileWriter.WriteLine() @@ -58,6 +59,7 @@ let state = { Todo = () } let writer = Visp.Syntax.SynWriter.mkSynWriter fileWriter + let file = transformFile file Visp.Syntax.SynWriter.Write.writeParsedFile writer file fileWriter.WriteLine() diff --git a/src/Visp.Compiler/Syntax/SynWriter.fs b/src/Visp.Compiler/Syntax/SynWriter.fs index 5dde761..f6b2b13 100644 --- a/src/Visp.Compiler/Syntax/SynWriter.fs +++ b/src/Visp.Compiler/Syntax/SynWriter.fs @@ -1270,16 +1270,6 @@ module Write = string w "] |> HashMap.ofList" - - let private tfs = - [| Visp.Compiler.Transforms.SyntaxMacros.expand - Visp.Compiler.Transforms.QuasiquoteExpander.expand - Visp.Compiler.Transforms.BuiltinMacros.expand - Visp.Compiler.Transforms.Common.transformLambdaShortHands |] - - let expandExpr expr = - Visp.Compiler.Transforms.Helpers.runTransforms tfs expr - let writeParsedFile w (ParsedFile(fragments)) = let rec writeModuleDecls w (decls: SynModuleDecl list) = match decls with @@ -1303,7 +1293,7 @@ module Write = () | SynModuleDecl.ModuleAbbrev _ -> () | SynModuleDecl.Require _ -> () - | SynModuleDecl.Expr(ex, _) -> writeExpr w WriteState.Body (expandExpr ex) + | SynModuleDecl.Expr(ex, _) -> writeExpr w WriteState.Body ex | SynModuleDecl.Open(target, range) -> indent w lineof w range diff --git a/src/Visp.Compiler/Transforms/BuiltinMacroExpander.fs b/src/Visp.Compiler/Transforms/BuiltinMacroExpander.fs index a8c28b7..7919a3d 100644 --- a/src/Visp.Compiler/Transforms/BuiltinMacroExpander.fs +++ b/src/Visp.Compiler/Transforms/BuiltinMacroExpander.fs @@ -10,9 +10,6 @@ open Visp.Compiler.Transforms let rec expand (expr: SynExpr) = let inner expr = match expr with - | SynExpr.FunctionCall(Patterns.SymbolWith "and", args, range) -> handleAnd args range - | SynExpr.FunctionCall(Patterns.SymbolWith "or", args, range) -> handleOr args range - | SynExpr.FunctionCall(Patterns.SymbolWith "cond", args, range) -> handleCond args range | SynExpr.ThreadLast(items, range) -> SynExpr.ThreadLast(handleThreadables items, range) | _ -> expr diff --git a/src/Visp.Compiler/Transforms/SyntaxMacroExpander.fs b/src/Visp.Compiler/Transforms/SyntaxMacroExpander.fs index 0f5911a..9e6718f 100644 --- a/src/Visp.Compiler/Transforms/SyntaxMacroExpander.fs +++ b/src/Visp.Compiler/Transforms/SyntaxMacroExpander.fs @@ -103,11 +103,38 @@ let closeToken = | SynListKind.HashSet -> RBRACE | SynListKind.AttributeList -> RBRACKET +[] +type private TokenizeMode = + | Default + | Macro + +type private TokenizeArgs = + { mutable depth: int32 + mutable mode: TokenizeMode } + + member t.TryNest() = + if t.mode = TokenizeMode.Macro then + t.depth <- t.depth + 1 + + member t.StartMacro() = + t.mode <- TokenizeMode.Macro + t.TryNest() + + member t.TryUnnest() = + if t.mode = TokenizeMode.Macro then + t.depth <- t.depth - 1 + + if t.depth <= 0 then + t.mode <- TokenizeMode.Default + t.depth <- 0 + let private evaluatePatterns (body: SynMacroBody) (pats: Dictionary) (range: range) : SynExpr = + + let findPattern bod (pats: Dictionary) = match bod with | SynMacroBody.Symbol sym -> @@ -117,22 +144,30 @@ let private evaluatePatterns | _ -> None let rec tokenize - (f: SynMacroBody) (pats: Dictionary) (res: ResizeArray) + (args: TokenizeArgs) + (f: SynMacroBody) = + let bound_tokenize = tokenize pats res args + match findPattern f pats with | Some(pat) -> match pat with - | BoundPatternBody.Item(it) -> tokenize it pats res - | BoundPatternBody.List(lst) -> lst |> List.iter (fun ex -> tokenize ex pats res) + | BoundPatternBody.Item(it) -> bound_tokenize it + | BoundPatternBody.List(lst) -> lst |> List.iter bound_tokenize | None -> match f with | SynMacroBody.List(kind, lst, _) -> res.Add(openToken kind) - lst |> List.iter (fun ex -> tokenize ex pats res) + + args.TryNest() + + lst |> List.iter bound_tokenize + + args.TryUnnest() res.Add(closeToken kind) | SynMacroBody.Trivia(kind, _) -> @@ -158,12 +193,27 @@ let private evaluatePatterns () - | SynMacroBody.Symbol sym -> res.Add(LexHelpers.symbolOrKeyword sym.Text) + | SynMacroBody.Symbol sym -> + match args.mode with + | TokenizeMode.Macro -> res.Add(SYMBOL sym.Text) + | TokenizeMode.Default -> + let tok = LexHelpers.symbolOrKeyword sym.Text + + match tok with + | MACRO_NAME _ + | SYNTAX_MACRO -> args.StartMacro() + | _ -> () + + res.Add(tok) use pooled = PooledList.GetPooled() let res = pooled.Value - tokenize body pats res + let args = + { depth = 0 + mode = TokenizeMode.Default } + + tokenize pats res args body // Dummy lexbuffer let lexbuf = LexBuffer<_>.FromString "" @@ -198,6 +248,8 @@ let private evaluatePatterns try let result = raw_expr getTokens lexbuf + // printfn "result\n%A" result + result with :? ParseHelpers.SyntaxError as syn -> LexHelpers.outputSyntaxError syn @@ -218,6 +270,20 @@ let private expandSynMacro (SynMacro(_, cases, _) as macro) (SynMacroCall(_, arg result | None -> failwith "no matching pattern" +let private hasMacroCall (expr: SynExpr) = + let mutable res = false + + // TODO: Provide some iterators for doing this so we can stop earlY? + expr + |> Helpers.transform (function + | SynExpr.SyntaxMacroCall _ as ex -> + res <- true + ex + | it -> it) + |> ignore + + res + let expand (expr: SynExpr) = let collect = @@ -233,13 +299,23 @@ let expand (expr: SynExpr) = ) | it -> it + let mutable didExpand = true + let expandMacros = function | SynExpr.SyntaxMacroCall(SynMacroCall(name = name) as call) -> match macroTable.TryGetMacro(Syntax.textOfSymbol name) with - | Some(syn) -> expandSynMacro syn call + | Some(syn) -> + didExpand <- true + expandSynMacro syn call | None -> failwithf "macro: %A not found" name | it -> it // TODO: this should continue expanding until no more macro invocations are available - [ collect; expandMacros ] |> Helpers.runTransforms1 expr + + let mutable expr = expr |> Helpers.transform collect + + while hasMacroCall expr do + expr <- Helpers.transform expandMacros expr + + expr diff --git a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs index 15f6887..bf764ae 100644 --- a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs @@ -11,189 +11,189 @@ namespace ParsingTests open Xunit [] -module ``tests_atom_atom-0`` = +module ``tests_while_while-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/atom/atom-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/while/while-0.visp" [] -module ``tests_attributes_attributes-0`` = +module ``tests_dot_dot-shorthands`` = [] - let ``can parse`` () = TestUtils.runTest "tests/attributes/attributes-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp" [] -module ``tests_builtin-macros_cond-0`` = +module ``tests_type_type-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/type/type-0.visp" [] -module ``tests_builtin-macros_thread-first-0`` = +module ``tests_type_member-fn-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-first-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/type/member-fn-0.visp" [] -module ``tests_builtin-macros_thread-first-1`` = +module ``tests_type_type-alias-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-first-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/type/type-alias-0.visp" [] -module ``tests_builtin-macros_thread-last-0`` = +module ``tests_type_record-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-last-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/type/record-0.visp" [] -module ``tests_chars_char-0`` = +module ``tests_hashset_hashset-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/chars/char-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/hashset/hashset-0.visp" [] -module ``tests_chars_char-1`` = +module ``tests_parsing_match-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/chars/char-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/match-0.visp" [] -module ``tests_dot_dot-shorthands`` = +module ``tests_parsing_tuple-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/tuple-0.visp" [] -module ``tests_examples_example-0`` = +module ``tests_parsing_strings-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/strings-0.visp" [] -module ``tests_examples_example-1`` = +module ``tests_parsing_lambda-shorthand-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/lambda-shorthand-0.visp" [] -module ``tests_examples_example-10`` = +module ``tests_parsing_props`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-10.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/props.visp" [] -module ``tests_examples_example-11`` = +module ``tests_parsing_call-tuple-args-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-11.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/call-tuple-args-0.visp" [] -module ``tests_examples_example-12`` = +module ``tests_parsing_let-values`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-12.visp" + let ``can parse`` () = TestUtils.runTest "tests/parsing/let-values.visp" [] -module ``tests_examples_example-13`` = +module ``tests_atom_atom-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-13.visp" + let ``can parse`` () = TestUtils.runTest "tests/atom/atom-0.visp" [] -module ``tests_examples_example-14`` = +module ``tests_vector_vector-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-14.visp" + let ``can parse`` () = TestUtils.runTest "tests/vector/vector-0.visp" [] -module ``tests_examples_example-15`` = +module ``tests_numbers_int-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-15.visp" + let ``can parse`` () = TestUtils.runTest "tests/numbers/int-0.visp" [] -module ``tests_examples_example-16`` = +module ``tests_chars_char-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-16.visp" + let ``can parse`` () = TestUtils.runTest "tests/chars/char-1.visp" [] -module ``tests_examples_example-17`` = +module ``tests_chars_char-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-17.visp" + let ``can parse`` () = TestUtils.runTest "tests/chars/char-0.visp" [] -module ``tests_examples_example-2`` = +module ``tests_hashmap_hashmap-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-2.visp" + let ``can parse`` () = TestUtils.runTest "tests/hashmap/hashmap-0.visp" [] -module ``tests_examples_example-3`` = +module ``tests_for-in_for-in-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-3.visp" + let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-0.visp" [] -module ``tests_examples_example-4`` = +module ``tests_for-in_for-in-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-4.visp" + let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-1.visp" [] -module ``tests_examples_example-5`` = +module ``tests_for-in_for-in-2`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-5.visp" + let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-2.visp" [] -module ``tests_examples_example-6`` = +module ``tests_for-in_for-in-4`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-6.visp" + let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-4.visp" [] -module ``tests_examples_example-7`` = +module ``tests_for-in_for-in-3`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-7.visp" + let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-3.visp" [] -module ``tests_examples_example-8`` = +module ``tests_attributes_attributes-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-8.visp" + let ``can parse`` () = TestUtils.runTest "tests/attributes/attributes-0.visp" [] -module ``tests_examples_example-9`` = +module ``tests_if_if-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/example-9.visp" + let ``can parse`` () = TestUtils.runTest "tests/if/if-0.visp" [] -module ``tests_examples_variables-0`` = +module ``tests_quotation_quote-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/examples/variables-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/quotation/quote-0.visp" [] -module ``tests_for-in_for-in-0`` = +module ``tests_builtin-macros_thread-first-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-first-1.visp" [] -module ``tests_for-in_for-in-1`` = +module ``tests_builtin-macros_thread-first-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-first-0.visp" [] -module ``tests_for-in_for-in-2`` = +module ``tests_builtin-macros_thread-last-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-2.visp" + let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/thread-last-0.visp" [] -module ``tests_for-in_for-in-3`` = +module ``tests_builtin-macros_cond-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-3.visp" + let ``can parse`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" [] -module ``tests_for-in_for-in-4`` = +module ``tests_macros_struct-example-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/for-in/for-in-4.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" [] -module ``tests_hashmap_hashmap-0`` = +module ``tests_macros_syntax-macro-2`` = [] - let ``can parse`` () = TestUtils.runTest "tests/hashmap/hashmap-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/syntax-macro-2.visp" [] -module ``tests_hashset_hashset-0`` = +module ``tests_macros_syntax-macro-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/hashset/hashset-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/syntax-macro-0.visp" [] -module ``tests_if_if-0`` = +module ``tests_macros_cond-macro-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/if/if-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/cond-macro-1.visp" [] -module ``tests_macros_struct-example-1`` = +module ``tests_macros_cond-macro-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/cond-macro-0.visp" [] module ``tests_macros_struct-macro-0`` = @@ -201,97 +201,112 @@ module ``tests_macros_struct-macro-0`` = let ``can parse`` () = TestUtils.runTest "tests/macros/struct-macro-0.visp" [] -module ``tests_macros_syntax-macro-0`` = +module ``tests_macros_and-example-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/macros/syntax-macro-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/and-example-0.visp" [] -module ``tests_macros_syntax-macro-1`` = +module ``tests_macros_while-match-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/macros/syntax-macro-1.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/while-match-0.visp" [] -module ``tests_macros_syntax-macro-2`` = +module ``tests_macros_or-example-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/macros/syntax-macro-2.visp" + let ``can parse`` () = TestUtils.runTest "tests/macros/or-example-0.visp" [] -module ``tests_macros_while-match-0`` = +module ``tests_examples_example-4`` = [] - let ``can parse`` () = TestUtils.runTest "tests/macros/while-match-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-4.visp" [] -module ``tests_numbers_int-0`` = +module ``tests_examples_example-11`` = [] - let ``can parse`` () = TestUtils.runTest "tests/numbers/int-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-11.visp" [] -module ``tests_parsing_call-tuple-args-0`` = +module ``tests_examples_example-3`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/call-tuple-args-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-3.visp" [] -module ``tests_parsing_lambda-shorthand-0`` = +module ``tests_examples_example-9`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/lambda-shorthand-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-9.visp" [] -module ``tests_parsing_let-values`` = +module ``tests_examples_example-10`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/let-values.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-10.visp" [] -module ``tests_parsing_match-0`` = +module ``tests_examples_example-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/match-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-0.visp" [] -module ``tests_parsing_props`` = +module ``tests_examples_example-15`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/props.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-15.visp" [] -module ``tests_parsing_strings-0`` = +module ``tests_examples_example-16`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/strings-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-16.visp" [] -module ``tests_parsing_tuple-0`` = +module ``tests_examples_example-1`` = [] - let ``can parse`` () = TestUtils.runTest "tests/parsing/tuple-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-1.visp" [] -module ``tests_quotation_quote-0`` = +module ``tests_examples_variables-0`` = [] - let ``can parse`` () = TestUtils.runTest "tests/quotation/quote-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/variables-0.visp" [] -module ``tests_type_member-fn-0`` = +module ``tests_examples_example-7`` = [] - let ``can parse`` () = TestUtils.runTest "tests/type/member-fn-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-7.visp" [] -module ``tests_type_record-0`` = +module ``tests_examples_example-2`` = [] - let ``can parse`` () = TestUtils.runTest "tests/type/record-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-2.visp" [] -module ``tests_type_type-0`` = +module ``tests_examples_example-13`` = [] - let ``can parse`` () = TestUtils.runTest "tests/type/type-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-13.visp" [] -module ``tests_type_type-alias-0`` = +module ``tests_examples_example-14`` = [] - let ``can parse`` () = TestUtils.runTest "tests/type/type-alias-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-14.visp" [] -module ``tests_vector_vector-0`` = +module ``tests_examples_example-6`` = [] - let ``can parse`` () = TestUtils.runTest "tests/vector/vector-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-6.visp" [] -module ``tests_while_while-0`` = +module ``tests_examples_example-8`` = [] - let ``can parse`` () = TestUtils.runTest "tests/while/while-0.visp" + let ``can parse`` () = TestUtils.runTest "tests/examples/example-8.visp" + +[] +module ``tests_examples_example-12`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/examples/example-12.visp" + +[] +module ``tests_examples_example-17`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/examples/example-17.visp" + +[] +module ``tests_examples_example-5`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/examples/example-5.visp" diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_builtin-macros_cond-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_builtin-macros_cond-0.can parse.verified.txt index f10e0c5..0fc0010 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_builtin-macros_cond-0.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_builtin-macros_cond-0.can parse.verified.txt @@ -26,7 +26,7 @@ let visp_result_todo = 3 else // line 8 @"cond-0.visp" - failwith ("Unbalanced cond") + failwith ("unreachable cond") // line 8 @"cond-0.visp" printfn ("%A") (visp_result_todo) diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_and-example-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_and-example-0.can parse.verified.txt new file mode 100644 index 0000000..57715ce --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_and-example-0.can parse.verified.txt @@ -0,0 +1,64 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"and-example-0.visp" +let ``macro_my-and`` = "__MACRO_INIT__" +// line 17 @"and-example-0.visp" +printfn ("my-and %A") (true) +// line 18 @"and-example-0.visp" +printfn ("my-and %A") (false) +// line 19 @"and-example-0.visp" +printfn ("my-and %A") (true) +// line 20 @"and-example-0.visp" +printfn ("my-and %A") ( + if CoreMethods.isTruthy( + true) + then + false + else + false) +// line 21 @"and-example-0.visp" +printfn ("my-and %A") ( + if CoreMethods.isTruthy( + true) + then + true + else + false) +// line 22 @"and-example-0.visp" +printfn ("my-and %A") ( + if CoreMethods.isTruthy( + true) + then + // line 22 @"and-example-0.visp" + if CoreMethods.isTruthy( + true) + then + false + else + false + else + false) +// line 23 @"and-example-0.visp" +let visp_result_todo = + // line 23 @"and-example-0.visp" + printfn ("my-and %A") ( + if CoreMethods.isTruthy( + true) + then + // line 23 @"and-example-0.visp" + if CoreMethods.isTruthy( + true) + then + true + else + false + else + false) +// line 23 @"and-example-0.visp" +printfn ("%A") (visp_result_todo) + diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-0.can parse.verified.txt new file mode 100644 index 0000000..8a59e33 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-0.can parse.verified.txt @@ -0,0 +1,34 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"cond-macro-0.visp" +let ``macro_my-cond`` = "__MACRO_INIT__" +// line 17 @"cond-macro-0.visp" +let visp_result_todo = + // line 17 @"cond-macro-0.visp" + if CoreMethods.isTruthy( + CoreMethods.``gt``(0, 0)) + then + 1 + else + // line 17 @"cond-macro-0.visp" + if CoreMethods.isTruthy( + CoreMethods.``lt``(0, 0)) + then + 2 + else + // line 17 @"cond-macro-0.visp" + if CoreMethods.isTruthy( + Value.keyword(":else")) + then + 3 + else + // line 17 @"cond-macro-0.visp" + failwith ("unreachable cond") +// line 17 @"cond-macro-0.visp" +printfn ("%A") (visp_result_todo) + diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-1.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-1.can parse.verified.txt new file mode 100644 index 0000000..eb80262 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_cond-macro-1.can parse.verified.txt @@ -0,0 +1,50 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"cond-macro-1.visp" +let ``macro_my-cond_`` = "__MACRO_INIT__" +// line 17 @"cond-macro-1.visp" +let visp_result_todo = + // line 17 @"cond-macro-1.visp" + if CoreMethods.isTruthy( + CoreMethods.``gt``(0, 1)) + then + // line 17 @"cond-macro-1.visp" + + // line 17 @"cond-macro-1.visp" + printfn ("body here1") + // line 17 @"cond-macro-1.visp" + printfn ("body here2") + () + else + // line 17 @"cond-macro-1.visp" + if CoreMethods.isTruthy( + CoreMethods.``lt``(1, 0)) + then + // line 17 @"cond-macro-1.visp" + + // line 17 @"cond-macro-1.visp" + printfn ("here1") + // line 17 @"cond-macro-1.visp" + printfn ("here2") + else + // line 17 @"cond-macro-1.visp" + if CoreMethods.isTruthy( + Value.keyword(":else")) + then + // line 17 @"cond-macro-1.visp" + + // line 17 @"cond-macro-1.visp" + printfn ("default1") + // line 17 @"cond-macro-1.visp" + printfn ("default2") + else + // line 17 @"cond-macro-1.visp" + failwith ("unbalanced cond") +// line 17 @"cond-macro-1.visp" +printfn ("%A") (visp_result_todo) + diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_or-example-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_or-example-0.can parse.verified.txt new file mode 100644 index 0000000..d14816c --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_or-example-0.can parse.verified.txt @@ -0,0 +1,126 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"or-example-0.visp" +let ``macro_my-or`` = "__MACRO_INIT__" +// line 20 @"or-example-0.visp" +printfn ("my-or %A") (false) +// line 21 @"or-example-0.visp" +printfn ("my-or %A") (false) +// line 22 @"or-example-0.visp" +printfn ("my-or %A") (true) +// line 23 @"or-example-0.visp" +printfn ("my-or %A") (( + // line 23 @"or-example-0.visp" + let orTemp = true + // line 23 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + false)) +// line 24 @"or-example-0.visp" +printfn ("my-or %A") (( + // line 24 @"or-example-0.visp" + let orTemp = true + // line 24 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + true)) +// line 25 @"or-example-0.visp" +printfn ("my-or %A") (( + // line 25 @"or-example-0.visp" + let orTemp = true + // line 25 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + // line 25 @"or-example-0.visp" + ( + // line 25 @"or-example-0.visp" + let orTemp = true + // line 25 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + false))) +// line 26 @"or-example-0.visp" +printfn ("my-or %A") (( + // line 26 @"or-example-0.visp" + let orTemp = true + // line 26 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + // line 26 @"or-example-0.visp" + ( + // line 26 @"or-example-0.visp" + let orTemp = true + // line 26 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + true))) +// line 28 @"or-example-0.visp" +printfn ("my-or %A") (Value.bool (false)) +// line 29 @"or-example-0.visp" +printfn ("my-or %A") (( + // line 29 @"or-example-0.visp" + let orTemp = + // line 29 @"or-example-0.visp" + Value.bool (false) + // line 29 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + // line 29 @"or-example-0.visp" + Value.string ("this works, yay"))) +// line 30 @"or-example-0.visp" +let visp_result_todo = + // line 30 @"or-example-0.visp" + printfn ("my-or %A") (( + // line 30 @"or-example-0.visp" + let orTemp = + // line 30 @"or-example-0.visp" + Value.bool (false) + // line 30 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + // line 30 @"or-example-0.visp" + ( + // line 30 @"or-example-0.visp" + let orTemp = + // line 30 @"or-example-0.visp" + Value.bool (false) + // line 30 @"or-example-0.visp" + if CoreMethods.isTruthy( + orTemp) + then + orTemp + else + // line 30 @"or-example-0.visp" + Value.string ("this works, yay")))) +// line 30 @"or-example-0.visp" +printfn ("%A") (visp_result_todo) + diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt index 133600c..407b808 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt @@ -93,7 +93,7 @@ type SourceDestMap (dest: int64, src: int64, len: int64) = src else // line 29 @"struct-example-1.visp" - failwith ("Unbalanced cond") + failwith ("unreachable cond") // line 29 @"struct-example-1.visp" override t.ToString () = diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-1.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-1.can parse.verified.txt deleted file mode 100644 index 055ef28..0000000 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-1.can parse.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -// This file is auto-generated - -#nowarn "0020" // unused results from functions - -open Visp.Runtime.Library - -let state = { Todo = () } -// line 9 @"syntax-macro-1.visp" -#nowarn "0026" -// line 11 @"syntax-macro-1.visp" -let ``macro_my-or`` = "__MACRO_INIT__" -// line 23 @"syntax-macro-1.visp" -printfn ("%A") (true) -// line 24 @"syntax-macro-1.visp" -printfn ("%A") (Value.bool (false)) -// line 25 @"syntax-macro-1.visp" -printfn ("%A") (( - // line 25 @"syntax-macro-1.visp" - let ortemp = - // line 25 @"syntax-macro-1.visp" - Value.bool (false) - // line 25 @"syntax-macro-1.visp" - if CoreMethods.isTruthy( - ortemp) - then - ortemp - else - // line 25 @"syntax-macro-1.visp" - Value.string ("this works, yay"))) -// line 26 @"syntax-macro-1.visp" -let visp_result_todo = - // line 26 @"syntax-macro-1.visp" - printfn ("%A") (( - // line 26 @"syntax-macro-1.visp" - let ortemp = - // line 26 @"syntax-macro-1.visp" - Value.bool (false) - // line 26 @"syntax-macro-1.visp" - if CoreMethods.isTruthy( - ortemp) - then - ortemp - else - // line 26 @"syntax-macro-1.visp" - ( - // line 26 @"syntax-macro-1.visp" - let ortemp = - // line 26 @"syntax-macro-1.visp" - Value.bool (false) - // line 26 @"syntax-macro-1.visp" - if CoreMethods.isTruthy( - ortemp) - then - ortemp - else - // line 26 @"syntax-macro-1.visp" - Value.string ("this works, yay")))) -// line 26 @"syntax-macro-1.visp" -printfn ("%A") (visp_result_todo) - diff --git a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs index 49ed54f..42a0dc3 100644 --- a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs +++ b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs @@ -11,189 +11,189 @@ namespace ExecutionTests open Xunit [] -module ``tests_atom_atom-0`` = +module ``tests_while_while-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/atom/atom-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/while/while-0.visp" [] -module ``tests_attributes_attributes-0`` = +module ``tests_dot_dot-shorthands`` = [] - let ``can execute`` () = TestUtils.runTest "tests/attributes/attributes-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp" [] -module ``tests_builtin-macros_cond-0`` = +module ``tests_type_type-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/type/type-0.visp" [] -module ``tests_builtin-macros_thread-first-0`` = +module ``tests_type_member-fn-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-first-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/type/member-fn-0.visp" [] -module ``tests_builtin-macros_thread-first-1`` = +module ``tests_type_type-alias-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-first-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/type/type-alias-0.visp" [] -module ``tests_builtin-macros_thread-last-0`` = +module ``tests_type_record-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-last-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/type/record-0.visp" [] -module ``tests_chars_char-0`` = +module ``tests_hashset_hashset-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/chars/char-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/hashset/hashset-0.visp" [] -module ``tests_chars_char-1`` = +module ``tests_parsing_match-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/chars/char-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/match-0.visp" [] -module ``tests_dot_dot-shorthands`` = +module ``tests_parsing_tuple-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/tuple-0.visp" [] -module ``tests_examples_example-0`` = +module ``tests_parsing_strings-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/strings-0.visp" [] -module ``tests_examples_example-1`` = +module ``tests_parsing_lambda-shorthand-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/lambda-shorthand-0.visp" [] -module ``tests_examples_example-10`` = +module ``tests_parsing_props`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-10.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/props.visp" [] -module ``tests_examples_example-11`` = +module ``tests_parsing_call-tuple-args-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-11.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/call-tuple-args-0.visp" [] -module ``tests_examples_example-12`` = +module ``tests_parsing_let-values`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-12.visp" + let ``can execute`` () = TestUtils.runTest "tests/parsing/let-values.visp" [] -module ``tests_examples_example-13`` = +module ``tests_atom_atom-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-13.visp" + let ``can execute`` () = TestUtils.runTest "tests/atom/atom-0.visp" [] -module ``tests_examples_example-14`` = +module ``tests_vector_vector-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-14.visp" + let ``can execute`` () = TestUtils.runTest "tests/vector/vector-0.visp" [] -module ``tests_examples_example-15`` = +module ``tests_numbers_int-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-15.visp" + let ``can execute`` () = TestUtils.runTest "tests/numbers/int-0.visp" [] -module ``tests_examples_example-16`` = +module ``tests_chars_char-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-16.visp" + let ``can execute`` () = TestUtils.runTest "tests/chars/char-1.visp" [] -module ``tests_examples_example-17`` = +module ``tests_chars_char-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-17.visp" + let ``can execute`` () = TestUtils.runTest "tests/chars/char-0.visp" [] -module ``tests_examples_example-2`` = +module ``tests_hashmap_hashmap-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-2.visp" + let ``can execute`` () = TestUtils.runTest "tests/hashmap/hashmap-0.visp" [] -module ``tests_examples_example-3`` = +module ``tests_for-in_for-in-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-3.visp" + let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-0.visp" [] -module ``tests_examples_example-4`` = +module ``tests_for-in_for-in-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-4.visp" + let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-1.visp" [] -module ``tests_examples_example-5`` = +module ``tests_for-in_for-in-2`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-5.visp" + let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-2.visp" [] -module ``tests_examples_example-6`` = +module ``tests_for-in_for-in-4`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-6.visp" + let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-4.visp" [] -module ``tests_examples_example-7`` = +module ``tests_for-in_for-in-3`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-7.visp" + let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-3.visp" [] -module ``tests_examples_example-8`` = +module ``tests_attributes_attributes-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-8.visp" + let ``can execute`` () = TestUtils.runTest "tests/attributes/attributes-0.visp" [] -module ``tests_examples_example-9`` = +module ``tests_if_if-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/example-9.visp" + let ``can execute`` () = TestUtils.runTest "tests/if/if-0.visp" [] -module ``tests_examples_variables-0`` = +module ``tests_quotation_quote-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/examples/variables-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/quotation/quote-0.visp" [] -module ``tests_for-in_for-in-0`` = +module ``tests_builtin-macros_thread-first-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-first-1.visp" [] -module ``tests_for-in_for-in-1`` = +module ``tests_builtin-macros_thread-first-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-first-0.visp" [] -module ``tests_for-in_for-in-2`` = +module ``tests_builtin-macros_thread-last-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-2.visp" + let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/thread-last-0.visp" [] -module ``tests_for-in_for-in-3`` = +module ``tests_builtin-macros_cond-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-3.visp" + let ``can execute`` () = TestUtils.runTest "tests/builtin-macros/cond-0.visp" [] -module ``tests_for-in_for-in-4`` = +module ``tests_macros_struct-example-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/for-in/for-in-4.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" [] -module ``tests_hashmap_hashmap-0`` = +module ``tests_macros_syntax-macro-2`` = [] - let ``can execute`` () = TestUtils.runTest "tests/hashmap/hashmap-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/syntax-macro-2.visp" [] -module ``tests_hashset_hashset-0`` = +module ``tests_macros_syntax-macro-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/hashset/hashset-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/syntax-macro-0.visp" [] -module ``tests_if_if-0`` = +module ``tests_macros_cond-macro-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/if/if-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/cond-macro-1.visp" [] -module ``tests_macros_struct-example-1`` = +module ``tests_macros_cond-macro-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/cond-macro-0.visp" [] module ``tests_macros_struct-macro-0`` = @@ -201,97 +201,112 @@ module ``tests_macros_struct-macro-0`` = let ``can execute`` () = TestUtils.runTest "tests/macros/struct-macro-0.visp" [] -module ``tests_macros_syntax-macro-0`` = +module ``tests_macros_and-example-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/macros/syntax-macro-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/and-example-0.visp" [] -module ``tests_macros_syntax-macro-1`` = +module ``tests_macros_while-match-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/macros/syntax-macro-1.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/while-match-0.visp" [] -module ``tests_macros_syntax-macro-2`` = +module ``tests_macros_or-example-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/macros/syntax-macro-2.visp" + let ``can execute`` () = TestUtils.runTest "tests/macros/or-example-0.visp" [] -module ``tests_macros_while-match-0`` = +module ``tests_examples_example-4`` = [] - let ``can execute`` () = TestUtils.runTest "tests/macros/while-match-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-4.visp" [] -module ``tests_numbers_int-0`` = +module ``tests_examples_example-11`` = [] - let ``can execute`` () = TestUtils.runTest "tests/numbers/int-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-11.visp" [] -module ``tests_parsing_call-tuple-args-0`` = +module ``tests_examples_example-3`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/call-tuple-args-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-3.visp" [] -module ``tests_parsing_lambda-shorthand-0`` = +module ``tests_examples_example-9`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/lambda-shorthand-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-9.visp" [] -module ``tests_parsing_let-values`` = +module ``tests_examples_example-10`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/let-values.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-10.visp" [] -module ``tests_parsing_match-0`` = +module ``tests_examples_example-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/match-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-0.visp" [] -module ``tests_parsing_props`` = +module ``tests_examples_example-15`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/props.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-15.visp" [] -module ``tests_parsing_strings-0`` = +module ``tests_examples_example-16`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/strings-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-16.visp" [] -module ``tests_parsing_tuple-0`` = +module ``tests_examples_example-1`` = [] - let ``can execute`` () = TestUtils.runTest "tests/parsing/tuple-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-1.visp" [] -module ``tests_quotation_quote-0`` = +module ``tests_examples_variables-0`` = [] - let ``can execute`` () = TestUtils.runTest "tests/quotation/quote-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/variables-0.visp" [] -module ``tests_type_member-fn-0`` = +module ``tests_examples_example-7`` = [] - let ``can execute`` () = TestUtils.runTest "tests/type/member-fn-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-7.visp" [] -module ``tests_type_record-0`` = +module ``tests_examples_example-2`` = [] - let ``can execute`` () = TestUtils.runTest "tests/type/record-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-2.visp" [] -module ``tests_type_type-0`` = +module ``tests_examples_example-13`` = [] - let ``can execute`` () = TestUtils.runTest "tests/type/type-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-13.visp" [] -module ``tests_type_type-alias-0`` = +module ``tests_examples_example-14`` = [] - let ``can execute`` () = TestUtils.runTest "tests/type/type-alias-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-14.visp" [] -module ``tests_vector_vector-0`` = +module ``tests_examples_example-6`` = [] - let ``can execute`` () = TestUtils.runTest "tests/vector/vector-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-6.visp" [] -module ``tests_while_while-0`` = +module ``tests_examples_example-8`` = [] - let ``can execute`` () = TestUtils.runTest "tests/while/while-0.visp" + let ``can execute`` () = TestUtils.runTest "tests/examples/example-8.visp" + +[] +module ``tests_examples_example-12`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/examples/example-12.visp" + +[] +module ``tests_examples_example-17`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/examples/example-17.visp" + +[] +module ``tests_examples_example-5`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/examples/example-5.visp" diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_and-example-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_and-example-0.can execute.verified.txt new file mode 100644 index 0000000..d1b2494 --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_and-example-0.can execute.verified.txt @@ -0,0 +1,10 @@ +my-and true +my-and false +my-and true +my-and false +my-and true +my-and false +my-and true +() + +ExitCode: 0 diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-0.can execute.verified.txt new file mode 100644 index 0000000..6f7468a --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-0.can execute.verified.txt @@ -0,0 +1,3 @@ +3 + +ExitCode: 0 diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-1.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-1.can execute.verified.txt new file mode 100644 index 0000000..e8f9279 --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_cond-macro-1.can execute.verified.txt @@ -0,0 +1,5 @@ +default1 +default2 +() + +ExitCode: 0 diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_or-example-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_or-example-0.can execute.verified.txt new file mode 100644 index 0000000..5494307 --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_or-example-0.can execute.verified.txt @@ -0,0 +1,13 @@ +my-or false +my-or false +my-or true +my-or true +my-or true +my-or true +my-or true +my-or Bool false +my-or String "this works, yay" +my-or String "this works, yay" +() + +ExitCode: 0 diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_syntax-macro-1.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_syntax-macro-1.can execute.verified.txt deleted file mode 100644 index c12d02f..0000000 --- a/tests/Visp.ExecutionTests/snapshots/tests_macros_syntax-macro-1.can execute.verified.txt +++ /dev/null @@ -1,7 +0,0 @@ -true -Bool false -String "this works, yay" -String "this works, yay" -() - -ExitCode: 0 diff --git a/visp/lib/core-macros.visp b/visp/lib/core-macros.visp index 628353e..f21b575 100644 --- a/visp/lib/core-macros.visp +++ b/visp/lib/core-macros.visp @@ -7,6 +7,44 @@ ;; core-macros +(syntax-macro and + [(_) true] + [(_ one) one] + [(_ cond exprs ...) + (if cond + (and exprs ...) + false) + ]) + +(syntax-macro or + [(_) false] + [(_ one) one] + [(_ cond exprs ...) + (do + (let orTemp cond) + (if orTemp + orTemp + (or exprs ...) + )) + ]) + +(syntax-macro cond + [(_) (failwith "unreachable cond")] + [(_ one) one] + [(_ var body exprs ...) + (if var + body + (cond exprs ...)) + ]) + +(syntax-macro cond_ + [(_) (failwith "unbalanced cond")] + [(_ (test body ...) rest ...) + (if test + (begin body ...) + (cond_ rest ...)) + ]) + (syntax-macro match-fn [(_ (c ...) rest ...) (fn (arg) @@ -44,3 +82,4 @@ body ... ) ]) + diff --git a/visp/tests/macros/and-example-0.visp b/visp/tests/macros/and-example-0.visp new file mode 100644 index 0000000..52e96cc --- /dev/null +++ b/visp/tests/macros/and-example-0.visp @@ -0,0 +1,23 @@ +;; 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: + +(syntax-macro my-and + [(_) true] + [(_ one) one] + [(_ cond exprs ...) + (if cond + (my-and exprs ...) + false) + ]) + +(printfn "my-and %A" (my-and)) +(printfn "my-and %A" (my-and false)) +(printfn "my-and %A" (my-and true)) +(printfn "my-and %A" (my-and true false)) +(printfn "my-and %A" (my-and true true)) +(printfn "my-and %A" (my-and true true false)) +(printfn "my-and %A" (my-and true true true)) diff --git a/visp/tests/macros/cond-macro-0.visp b/visp/tests/macros/cond-macro-0.visp new file mode 100644 index 0000000..8fa3327 --- /dev/null +++ b/visp/tests/macros/cond-macro-0.visp @@ -0,0 +1,23 @@ +;; 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: + +(syntax-macro my-cond + [(_) (failwith "unreachable cond")] + [(_ one) one] + [(_ var body exprs ...) + (if var + body + (my-cond exprs ...)) + ]) + +(my-cond + (> 0 0) + 1 + (< 0 0) + 2 + :else + 3) diff --git a/visp/tests/macros/skip-cond-macro-0.visp b/visp/tests/macros/cond-macro-1.visp similarity index 54% rename from visp/tests/macros/skip-cond-macro-0.visp rename to visp/tests/macros/cond-macro-1.visp index 3bec8ed..f08ef82 100644 --- a/visp/tests/macros/skip-cond-macro-0.visp +++ b/visp/tests/macros/cond-macro-1.visp @@ -5,21 +5,26 @@ ;; for basic syntax highlighting ;; vim: set syntax=clojure: -(syntax-macro cond_ +(syntax-macro my-cond_ [(_) (failwith "unbalanced cond")] - [(_ (test body ...)) - ] [(_ (test body ...) rest ...) - + (if test + (begin body ...) + (my-cond_ rest ...)) ] ) -(cond_ +(my-cond_ [(> 0 1) - (printfn "body here") + (printfn "body here1") + (printfn "body here2") ()] [(< 1 0) - (printfn "here") + (printfn "here1") + (printfn "here2") ] - [_ (printfn "default")] + [:else + (printfn "default1") + (printfn "default2") + ] ) diff --git a/visp/tests/macros/or-example-0.visp b/visp/tests/macros/or-example-0.visp new file mode 100644 index 0000000..2324654 --- /dev/null +++ b/visp/tests/macros/or-example-0.visp @@ -0,0 +1,30 @@ +;; 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: + +(syntax-macro my-or + [(_) false] + [(_ one) one] + [(_ test exprs ...) + (do + (let orTemp test) + (if orTemp + orTemp + (my-or exprs ...) + )) + ]) + +(printfn "my-or %A" (my-or)) +(printfn "my-or %A" (my-or false)) +(printfn "my-or %A" (my-or true)) +(printfn "my-or %A" (my-or true false)) +(printfn "my-or %A" (my-or true true)) +(printfn "my-or %A" (my-or true true false)) +(printfn "my-or %A" (my-or true true true)) + +(printfn "my-or %A" (my-or (Value.bool false))) +(printfn "my-or %A" (my-or (Value.bool false) (Value.string "this works, yay"))) +(printfn "my-or %A" (my-or (Value.bool false) (Value.bool false) (Value.string "this works, yay"))) diff --git a/visp/tests/macros/syntax-macro-1.visp b/visp/tests/macros/syntax-macro-1.visp deleted file mode 100644 index d014ef6..0000000 --- a/visp/tests/macros/syntax-macro-1.visp +++ /dev/null @@ -1,26 +0,0 @@ -;; 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: - -;; this rule will never be matched -#nowarn "0026" - -(syntax-macro my-or - [(_) true] - [(_ exp) exp] - [(_ exp rest ...) - (do - (let ortemp exp) - (if ortemp - ortemp - (my-or rest ...) - )) - ]) - -(printfn "%A" (my-or)) -(printfn "%A" (my-or (Value.bool false))) -(printfn "%A" (my-or (Value.bool false) (Value.string "this works, yay"))) -(printfn "%A" (my-or (Value.bool false) (Value.bool false) (Value.string "this works, yay"))) diff --git a/visp/utils/test-generator.visp b/visp/utils/test-generator.visp index ac25175..1098909 100644 --- a/visp/utils/test-generator.visp +++ b/visp/utils/test-generator.visp @@ -115,7 +115,7 @@ let ``%s %s`` () = TestUtils.runTest "%s" (let tests (->> files (Seq.filter #(not (IsIgnoredFile %1))) (Seq.map (fn [file] - (GetTestCategory parent file) + ;; (GetTestCategory parent file) (let simplified (->> (.Replace file parent "") #(.TrimStart %1 #\/)