aboutsummaryrefslogtreecommitdiff
path: root/test.yx
blob: 346f095ce9ce973c33c7b9047b456c021139df03 (plain) (blame)
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
X :: 5;
Y: u8 : X;
Z :: Y;

ZZ :: 127;

my_global: i8 = ZZ;
no_init: u128;

another_global := 123'456'789;

uninit :: () {
	x: int = …;
	y: u32 = ...;
}

pub main :: () {
	no_init: u128;
	x := no_init;

	no_init_undef: int = …;
}

pub bar :: () int {
	hello_world_this_is_my_var  := 126;
	hello_world_this_is_my_var′ := 127;
	hello_world_this_is_my_var″ := 128;
	return hello_world_this_is_my_var′;
}

foo :: () int {
	baz :: () int {
		X :: X;
		return X;
	}

	y := 5;
	x := y;
	return x;
}

rune :: () {
	ch: rune = 8224; /* U+2020 DAGGER */
}

float_test :: () {
	π :: 3.14159265358979323846264338327950288419716939937510582097494459;
	a: f16  = π;
	b: f32  = π;
	c: f64  = π;
	d: f128 = π;

	f := 3.14;
}

/* Yes we have comments in this language,
	/* You can even nest them! */ */

/* There are no line-comments, because why have 2 styles when you can have 1? */

neg_test :: () int {
	x := 420;
	return -x;
}

/* This method should return 1337, because it’s not an increment but
   actually parsed as (+ (+ x)), which is equivalant to ‘x’. */
some_math :: () int {
	x := 1337;
	return ++x;
}

complex_math :: () uint {
	x: uint = 42;
	y: uint = 123;
	z := (x + y) / x;
	return x + y / x;
}

div :: () f64 {
	return 5 / 2;
}

remainder :: () int {
	x := 5;
	y := 2;
	z := 5 % 2;
	return x % y;
}

xor :: () int {
	x := 42;
	y := 123;
	z := ~y;
	return x + z ~ y;
}

shl_kinda_sus :: () u8 {
	x: u8 = 1;
	y: u16 : 1<<8 - 1;
	return x<<y;
}

shr :: () u8 {
	x: u8 = 255;
	y: u8 = 3;
	return x >> 256;
}

bit_fidling :: () int {
	x := 122;
	y := x | 1;
	return y;
}

assignment :: () int {
	x := 5;
	y := 4;
	x = x + y;
	y = 69;
	return x + y;
}

some_global: int;
mutate_global :: () {
	some_global = 42;
}

float_div :: () f64 {
	x := 5.0;
	y := 2.0;
	return x / y;
}