annotate clang/docs/ConstantInterpreter.rst @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ====================
anatofuz
parents:
diff changeset
2 Constant Interpreter
anatofuz
parents:
diff changeset
3 ====================
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 .. contents::
anatofuz
parents:
diff changeset
6 :local:
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 Introduction
anatofuz
parents:
diff changeset
9 ============
anatofuz
parents:
diff changeset
10
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 The constexpr interpreter aims to replace the existing tree evaluator in
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 clang, improving performance on constructs which are executed inefficiently
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
13 by the evaluator. The interpreter is activated using the following flags:
150
anatofuz
parents:
diff changeset
14
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 * ``-fexperimental-new-constant-interpreter`` enables the interpreter,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
16 emitting an error if an unsupported feature is encountered
150
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 Bytecode Compilation
anatofuz
parents:
diff changeset
19 ====================
anatofuz
parents:
diff changeset
20
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
21 Bytecode compilation is handled in ``ByteCodeStmtGen.h`` for statements
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
22 and ``ByteCodeExprGen.h`` for expressions. The compiler has two different
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
23 backends: one to generate bytecode for functions (``ByteCodeEmitter``) and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 one to directly evaluate expressions as they are compiled, without
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 generating bytecode (``EvalEmitter``). All functions are compiled to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
26 bytecode, while toplevel expressions used in constant contexts are directly
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
27 evaluated since the bytecode would never be reused. This mechanism aims to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 pave the way towards replacing the evaluator, improving its performance on
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 functions and loops, while being just as fast on single-use toplevel
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
30 expressions.
150
anatofuz
parents:
diff changeset
31
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
32 The interpreter relies on stack-based, strongly-typed opcodes. The glue
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
33 logic between the code generator, along with the enumeration and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
34 description of opcodes, can be found in ``Opcodes.td``. The opcodes are
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
35 implemented as generic template methods in ``Interp.h`` and instantiated
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 with the relevant primitive types by the interpreter loop or by the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
37 evaluating emitter.
150
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 Primitive Types
anatofuz
parents:
diff changeset
40 ---------------
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 * ``PT_{U|S}int{8|16|32|64}``
anatofuz
parents:
diff changeset
43
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
44 Signed or unsigned integers of a specific bit width, implemented using
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
45 the ```Integral``` type.
150
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 * ``PT_{U|S}intFP``
anatofuz
parents:
diff changeset
48
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
49 Signed or unsigned integers of an arbitrary, but fixed width used to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
50 implement integral types which are required by the target, but are not
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
51 supported by the host. Under the hood, they rely on APValue. The
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
52 ``Integral`` specialisation for these types is required by opcodes to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
53 share an implementation with fixed integrals.
150
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 * ``PT_Bool``
anatofuz
parents:
diff changeset
56
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
57 Representation for boolean types, essentially a 1-bit unsigned
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 ``Integral``.
150
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 * ``PT_RealFP``
anatofuz
parents:
diff changeset
61
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
62 Arbitrary, but fixed precision floating point numbers. Could be
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
63 specialised in the future similarly to integers in order to improve
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
64 floating point performance.
150
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 * ``PT_Ptr``
anatofuz
parents:
diff changeset
67
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
68 Pointer type, defined in ``"Pointer.h"``. A pointer can be either null,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
69 reference interpreter-allocated memory (``BlockPointer``) or point to an
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
70 address which can be derived, but not accessed (``ExternPointer``).
150
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 * ``PT_FnPtr``
anatofuz
parents:
diff changeset
73
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
74 Function pointer type, can also be a null function pointer. Defined
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
75 in ``"FnPointer.h"``.
150
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 * ``PT_MemPtr``
anatofuz
parents:
diff changeset
78
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
79 Member pointer type, can also be a null member pointer. Defined
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
80 in ``"MemberPointer.h"``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
82 * ``PT_VoidPtr``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
83
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
84 Void pointer type, can be used for round-trip casts. Represented as
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 the union of all pointers which can be cast to void.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
86 Defined in ``"VoidPointer.h"``.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
87
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
88 * ``PT_ObjCBlockPtr``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
89
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
90 Pointer type for ObjC blocks. Defined in ``"ObjCBlockPointer.h"``.
150
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 Composite types
anatofuz
parents:
diff changeset
93 ---------------
anatofuz
parents:
diff changeset
94
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
95 The interpreter distinguishes two kinds of composite types: arrays and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
96 records (structs and classes). Unions are represented as records, except
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
97 at most a single field can be marked as active. The contents of inactive
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
98 fields are kept until they are reactivated and overwritten.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
99 Complex numbers (``_Complex``) and vectors
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
100 (``__attribute((vector_size(16)))``) are treated as arrays.
150
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 Bytecode Execution
anatofuz
parents:
diff changeset
104 ==================
anatofuz
parents:
diff changeset
105
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
106 Bytecode is executed using a stack-based interpreter. The execution
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
107 context consists of an ``InterpStack``, along with a chain of
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
108 ``InterpFrame`` objects storing the call frames. Frames are built by
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
109 call instructions and destroyed by return instructions. They perform
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
110 one allocation to reserve space for all locals in a single block.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
111 These objects store all the required information to emit stack traces
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
112 whenever evaluation fails.
150
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 Memory Organisation
anatofuz
parents:
diff changeset
115 ===================
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 Memory management in the interpreter relies on 3 data structures: ``Block``
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
118 objects which store the data and associated inline metadata, ``Pointer``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
119 objects which refer to or into blocks, and ``Descriptor`` structures which
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
120 describe blocks and subobjects nested inside blocks.
150
anatofuz
parents:
diff changeset
121
anatofuz
parents:
diff changeset
122 Blocks
anatofuz
parents:
diff changeset
123 ------
anatofuz
parents:
diff changeset
124
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
125 Blocks contain data interleaved with metadata. They are allocated either
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
126 statically in the code generator (globals, static members, dummy parameter
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
127 values etc.) or dynamically in the interpreter, when creating the frame
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
128 containing the local variables of a function. Blocks are associated with a
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
129 descriptor that characterises the entire allocation, along with a few
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
130 additional attributes:
150
anatofuz
parents:
diff changeset
131
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
132 * ``IsStatic`` indicates whether the block has static duration in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
133 interpreter, i.e. it is not a local in a frame.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
134
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
135 * ``DeclID`` identifies each global declaration (it is set to an invalid
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
136 and irrelevant value for locals) in order to prevent illegal writes and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
137 reads involving globals and temporaries with static storage duration.
150
anatofuz
parents:
diff changeset
138
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
139 Static blocks are never deallocated, but local ones might be deallocated
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
140 even when there are live pointers to them. Pointers are only valid as
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
141 long as the blocks they point to are valid, so a block with pointers to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
142 it whose lifetime ends is kept alive until all pointers to it go out of
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
143 scope. Since the frame is destroyed on function exit, such blocks are
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
144 turned into a ``DeadBlock`` and copied to storage managed by the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
145 interpreter itself, not the frame. Reads and writes to these blocks are
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
146 illegal and cause an appropriate diagnostic to be emitted. When the last
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
147 pointer goes out of scope, dead blocks are also deallocated.
150
anatofuz
parents:
diff changeset
148
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
149 The lifetime of blocks is managed through 3 methods stored in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
150 descriptor of the block:
150
anatofuz
parents:
diff changeset
151
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
152 * **CtorFn**: initializes the metadata which is store in the block,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
153 alongside actual data. Invokes the default constructors of objects
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
154 which are not trivial (``Pointer``, ``RealFP``, etc.)
150
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 * **DtorFn**: invokes the destructors of non-trivial objects.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
157
150
anatofuz
parents:
diff changeset
158 * **MoveFn**: moves a block to dead storage.
anatofuz
parents:
diff changeset
159
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
160 Non-static blocks track all the pointers into them through an intrusive
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
161 doubly-linked list, required to adjust and invalidate all pointers when
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
162 transforming a block into a dead block. If the lifetime of an object ends,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
163 all pointers to it are invalidated, emitting the appropriate diagnostics when
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
164 dereferenced.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
165
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
166 The interpreter distinguishes 3 different kinds of blocks:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
167
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
168 * **Primitives**
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
169
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
170 A block containing a single primitive with no additional metadata.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
171
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
172 * **Arrays of primitives**
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
174 An array of primitives contains a pointer to an ``InitMap`` storage as its
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
175 first field: the initialisation map is a bit map indicating all elements of
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
176 the array which were initialised. If the pointer is null, no elements were
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
177 initialised, while a value of ``(InitMap*)-1`` indicates that the object was
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
178 fully initialised. When all fields are initialised, the map is deallocated
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
179 and replaced with that token.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
180
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
181 Array elements are stored sequentially, without padding, after the pointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
182 to the map.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
183
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
184 * **Arrays of composites and records**
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
185
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
186 Each element in an array of composites is preceded by an ``InlineDescriptor``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
187 which stores the attributes specific to the field and not the whole
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
188 allocation site. Descriptors and elements are stored sequentially in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
189 block.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
190 Records are laid out identically to arrays of composites: each field and base
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
191 class is preceded by an inline descriptor. The ``InlineDescriptor``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
192 has the following fields:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
193
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
194 * **Offset**: byte offset into the array or record, used to step back to the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
195 parent array or record.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
196 * **IsConst**: flag indicating if the field is const-qualified.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
197 * **IsInitialized**: flag indicating whether the field or element was
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
198 initialized. For non-primitive fields, this is only relevant to determine
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
199 the dynamic type of objects during construction.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
200 * **IsBase**: flag indicating whether the record is a base class. In that
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
201 case, the offset can be used to identify the derived class.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
202 * **IsActive**: indicates if the field is the active field of a union.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
203 * **IsMutable**: indicates if the field is marked as mutable.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
204
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
205 Inline descriptors are filled in by the `CtorFn` of blocks, which leaves storage
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
206 in an uninitialised, but valid state.
150
anatofuz
parents:
diff changeset
207
anatofuz
parents:
diff changeset
208 Descriptors
anatofuz
parents:
diff changeset
209 -----------
anatofuz
parents:
diff changeset
210
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
211 Descriptors are generated at bytecode compilation time and contain information
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
212 required to determine if a particular memory access is allowed in constexpr.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
213 They also carry all the information required to emit a diagnostic involving
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
214 a memory access, such as the declaration which originates the block.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
215 Currently there is a single kind of descriptor encoding information for all
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
216 block types.
150
anatofuz
parents:
diff changeset
217
anatofuz
parents:
diff changeset
218 Pointers
anatofuz
parents:
diff changeset
219 --------
anatofuz
parents:
diff changeset
220
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
221 Pointers, implemented in ``Pointer.h`` are represented as a tagged union.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
222 Some of these may not yet be available in upstream ``clang``.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
223
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
224 * **BlockPointer**: used to reference memory allocated and managed by the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
225 interpreter, being the only pointer kind which allows dereferencing in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
226 interpreter
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
227 * **ExternPointer**: points to memory which can be addressed, but not read by
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
228 the interpreter. It is equivalent to APValue, tracking a declaration and a path
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
229 of fields and indices into that allocation.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
230 * **TargetPointer**: represents a target address derived from a base address
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
231 through pointer arithmetic, such as ``((int *)0x100)[20]``. Null pointers are
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
232 target pointers with a zero offset.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
233 * **TypeInfoPointer**: tracks information for the opaque type returned by
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
234 ``typeid``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
235 * **InvalidPointer**: is dummy pointer created by an invalid operation which
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
236 allows the interpreter to continue execution. Does not allow pointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
237 arithmetic or dereferencing.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
238
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
239 Besides the previously mentioned union, a number of other pointer-like types
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
240 have their own type:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
241
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
242 * **ObjCBlockPointer** tracks Objective-C blocks
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
243 * **FnPointer** tracks functions and lazily caches their compiled version
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
244 * **MemberPointer** tracks C++ object members
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
245
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
246 Void pointers, which can be built by casting any of the aforementioned
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
247 pointers, are implemented as a union of all pointer types. The ``BitCast``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
248 opcode is responsible for performing all legal conversions between these
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
249 types and primitive integers.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
250
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
251 BlockPointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
252 ~~~~~~~~~~~~
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
253
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
254 Block pointers track a ``Pointee``, the block to which they point, along
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
255 with a ``Base`` and an ``Offset``. The base identifies the innermost field,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
256 while the offset points to an array element relative to the base (including
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
257 one-past-end pointers). The offset identifies the array element or field
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
258 which is referenced, while the base points to the outer object or array which
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
259 contains the field. These two fields allow all pointers to be uniquely
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
260 identified, disambiguated and characterised.
150
anatofuz
parents:
diff changeset
261
anatofuz
parents:
diff changeset
262 As an example, consider the following structure:
anatofuz
parents:
diff changeset
263
anatofuz
parents:
diff changeset
264 .. code-block:: c
anatofuz
parents:
diff changeset
265
anatofuz
parents:
diff changeset
266 struct A {
anatofuz
parents:
diff changeset
267 struct B {
anatofuz
parents:
diff changeset
268 int x;
anatofuz
parents:
diff changeset
269 int y;
anatofuz
parents:
diff changeset
270 } b;
anatofuz
parents:
diff changeset
271 struct C {
anatofuz
parents:
diff changeset
272 int a;
anatofuz
parents:
diff changeset
273 int b;
anatofuz
parents:
diff changeset
274 } c[2];
anatofuz
parents:
diff changeset
275 int z;
anatofuz
parents:
diff changeset
276 };
anatofuz
parents:
diff changeset
277 constexpr A a;
anatofuz
parents:
diff changeset
278
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
279 On the target, ``&a`` and ``&a.b.x`` are equal. So are ``&a.c[0]`` and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
280 ``&a.c[0].a``. In the interpreter, all these pointers must be
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
281 distinguished since the are all allowed to address distinct range of
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
282 memory.
150
anatofuz
parents:
diff changeset
283
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
284 In the interpreter, the object would require 240 bytes of storage and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
285 would have its field interleaved with metadata. The pointers which can
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
286 be derived to the object are illustrated in the following diagram:
150
anatofuz
parents:
diff changeset
287
anatofuz
parents:
diff changeset
288 ::
anatofuz
parents:
diff changeset
289
anatofuz
parents:
diff changeset
290 0 16 32 40 56 64 80 96 112 120 136 144 160 176 184 200 208 224 240
anatofuz
parents:
diff changeset
291 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
anatofuz
parents:
diff changeset
292 + B | D | D | x | D | y | D | D | D | a | D | b | D | D | a | D | b | D | z |
anatofuz
parents:
diff changeset
293 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
anatofuz
parents:
diff changeset
294 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
anatofuz
parents:
diff changeset
295 | | | | | | | &a.c[0].b | | &a.c[1].b |
anatofuz
parents:
diff changeset
296 a |&a.b.x &a.y &a.c |&a.c[0].a |&a.c[1].a |
anatofuz
parents:
diff changeset
297 &a.b &a.c[0] &a.c[1] &a.z
anatofuz
parents:
diff changeset
298
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
299 The ``Base`` offset of all pointers points to the start of a field or
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
300 an array and is preceded by an inline descriptor (unless ``Base`` is
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
301 zero, pointing to the root). All the relevant attributes can be read
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
302 from either the inline descriptor or the descriptor of the block.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
303
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
304
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
305 Array elements are identified by the ``Offset`` field of pointers,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
306 pointing to past the inline descriptors for composites and before
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
307 the actual data in the case of primitive arrays. The ``Offset``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
308 points to the offset where primitives can be read from. As an example,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
309 ``a.c + 1`` would have the same base as ``a.c`` since it is an element
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
310 of ``a.c``, but its offset would point to ``&a.c[1]``. The
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
311 array-to-pointer decay operation adjusts a pointer to an array (where
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
312 the offset is equal to the base) to a pointer to the first element.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
313
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
314 ExternPointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
315 ~~~~~~~~~~~~~
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
316
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
317 Extern pointers can be derived, pointing into symbols which are not
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
318 readable from constexpr. An external pointer consists of a base
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
319 declaration, along with a path designating a subobject, similar to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
320 the ``LValuePath`` of an APValue. Extern pointers can be converted
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
321 to block pointers if the underlying variable is defined after the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
322 pointer is created, as is the case in the following example:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
323
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
324 .. code-block:: c
150
anatofuz
parents:
diff changeset
325
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
326 extern const int a;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
327 constexpr const int *p = &a;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
328 const int a = 5;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
329 static_assert(*p == 5, "x");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
330
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
331 TargetPointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
332 ~~~~~~~~~~~~~
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
333
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
334 While null pointer arithmetic or integer-to-pointer conversion is
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
335 banned in constexpr, some expressions on target offsets must be folded,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
336 replicating the behaviour of the ``offsetof`` builtin. Target pointers
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
337 are characterised by 3 offsets: a field offset, an array offset and a
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
338 base offset, along with a descriptor specifying the type the pointer is
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
339 supposed to refer to. Array indexing adjusts the array offset, while the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
340 field offset is adjusted when a pointer to a member is created. Casting
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
341 an integer to a pointer sets the value of the base offset. As a special
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
342 case, null pointers are target pointers with all offsets set to 0.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
343
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
344 TypeInfoPointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
345 ~~~~~~~~~~~~~~~
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
346
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
347 ``TypeInfoPointer`` tracks two types: the type assigned to
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
348 ``std::type_info`` and the type which was passed to ``typeinfo``.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
349
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
350 InvalidPointer
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
351 ~~~~~~~~~~~~~~
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
352
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
353 Such pointers are built by operations which cannot generate valid
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
354 pointers, allowing the interpreter to continue execution after emitting
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
355 a warning. Inspecting such a pointer stops execution.
150
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 TODO
anatofuz
parents:
diff changeset
358 ====
anatofuz
parents:
diff changeset
359
anatofuz
parents:
diff changeset
360 Missing Language Features
anatofuz
parents:
diff changeset
361 -------------------------
anatofuz
parents:
diff changeset
362
anatofuz
parents:
diff changeset
363 * Changing the active field of unions
anatofuz
parents:
diff changeset
364 * ``volatile``
anatofuz
parents:
diff changeset
365 * ``__builtin_constant_p``
anatofuz
parents:
diff changeset
366 * ``dynamic_cast``
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
367 * ``new`` and ``delete``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
368 * Fixed Point numbers and arithmetic on Complex numbers
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
369 * Several builtin methods, including string operations and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
370 ``__builtin_bit_cast``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
371 * Continue-after-failure: a form of exception handling at the bytecode
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
372 level should be implemented to allow execution to resume. As an example,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
373 argument evaluation should resume after the computation of an argument fails.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
374 * Pointer-to-Integer conversions
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
375 * Lazy descriptors: the interpreter creates a ``Record`` and ``Descriptor``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
376 when it encounters a type: ones which are not yet defined should be lazily
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
377 created when required
150
anatofuz
parents:
diff changeset
378
anatofuz
parents:
diff changeset
379 Known Bugs
anatofuz
parents:
diff changeset
380 ----------
anatofuz
parents:
diff changeset
381
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
382 * If execution fails, memory storing APInts and APFloats is leaked when the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
383 stack is cleared