File: 33-yield.ha

package info (click to toggle)
harec 0.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,480 kB
  • sloc: ansic: 20,054; asm: 335; makefile: 116; lisp: 80; sh: 45
file content (63 lines) | stat: -rw-r--r-- 810 bytes parent folder | download | duplicates (2)
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
use rt::{compile, status};

fn basics() void = {
	let x = {
		yield 10;
	};
	let y = :outer {
		if (true) {
			yield :outer, 20;
		};
		abort();
	};
	assert(x == 10);
	assert(y == 20);
};

fn _never() void = {
	:outer {
		let x: int = if (true) {
			yield :outer;
		} else 1;
		abort();
	};

	compile(status::CHECK,
		"fn test() void = { let x: int = if (true) { yield; } else 1; };"
	)!;
};

fn cast_lowering() void = {
	let x: (int | void) = {
		yield 10;
	};
	assert(x as int == 10);

	let x = {
		for (false) yield 10;
	};
	assert(x is void);
};

fn shadowing() void = {
	let i = 0;
	:foo {
		:foo {
			for :foo (true) {
				break :foo;
			};
			i += 1;
			yield :foo;
		};
		i += 1;
		yield :foo;
	};
	assert(i == 2);
};

export fn main() void = {
	basics();
	_never();
	cast_lowering();
	shadowing();
};