aboutsummaryrefslogtreecommitdiffstats
path: root/tests/semantics.bad
blob: b816a62f6e9ee917f2a533fd478f051dc9e8d037 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
struct vec {
    x: f64
    y: f64
}

fun foo(): nil {
    struct vec {
        z: f64
    }
    let a: vec
    set a.z = 1.0
}

; struct vec {
;     x: f64 = 2.0
;     y: f64 = 1.0
;     bruh: {
;         id:  int = 10
;         msg: str = "hello"
;         inner: {
;             x: int = 32
;             y: str
;         }
;     }
; }

; let v: vec
; set v.x = 1.0
; set v.bruh.id = 1
; set v.bruh.inner.y = "yo"

; set v = vec : { 
;     x = 1.0 
;     y = 32.0
;     ; bruh = dud : {
;     ;     id = 1
;     ; }
; }

; struct person {
;     name: str = "joe"
;     age: int = 18 * 2
; }

; ; We can use the dot operator to access fields.
; let player_a: person
; set player_a.name = "alex"

; struct vec {
;     x: f64
;     y: f64
;     z: f64
; }
; let v = vec : { x = 1.0 }

; enum weekdays {
;     mon = 1
;     tue
;     wed
;     thu
;     fri
;     sat
;     sun
; }
; let a = weekdays.tue
; let b = a

; struct item {
;     id: int
;     name: str
; }

; ; let a: item = item {
; ;     id = 1
; ; }
; ; let a: item = item ; this shouldn't work, or should it return the default val?
; let c: item
; set c.id = 1
; let d = c.id
; set a.name = "hello"
; let b = a.id
; let c = a.name

; fun add10(a: int, b: str): int {
;     a + 10
; }

; fun foo(): int {
;     add10(1, "hello")
; }

; let a:f32 = (1.0 + 2.0 * 2.0) / 2.0

; let annotated:int = (1 + 2 * 2) / 2
; let numbers = 1
; let symbols = numbers
; let arith = 1 + 2 * 4
; let cmp = 1 <= 2
; let logic = !true && false || (1 <= 2)
; let bits = 0xff & 0b00001111
; let block = {
;     let a = 1 + 2
;     a + 3
; }

; let maybe = if (1 == 2) {
;     32
; } else {
;     44
; }

; let single = if (true) {
;     123
; }

; while (!true) {
;     "asjdflasdjf"
; }

; set single = 32

; cond {
;     1 == 2 = "hello"
;     else = "dong"
; }

; enum test {
;     a = 1
;     b
; }
; ; Resolve struct accessors.
; struct my_struct {
;     field_a: int
;     field_b: int
; }

; let a:my_struct
; set a.field_a = 1

; fun nested(): int {
;     fun adder(a: u32, b: u32): u32 {
;         a + b
;     }
;     if (1 + 1 == 2) {
;         let b = 15
;         {
;             let c = 32
;             5 + c
;         }
;     }
; }

; enum field {
;     a
;     b
; }

; struct vec {
;     a: int
;     b: int
; }

; fun foo(): nil {
;     bar()
; }

; fun bar(): nil {
;     foo()
; }

; ; There are some builtint functions.
; println("hello world")

; ; Let/set.
; let num = 1
; set num = 2
; set num = 0 + num

; ; Loops and conditionals.
; if (num) 3 else 1
; let val = if (2 + num == 4) num else num
; if (true) {
;     let c = 1
;     1 + 1 + c
; }

; fun testmatches(num: int): int {
; ;     match (num) {
; ;         case 1 = 23
; ;         case 2 = num
; ;         else = num
; ;     }

;     cond {
;         1 == 1 = 23
;         2 != 1 = num
;         else = num
;     }
; }

; while (num == 1) num
; while (true) {
;     let c = 1
;     1 + 1 + c
; }
; fun foo(a: int b: str): (f64, f64) {
;     fun bar(): nil {
;         println("ding")
;     }
;     if (a == 1) {
;         ; return("test", b)
;         return (3.0, 4.0)
;     }
;     return (1.0, 2.0)
; }

; let b = a
; let a = a
; set a = 10
; set num = 1 << a
; baz()
; if (a) 1
; if (num == 1) a
; if (num == 1) 1 else a