diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-25 23:33:22 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-26 02:45:19 +0200 |
| commit | dea1c177cd3592cc24fd15ad446a676da2e4da28 (patch) | |
| tree | ca29eefe25858ca49d376614ecf6ddda9e144299 /testsuite | |
| parent | 4f89a02e03b056d0c55108a8c9194126ef4ee811 (diff) | |
| download | elna-dea1c177cd3592cc24fd15ad446a676da2e4da28.tar.gz | |
Support #offset trait at compile time
Diffstat (limited to 'testsuite')
| -rw-r--r-- | testsuite/runnable/record_layout.elna | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/testsuite/runnable/record_layout.elna b/testsuite/runnable/record_layout.elna new file mode 100644 index 0000000..180d7bc --- /dev/null +++ b/testsuite/runnable/record_layout.elna @@ -0,0 +1,55 @@ +type + IntChar = record + x: Int; + y: Char + end + CharInt = record + c: Char; + i: Int + end + Base = record + x: Int + end + Derived = record(Base) + y: Char + end + ArrayRecord = record + a: [3]Int; + c: Char + end + +proc f() +var + int_size: const Word := #size(Int) + + int_char_size: const Word := #size(IntChar) + int_char_y_offset: const Word := #offset(IntChar, y) + char_int_size: const Word := #size(CharInt) + char_int_c_offset: const Word := #offset(CharInt, c) + char_int_i_offset: const Word := #offset(CharInt, i) + derived_size: const Word := #size(Derived) + derived_x_offset: const Word := #offset(Derived, x) + derived_y_offset: const Word := #offset(Derived, y) + array_record_size: const Word := #size(ArrayRecord) + array_record_a_offset: const Word := #offset(ArrayRecord, a) + array_record_c_offset: const Word := #offset(ArrayRecord, c) +begin + assert(int_char_y_offset = int_size); + assert(int_char_size = 2u * int_size); + + assert(char_int_c_offset = 0u); + assert(char_int_i_offset = int_size); + assert(char_int_size = 2u * int_size); + + assert(derived_x_offset = 0u); + assert(derived_y_offset = int_size); + assert(derived_size = 2u * int_size); + + assert(array_record_size = 4u * int_size); + assert(array_record_a_offset = 0u); + assert(array_record_c_offset = 3u * int_size) +return + +begin + f() +end. |
