aboutsummaryrefslogtreecommitdiff
path: root/docs/history/17-o3-boundaries/code/tests/misc.zc
blob: 25fc53b0dfb6bef87303b9c6122f1335b3b13302 (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
// ct { ... } runs a block while compiling and leaves its result as a constant
immediate fn ct()
{
	let q, v;
	next();
	q = grab();
	v = eval(q);
	free(d*q);
	lit(v);
	return 0;
}
// teach the asm syntax that p means out, like the old repl demo
immediate fn teach() { next(); mnem[12] = 'p'; return 0; }
teach

fn countdown()
{
	asm { 5 :top 0 $ '0' + p 1 - 0 $ done z top j :done _ 10 p }
	return 0;
}
fn main()
{
	putn(ct { let i = 0, s = 0; while (i < 10) { s += i; i++; } return s; }); putc(10);
	countdown();
	puts(lazy()); putc(10);
	return 0;
}
// the analyzer is off from here on
unchecked;
fn lazy() { let p = new(3); p[0] = 'o'; p[1] = 'k'; return p; }