harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

26-gen.ha (943B)


      1 // Tests for various gen bugs
      2 
      3 type embedded = struct {
      4 	a: u64,
      5 	b: u8,
      6 };
      7 
      8 type thing = struct {
      9 	offs: u64,
     10 	e: embedded,
     11 };
     12 
     13 def THING: thing = thing{
     14 	offs = 0,
     15 	e = embedded {
     16 		a = 1,
     17 		b = 0,
     18 	},
     19 };
     20 
     21 let global: int = 0;
     22 
     23 export fn main() void = {
     24 	let t = thing {
     25 		offs = 0,
     26 		e = embedded {
     27 			a = 1,
     28 			b = 0,
     29 		},
     30 	};
     31 	let t = t;
     32 	assert(t.e.a == 1);
     33 
     34 	let t2 = THING;
     35 	assert(t2.e.a == 1);
     36 
     37 	t2.offs = 42;
     38 	assert(THING.offs == 0);
     39 
     40 	let x: (void | int) = 10;
     41 	match (x) {
     42 	case let i: int =>
     43 		assert(i == 10);
     44 	case void =>
     45 		abort();
     46 	};
     47 
     48 	let p = 0;
     49 	let p = &p: uintptr: u64: (u64 | void);
     50 	let p = match (p) {
     51 	case void =>
     52 		abort();
     53 	case let p: u64 =>
     54 		yield p: uintptr: *int;
     55 	};
     56 	assert(*p == 0);
     57 
     58 	let thing: int = 0;
     59 	let thing = &thing: (*int | int);
     60 	let p = match (thing) {
     61 	case int =>
     62 		abort();
     63 	case let p: *int =>
     64 		yield p;
     65 	};
     66 	*p = 0;
     67 
     68 	switch (&global) {
     69 	case &global => void;
     70 	case => abort();
     71 	};
     72 };