|
| 1 | + |
| 2 | +// --- Scaffolding |
| 3 | + |
| 4 | +f: () = std::cout << "hello world!\n"; |
| 5 | + |
| 6 | +g_in : ( s: std::string) = std::cout << "Come in, (s)$\n"; |
| 7 | +g_inout: (inout s: std::string) = std::cout << "Come in awhile, but take some biscuits on your way out, (s)$!\n"; |
| 8 | +g_out : (out s: std::string) = s = "A Powerful Mage"; |
| 9 | +g_move : (move s: std::string) = std::cout << "I hear you've moving, (s)$?\n"; |
| 10 | + |
| 11 | +h_forward: (inout s: std::string) -> forward std::string = { std::cout << "Inout (s)$ ... "; return s; } |
| 12 | +h_out : ( s: std::string) -> std::string = { std::cout << "In (s)$ ... "; return "yohoho"; } |
| 13 | + |
| 14 | +f1: (a: std::function< (x:int) -> int >) -> int = a(1); |
| 15 | +f2: (a: * (x:int) -> int ) -> int = a(2); |
| 16 | +g : (x:int) -> int = x+42; |
| 17 | + |
| 18 | + |
| 19 | +// --- Tests for type aliases |
| 20 | + |
| 21 | +A_h_forward: type == (inout s: std::string) -> forward std::string; |
| 22 | + |
| 23 | + |
| 24 | +main: () = |
| 25 | +{ |
| 26 | + // --- Test basic/degenerate cases |
| 27 | + |
| 28 | + // Test std::function< void() > |
| 29 | + ff: std::function< () -> void > = f&; |
| 30 | + ff(); |
| 31 | + |
| 32 | + // Ordinary pointer to function, deduced (always worked) |
| 33 | + pf: * () -> void = f&; |
| 34 | + pf(); |
| 35 | + |
| 36 | + |
| 37 | + // --- Tests for parameters |
| 38 | + // Note: Not forward parameters which imply a template... |
| 39 | + // function type-ids are for single function signatures |
| 40 | + |
| 41 | + fg_in : std::function< ( s: std::string) -> void > = g_in&; |
| 42 | + fg_inout: std::function< (inout s: std::string) -> void > = g_inout&; |
| 43 | + fg_out : std::function< (out s: std::string) -> void > = g_out&; |
| 44 | + fg_move : std::function< (move s: std::string) -> void > = g_move&; |
| 45 | + pg_in : * ( s: std::string) -> void = g_in&; |
| 46 | + pg_inout: * (inout s: std::string) -> void = g_inout&; |
| 47 | + pg_out : * (out s: std::string) -> void = g_out&; |
| 48 | + pg_move : * (move s: std::string) -> void = g_move&; |
| 49 | + |
| 50 | + frodo: std::string = "Frodo"; |
| 51 | + sam : std::string = "Sam"; |
| 52 | + |
| 53 | + // Test in param |
| 54 | + fg_in(frodo); |
| 55 | + pg_in(sam); |
| 56 | + |
| 57 | + // Test inout |
| 58 | + fg_inout(frodo); |
| 59 | + pg_inout(sam); |
| 60 | + |
| 61 | + // Test out |
| 62 | + gandalf : std::string; |
| 63 | + galadriel: std::string; |
| 64 | + fg_out(out gandalf); |
| 65 | + std::cout << "fg_out initialized gandalf to: (gandalf)$\n"; |
| 66 | + pg_out(out galadriel); |
| 67 | + std::cout << "pg_out initialized galadriel to: (galadriel)$\n"; |
| 68 | + gandalf = "Gandalf"; |
| 69 | + galadriel = "Galadriel"; |
| 70 | + |
| 71 | + // Test move |
| 72 | + fg_move(frodo); // last use, so (move frodo) is not required |
| 73 | + pg_move(sam); // last use, so (move sam) is not required |
| 74 | + |
| 75 | + |
| 76 | + // --- Tests for single anonymous returns |
| 77 | + // Note: Not multiple named return values... function-type-ids |
| 78 | + // are for Cpp1-style (single anonymous, possibly void) returns |
| 79 | + |
| 80 | + fh_forward: std::function< (inout s: std::string) -> forward std::string > = h_forward&; |
| 81 | + fh_out : std::function< ( s: std::string) -> std::string > = h_out&; |
| 82 | + ph_forward: * (inout s: std::string) -> forward std::string = h_forward&; |
| 83 | + ph_out : * ( s: std::string) -> std::string = h_out&; |
| 84 | + |
| 85 | + ph_forward2: * A_h_forward = h_forward&; |
| 86 | + |
| 87 | + // Test forward return |
| 88 | + std::cout << "fh_forward returned: (fh_forward(gandalf))$\n"; |
| 89 | + std::cout << "ph_forward returned: (ph_forward(galadriel))$\n"; |
| 90 | + std::cout << "ph_forward2 returned: (ph_forward2(galadriel))$\n"; |
| 91 | + |
| 92 | + // Test out return |
| 93 | + std::cout << "fh_out returned: (fh_out(gandalf))$\n"; |
| 94 | + std::cout << "ph_out returned: (ph_out(galadriel))$\n"; |
| 95 | + |
| 96 | + |
| 97 | + // --- Tests for function parameters |
| 98 | + std::cout << "(f1(g&))$\n"; |
| 99 | + std::cout << "(f2(g&))$\n"; |
| 100 | + |
| 101 | + |
| 102 | +} |
0 commit comments