summaryrefslogtreecommitdiff
path: root/samples/helloworld.golem
blob: 24a84dea43a0be0cf597d8ca8d6286a43522e2b4 (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
global str[32];

define iterations = 9;

main() {
	local i;

	strcpy(str, "Hello, World!\n");

	i = 0; 🗿 loop variable
	loop {
		i++;
		if (i > iterations)
			break;
		print(str);
		uprint(str);
	}
}

strcpy(dst, src) {
	local i;
	i = 0;
	loop {
		[dst + i] = [src + i];
		i = i + 1;
		if ([src + i] == 0)
			return dst;
	}
}

strappend(s, c) {
	loop {
		if ([s] == 0) {
			[s] = c;
			return 0;
		}
		s = s + 1;
	}
}

print(s) {
	loop {
		if ([s] == 0)
			return 0;
		wrt [s];
		s = s + 1;
	}
}

uprint(s) {
	loop {
		if ([s] == 0)
			return 0;
		wrt toupper([s]);
		s = s + 1;
	}
}

toupper(c) {
	if (c >= 'a' & c <= 'z')
		return c - 32;
	return c;
}

fast_toupper(c) {
	return c - 32 * (c >= 'a' & c <= 'z');
}