tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

159 lignes · 3347 octetsBrut · Historique
1// Attributes are checked where they are written (E0114), and a function
2// has a body unless it is `@extern` or a trait method (E0115).
3
4// Accepted.
5@extern c "ok_plain"
6fn plain :: x: Int -> Int
7
8@extern c "ok_options" blocking owned
9fn options :: x: Int -> Int / <ffi>
10
11@test
12@should_panic "boom"
13fn panics ::
14{
15 panic "boom"
16}
17
18@test native
19fn native_only :: {}
20
21@thread_safe
22@derive Eq
23@derive Show
24type Kind { Kind }
25
26@derivable size_of_constructor
27trait Size<a>
28{
29 fn size :: x: a -> Int
30}
31
32fn size_of_constructor :: c: Constructor<Int> -> Int
33{
34 1
35}
36
37// Unknown attributes, ABIs and options.
38@extrn c "typo" //~ ERROR E0114 unknown attribute `@extrn`
39
40fn typo :: //~ ERROR E0115 function `typo` has no body
41 x: Int
42 -> Int
43
44@extern rust "rusty" //~ ERROR E0114 unknown ABI `rust`
45
46fn rusty :: x: Int -> Int
47
48@extern c "slow" blockng //~ ERROR E0114 unknown `@extern` option `blockng`
49
50fn slow :: x: Int -> Int
51
52// Blocking pools (ADR 0005, Revision 2): `cpu` and `io` only.
53@extern c "on_cpu" (blocking cpu)
54fn on_cpu :: x: Int -> Int
55
56@extern c "on_io" (blocking io)
57fn on_io :: x: Int -> Int
58
59@extern c "on_gpu" (blocking gpu) //~ ERROR E0114 unknown blocking pool `gpu`
60
61fn on_gpu :: x: Int -> Int
62
63@extern c "owned_io" (owned io)
64//~^ ERROR E0114 the `@extern` option `owned` takes no argument
65fn owned_io ::
66 x: Int
67 -> Int
68
69// Malformed arguments.
70@extern c //~ ERROR E0114 `@extern` needs a symbol
71
72fn no_symbol :: x: Int -> Int
73
74@extern //~ ERROR E0114 `@extern` needs an ABI and a symbol
75
76fn nothing :: x: Int -> Int
77
78@extern c bare //~ ERROR E0114 the symbol of `@extern` is a non-empty string
79
80fn bare_symbol :: x: Int -> Int
81
82@test 1 //~ ERROR E0114 `@test` takes no argument, or `native`
83
84fn test_with_argument :: {}
85
86@test nativ //~ ERROR E0114 `@test` takes no argument, or `native`
87
88fn test_with_a_typo :: {}
89
90@test native native //~ ERROR E0114 `@test` takes no argument, or `native`
91
92fn test_native_twice :: {}
93
94@test
95@should_panic fragment //~ ERROR E0114 `@should_panic` takes at most one string
96
97fn bare_fragment :: {}
98
99@derive //~ ERROR E0114 `@derive` needs the traits to derive
100
101type Underived { Underived }
102
103@derivable f g
104//~^ ERROR E0114 `@derivable` takes the name of one derive function
105trait Twice<a> //~ ERROR E0412 no function `f` is in scope
106{
107 fn twice :: x: a -> Int
108}
109
110// Repeated, or on the wrong item.
111@test
112@test //~ ERROR E0114 `@test` is given twice
113
114fn twice_a_test :: {}
115
116@should_panic //~ ERROR E0114 `@should_panic` applies only to a `@test` function
117
118fn not_a_test :: {}
119
120@derive Eq //~ ERROR E0114 `@derive` does not apply to a function
121
122fn derived :: {}
123
124@extern c "on_a_type" //~ ERROR E0114 `@extern` does not apply to a type
125
126type Foreign
127
128@builtin
129//~^ ERROR E0114 `@builtin` applies only to a type without constructors in the standard library
130type Mine
131
132@intrinsic
133//~^ ERROR E0114 `@intrinsic` applies only to a function in the standard library
134fn compiled ::
135 -> Int
136{
137 1
138}
139
140trait Methods<a>
141{
142 @test //~ ERROR E0114 `@test` does not apply to a method
143
144 fn method :: x: a -> Int
145}
146
147// Bodies.
148fn forgotten :: x: Int -> Int //~ ERROR E0115 function `forgotten` has no body
149
150impl Size<Kind>
151{
152 fn size :: x: Kind -> Int //~ ERROR E0115 method `size` has no body
153}
154
155@extern c "both"
156fn both :: x: Int -> Int
157{ //~ ERROR E0115 `@extern` function `both` has a body
158 x
159}