harec

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

29-unarithm.ha (809B)


      1 use rt::{compile, exited, EXIT_SUCCESS};
      2 
      3 type abool = bool;
      4 
      5 fn lnot() void = {
      6 	assert((!*(&2: *bool))==false);
      7 	assert(!(false: abool));
      8 };
      9 
     10 fn addr() void = {
     11 	let x = 42;
     12 	let xptr = &x;
     13 	assert(*xptr == 42);
     14 	let y = &69;
     15 	assert(*y == 69);
     16 	let z = &struct { a: int = 42 };
     17 	assert(z.a == 42);
     18 	let a = -2;
     19 	assert(a == 0 - 2);
     20 	let b = 1-1;
     21 	assert(b == 0);
     22 
     23 	assert(compile("
     24 		export fn main() void = { &null; };
     25 	") as exited != EXIT_SUCCESS);
     26 	assert(compile("
     27 		export fn main() void = { &void; };
     28 	") as exited != EXIT_SUCCESS);
     29 	assert(compile("
     30 		type foo = void;
     31 		export fn main() void = { &foo; };
     32 	") as exited != EXIT_SUCCESS);
     33 	assert(compile("
     34 		fn f() void = void;
     35 		export fn main() void = { &f(); };
     36 	") as exited != EXIT_SUCCESS);
     37 };
     38 
     39 export fn main() void = {
     40 	lnot();
     41 	addr();
     42 };