harec

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

26-regression.ha (2799B)


      1 // Miscellaneous regression tests
      2 use rt;
      3 
      4 type embedded = struct {
      5 	a: u64,
      6 	b: u8,
      7 };
      8 
      9 type thing = struct {
     10 	offs: u64,
     11 	e: embedded,
     12 };
     13 
     14 def THING: thing = thing{
     15 	offs = 0,
     16 	e = embedded {
     17 		a = 1,
     18 		b = 0,
     19 	},
     20 };
     21 
     22 let global: int = 0;
     23 
     24 type mod::t = (size | const size); // needs to have a type id larger than size
     25 
     26 export fn main() void = {
     27 	let t = thing {
     28 		offs = 0,
     29 		e = embedded {
     30 			a = 1,
     31 			b = 0,
     32 		},
     33 	};
     34 	let t = t;
     35 	assert(t.e.a == 1);
     36 
     37 	let t2 = THING;
     38 	assert(t2.e.a == 1);
     39 
     40 	t2.offs = 42;
     41 	assert(THING.offs == 0);
     42 
     43 	let x: (void | int) = 10;
     44 	match (x) {
     45 	case let i: int =>
     46 		assert(i == 10);
     47 	case void =>
     48 		abort();
     49 	};
     50 
     51 	let p = 0;
     52 	let p = &p: uintptr: u64: (u64 | void);
     53 	let p = match (p) {
     54 	case void =>
     55 		abort();
     56 	case let p: u64 =>
     57 		yield p: uintptr: *int;
     58 	};
     59 	assert(*p == 0);
     60 
     61 	let thing: int = 0;
     62 	let thing = &thing: (*int | int);
     63 	let p = match (thing) {
     64 	case int =>
     65 		abort();
     66 	case let p: *int =>
     67 		yield p;
     68 	};
     69 	*p = 0;
     70 
     71 	switch (&global) {
     72 	case &global => void;
     73 	case => abort();
     74 	};
     75 
     76 	match (void: (void | !void)) {
     77 	case void => void;
     78 	case !void => abort();
     79 	};
     80 
     81 	assert(rt::compile("
     82 		fn a() void = switch (b) {
     83 		case &c => void;
     84 		};"
     85 	) as rt::exited != rt::EXIT_SUCCESS);
     86 
     87 	assert(rt::compile("let a;") as rt::exited != rt::EXIT_SUCCESS);
     88 	assert(rt::compile("
     89 		type a = struct {
     90 			b: int,
     91 			c: int,
     92 		};
     93 		def A: a = a { b = 0 };"
     94 	) as rt::exited != rt::EXIT_SUCCESS);
     95 	assert(rt::compile("let a = &0;") as rt::exited != rt::EXIT_SUCCESS);
     96 	assert(rt::compile("def A: a = 1 % 1;") as rt::exited != rt::EXIT_SUCCESS);
     97 	assert(rt::compile("def A: b = void;") as rt::exited != rt::EXIT_SUCCESS);
     98 	static assert(true == true && true != false);
     99 	assert(rt::compile("
    100 		type a = str;
    101 		type b = struct { a };
    102 		def A = b { c = 0 };"
    103 	) as rt::exited != rt::EXIT_SUCCESS);
    104 	assert(rt::compile("
    105 		fn a() void = {
    106 			let x: (void | int) = abort();
    107 		};"
    108 	) as rt::exited == rt::EXIT_SUCCESS);
    109 	assert(rt::compile("
    110 		def A = 0;
    111 		fn a() void = A = 0;"
    112 	) as rt::exited != rt::EXIT_SUCCESS);
    113 	assert(rt::compile("def A = x && true;") as rt::exited != rt::EXIT_SUCCESS);
    114 	assert(rt::compile("type a = struct { b: fn() void };") as rt::exited != rt::EXIT_SUCCESS);
    115 	assert(rt::compile("fn a() []int = alloc([]: [*]int, 0);") as rt::exited != rt::EXIT_SUCCESS);
    116 	assert(rt::compile("fn a() [1]int = [1]: []int: [1]int;") as rt::exited != rt::EXIT_SUCCESS);
    117 	assert(rt::compile("fn a() void = &*&a;") as rt::exited != rt::EXIT_SUCCESS);
    118 	assert(rt::compile("let a = [*&0];") as rt::exited != rt::EXIT_SUCCESS);
    119 	assert(rt::compile("fn a() *void = alloc(void);") as rt::exited != rt::EXIT_SUCCESS);
    120 	assert(rt::compile("fn a() void = { static let b = x & struct { a: int = 0 }; };") as rt::exited != rt::EXIT_SUCCESS);
    121 	let a: (size | mod::t) = 0;
    122 };