aboutsummaryrefslogtreecommitdiff
path: root/testsuite/runnable
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/runnable')
-rw-r--r--testsuite/runnable/record_layout.elna55
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.