Landin library reference source

compiler/tests/fixtures/runtime/r440-c-aliases/main.ldn

1import platform/c
2import platform/c (c_bool, c_double, c_float, c_long, c_longlong, c_ptrdiff,
3               c_size, c_ulong, c_ulonglong)
4
5public main: () -> (code: i32) =
6    --  c_char is deliberately a signed numeric byte, not Unicode u32.
7    character: c.c_char = -1
8    signed_character: c.c_schar = -2
9    unsigned_character: c.c_uchar = 255
10    short_value: c.c_short = -123
11    unsigned_short: c.c_ushort = 456
12    integer: c.c_int = -789
13    unsigned_integer: c.c_uint = 987
14    long_value: c.c_long = c_long(integer)
15    unsigned_long: c.c_ulong = c_ulong(unsigned_integer)
16    long_long: c.c_longlong = c_longlong(long_value)
17    unsigned_long_long: c.c_ulonglong = c_ulonglong(unsigned_long)
18    size: c.c_size = c_size(24)
19    difference: c.c_ptrdiff = c_ptrdiff(-24)
20    single: c.c_float = c_float(3)
21    double: c.c_double = c_double(single)
22    truth: c.c_bool = c_bool(1)
23
24    --  Alias identity permits these ordinary assignments without adapters.
25    ordinary_character: i8 = character
26    ordinary_short: i16 = short_value
27    ordinary_integer: i32 = integer
28    ordinary_long: i64 = long_value
29    ordinary_unsigned_character: u8 = unsigned_character
30    ordinary_unsigned_short: u16 = unsigned_short
31    ordinary_unsigned_integer: u32 = unsigned_integer
32    ordinary_unsigned_long: u64 = unsigned_long
33    ordinary_size: usize = size
34    ordinary_difference: isize = difference
35    ordinary_single: f32 = single
36    ordinary_double: f64 = double
37    ordinary_truth: bool = truth
38
39    if sizeof c.c_char == 1 and alignof c.c_char == 1
40      and sizeof c.c_schar == 1 and alignof c.c_schar == 1
41      and sizeof c.c_uchar == 1 and alignof c.c_uchar == 1
42      and sizeof c.c_short == 2 and alignof c.c_short == 2
43      and sizeof c.c_ushort == 2 and alignof c.c_ushort == 2
44      and sizeof c.c_int == 4 and alignof c.c_int == 4
45      and sizeof c.c_uint == 4 and alignof c.c_uint == 4
46      and sizeof c.c_long == 8 and alignof c.c_long == 8
47      and sizeof c.c_ulong == 8 and alignof c.c_ulong == 8
48      and sizeof c.c_longlong == 8 and alignof c.c_longlong == 8
49      and sizeof c.c_ulonglong == 8 and alignof c.c_ulonglong == 8
50      and sizeof c.c_size == 8 and alignof c.c_size == 8
51      and sizeof c.c_ptrdiff == 8 and alignof c.c_ptrdiff == 8
52      and sizeof c.c_float == 4 and alignof c.c_float == 4
53      and sizeof c.c_double == 8 and alignof c.c_double == 8
54      and sizeof c.c_bool == 1 and alignof c.c_bool == 1
55      and ordinary_character == -1 and ordinary_short == -123
56      and ordinary_integer == -789 and ordinary_long == -789
57      and ordinary_unsigned_character == 255 and ordinary_unsigned_short == 456
58      and ordinary_unsigned_integer == 987 and ordinary_unsigned_long == 987
59      and long_long == -789 and unsigned_long_long == 987
60      and ordinary_size == 24 and ordinary_difference == -24
61      and ordinary_single == 3.0 and ordinary_double == 3.0
62      and ordinary_truth
63    then
64        code = 42
65    else
66        code = 1
67    end if
68end main