harec

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

02-integers.ha (1193B)


      1 fn sizes() void = {
      2 	// Fixed precision
      3 	assert(size(i8) == 1);
      4 	assert(size(i16) == 2);
      5 	assert(size(i32) == 4);
      6 	assert(size(i64) == 8);
      7 	assert(size(u8) == 1);
      8 	assert(size(u16) == 2);
      9 	assert(size(u32) == 4);
     10 	assert(size(u64) == 8);
     11 	// Implementation-defined (test meets spec limits)
     12 	assert(size(int) >= 4);
     13 	assert(size(uint) >= 4);
     14 	// etc
     15 	assert(size(char) == 1);
     16 };
     17 
     18 fn alignment() void = {
     19 	// Fixed alignment
     20 	let _i8 = 0i8, _u8 = 0u8;
     21 	assert(&_i8: uintptr: size % 1 == 0);
     22 	assert(&_u8: uintptr: size % 1 == 0);
     23 	let _i16 = 0i16, _u16 = 0u16;
     24 	assert(&_i16: uintptr: size % 2 == 0);
     25 	assert(&_u16: uintptr: size % 2 == 0);
     26 	let _i32 = 0i32, _u32 = 0u32;
     27 	assert(&_i32: uintptr: size % 4 == 0);
     28 	assert(&_u32: uintptr: size % 4 == 0);
     29 	let _i64 = 0i64, _u64 = 0u64;
     30 	assert(&_i64: uintptr: size % 8 == 0);
     31 	assert(&_u64: uintptr: size % 8 == 0);
     32 	// Implementation-defined alignment
     33 	let i = 0i, u = 0u, z = 0z, uptr = &i: uintptr;
     34 	assert(&i: uintptr: size % size(int) == 0);
     35 	assert(&u: uintptr: size % size(uint) == 0);
     36 	assert(&z: uintptr: size % size(size) == 0);
     37 	assert(&uptr: uintptr: size % size(uintptr) == 0);
     38 };
     39 
     40 export fn main() void = {
     41 	sizes();
     42 	alignment();
     43 };