aboutsummaryrefslogtreecommitdiffstats
path: root/tests/semantics.bad
blob: acf43166c09b74e9d7abd1d122f39863f34874c5 (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
let idx = 1
let numbers: @int
set numbers[idx] = 32
set numbers[1] = numbers[0]

let numbers_arr: int[0xff]
set numbers_arr[0] = numbers[0]

let ptr_arr: @int[0xff]
set ptr_arr[0] = @numbers[0]

struct hallo {
    a: int
    b: str
}
let b: @hallo
set b[0].a = 1

struct ptrs {
    a: @int
    b: str[128]
    c: hallo[100]
}
let c: ptrs
set c.a[0] = 1
set c.b[0] = "ho"
; set c.c[0].a = 1 ; this doesn't work at the moment

fun foo(a: int): int {
    1
}
fun bar(): int {
    fun foo(): int 1 + 2
    1 
}

let a = 1
match a {
    case 1 = "ha"
    case 2 = "ho"
}
cond {
    1 == 1 = "ha"
    2 != 2 = "ho"
}

struct vec {
    x: f64
    y: f64
    huh: {
        z: int
        id: str
    }
}

let v: vec = vec : {
    x = 10.0
    huh = {
        z = 10
        id = "blah"
    }
}

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

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

let v2: ext
set v2.x = 1.0
set v2.bruh.id = 1
set v2.bruh.inner.y = "yo"

set v2 = ext : { 
    x = 1.0 
    y = 32.0
    bruh = {
        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 vecf {
    x: f64
    y: f64
    z: f64
}
let v3 = vecf : { x = 1.0 }

enum weekdays {
    mon = 1
    tue
    wed
    thu
    fri
    sat
    sun
}
let d = weekdays.tue

match 1 {
    case 2 = "monday"
    case 3 = "tuesday"
    else = "whateverday"
}

match d {
    case mon = "monday"
    case tue = "tuesday"
    else = "whateverday"
}

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

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

let f:f64 = (1.0 + 2.0 * 2.0) / 2.0

let annotated:int = (1 + 2 * 2) / 2
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) {
    println("asjdflasdjf")
}

set single = 32

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

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