typeof.bx
Bx
1extrn printf;
2
3type struct Point {
4 x int;
5 y int;
6};
7
8type enum Color {
9 RED,
10 GREEN,
11 BLUE
12};
13
14void testFunc(i int, f float) {
15 printf("param int: %s\n", typeof(i));
16 printf("param float: %s\n", typeof(f));
17}
18
19float returnFloat() {
20 return (2.5);
21}
22
23main() {
24 printf("Basic types:\n");
25
26 int i = 42;
27 uint ui = 42;
28 float f = 3.14;
29 bool b = 1;
30 byte by = 65;
31 printf("int: %s, uint: %s, float: %s, bool: %s, byte: %s\n",
32 typeof(i), typeof(ui), typeof(f), typeof(b), typeof(by));
33
34 printf("\nLiterals:\n");
35 printf("42: %s, 3.14: %s, \"hello\": %s\n",
36 typeof(42), typeof(3.14), typeof("hello"));
37
38 auto auto_int = 42;
39 auto auto_float = 3.14;
40 printf("auto int: %s, auto float: %s\n", typeof(auto_int), typeof(auto_float));
41
42 printf("\nPointers and arrays:\n");
43 auto ptr = &i;
44 int arr[3];
45 arr[0] = 10;
46 printf("int ptr: %s, array: %s, element: %s\n",
47 typeof(ptr), typeof(arr), typeof(arr[0]));
48
49 printf("\nStructs and enums:\n");
50 Point p;
51 p.x = 10;
52 Color color = RED;
53 printf("struct: %s, member: %s, enum: %s\n",
54 typeof(p), typeof(p.x), typeof(color));
55
56 printf("\nExpressions:\n");
57 printf("i + i: %s, f + f: %s, float(i) + f: %s\n",
58 typeof(i + i), typeof(f + f), typeof(float(i) + f));
59 printf("i > 0: %s\n", typeof(i > 0));
60
61 printf("\nControl flow:\n");
62 if (i > 0) {
63 printf("in if: %s\n", typeof(i));
64 }
65
66 auto counter = 0;
67 while (counter < 2) {
68 printf("in loop: %s\n", typeof(counter));
69 counter++;
70 }
71
72 printf("\nFunction calls:\n");
73 testFunc(42, 3.14);
74 auto ret = returnFloat();
75 printf("returned: %s\n", typeof(ret));
76
77 return(0);
78}