Landin library reference discuss source

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

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