@@ -18,8 +18,8 @@ by the evaluator. The interpreter is activated using the following flags:
18
18
Bytecode Compilation
19
19
====================
20
20
21
- Bytecode compilation is handled in ``ByteCodeStmtGen .h `` for statements
22
- and `` ByteCodeExprGen.h `` for expressions. The compiler has two different
21
+ Bytecode compilation is handled in ``Compiler .h `` for statements
22
+ and for expressions. The compiler has two different
23
23
backends: one to generate bytecode for functions (``ByteCodeEmitter ``) and
24
24
one to directly evaluate expressions as they are compiled, without
25
25
generating bytecode (``EvalEmitter ``). All functions are compiled to
@@ -44,11 +44,11 @@ Primitive Types
44
44
Signed or unsigned integers of a specific bit width, implemented using
45
45
the ```Integral` `` type.
46
46
47
- * ``PT_{U|S}intFP ``
47
+ * ``PT_IntAP{S} ``
48
48
49
49
Signed or unsigned integers of an arbitrary, but fixed width used to
50
50
implement integral types which are required by the target, but are not
51
- supported by the host. Under the hood, they rely on APValue . The
51
+ supported by the host. Under the hood, they rely on `` APInt `` . The
52
52
``Integral `` specialisation for these types is required by opcodes to
53
53
share an implementation with fixed integrals.
54
54
@@ -57,38 +57,29 @@ Primitive Types
57
57
Representation for boolean types, essentially a 1-bit unsigned
58
58
``Integral ``.
59
59
60
- * ``PT_RealFP ``
60
+ * ``PT_Float ``
61
61
62
62
Arbitrary, but fixed precision floating point numbers. Could be
63
63
specialised in the future similarly to integers in order to improve
64
64
floating point performance.
65
65
66
66
* ``PT_Ptr ``
67
67
68
- Pointer type, defined in ``"Pointer.h" ``. A pointer can be either null,
69
- reference interpreter-allocated memory (``BlockPointer ``) or point to an
70
- address which can be derived, but not accessed (``ExternPointer ``).
68
+ Pointer type, defined in ``"Pointer.h" ``. The most common type of
69
+ pointer is a "BlockPointer", which points to an ``interp::Block ``.
70
+ But other pointer types exist, such as typeid pointers or
71
+ integral pointers.
71
72
72
73
* ``PT_FnPtr ``
73
74
74
75
Function pointer type, can also be a null function pointer. Defined
75
- in ``"FnPointer .h" ``.
76
+ in ``"FunctionPointer .h" ``.
76
77
77
- * ``PT_MemPtr ``
78
+ * ``PT_MemberPtr ``
78
79
79
80
Member pointer type, can also be a null member pointer. Defined
80
81
in ``"MemberPointer.h" ``
81
82
82
- * ``PT_VoidPtr ``
83
-
84
- Void pointer type, can be used for round-trip casts. Represented as
85
- the union of all pointers which can be cast to void.
86
- Defined in ``"VoidPointer.h" ``.
87
-
88
- * ``PT_ObjCBlockPtr ``
89
-
90
- Pointer type for ObjC blocks. Defined in ``"ObjCBlockPointer.h" ``.
91
-
92
83
Composite types
93
84
---------------
94
85
@@ -219,35 +210,21 @@ Pointers
219
210
--------
220
211
221
212
Pointers, implemented in ``Pointer.h `` are represented as a tagged union.
222
- Some of these may not yet be available in upstream ``clang ``.
223
213
224
214
* **BlockPointer **: used to reference memory allocated and managed by the
225
215
interpreter, being the only pointer kind which allows dereferencing in the
226
216
interpreter
227
- * **ExternPointer **: points to memory which can be addressed, but not read by
228
- the interpreter. It is equivalent to APValue, tracking a declaration and a path
229
- of fields and indices into that allocation.
230
- * **TargetPointer **: represents a target address derived from a base address
231
- through pointer arithmetic, such as ``((int *)0x100)[20] ``. Null pointers are
232
- target pointers with a zero offset.
233
- * **TypeInfoPointer **: tracks information for the opaque type returned by
217
+ * **TypeIDPointer **: tracks information for the opaque type returned by
234
218
``typeid ``
235
- * **InvalidPointer **: is dummy pointer created by an invalid operation which
236
- allows the interpreter to continue execution. Does not allow pointer
237
- arithmetic or dereferencing.
219
+ * **IntegralPointer **: a pointer formed from an integer,
220
+ think ``(int*)123 ``.
238
221
239
222
Besides the previously mentioned union, a number of other pointer-like types
240
223
have their own type:
241
224
242
- * **ObjCBlockPointer ** tracks Objective-C blocks
243
- * **FnPointer ** tracks functions and lazily caches their compiled version
225
+ * **FunctionPointer ** tracks functions.
244
226
* **MemberPointer ** tracks C++ object members
245
227
246
- Void pointers, which can be built by casting any of the aforementioned
247
- pointers, are implemented as a union of all pointer types. The ``BitCast ``
248
- opcode is responsible for performing all legal conversions between these
249
- types and primitive integers.
250
-
251
228
BlockPointer
252
229
~~~~~~~~~~~~
253
230
@@ -311,73 +288,9 @@ of ``a.c``, but its offset would point to ``&a.c[1]``. The
311
288
array-to-pointer decay operation adjusts a pointer to an array (where
312
289
the offset is equal to the base) to a pointer to the first element.
313
290
314
- ExternPointer
315
- ~~~~~~~~~~~~~
316
-
317
- Extern pointers can be derived, pointing into symbols which are not
318
- readable from constexpr. An external pointer consists of a base
319
- declaration, along with a path designating a subobject, similar to
320
- the ``LValuePath `` of an APValue. Extern pointers can be converted
321
- to block pointers if the underlying variable is defined after the
322
- pointer is created, as is the case in the following example:
323
-
324
- .. code-block :: c
325
-
326
- extern const int a;
327
- constexpr const int *p = &a;
328
- const int a = 5;
329
- static_assert(*p == 5, "x");
330
-
331
- TargetPointer
332
- ~~~~~~~~~~~~~
333
-
334
- While null pointer arithmetic or integer-to-pointer conversion is
335
- banned in constexpr, some expressions on target offsets must be folded,
336
- replicating the behaviour of the ``offsetof `` builtin. Target pointers
337
- are characterised by 3 offsets: a field offset, an array offset and a
338
- base offset, along with a descriptor specifying the type the pointer is
339
- supposed to refer to. Array indexing adjusts the array offset, while the
340
- field offset is adjusted when a pointer to a member is created. Casting
341
- an integer to a pointer sets the value of the base offset. As a special
342
- case, null pointers are target pointers with all offsets set to 0.
343
-
344
291
TypeInfoPointer
345
292
~~~~~~~~~~~~~~~
346
293
347
294
``TypeInfoPointer `` tracks two types: the type assigned to
348
295
``std::type_info `` and the type which was passed to ``typeinfo ``.
349
-
350
- InvalidPointer
351
- ~~~~~~~~~~~~~~
352
-
353
- Such pointers are built by operations which cannot generate valid
354
- pointers, allowing the interpreter to continue execution after emitting
355
- a warning. Inspecting such a pointer stops execution.
356
-
357
- TODO
358
- ====
359
-
360
- Missing Language Features
361
- -------------------------
362
-
363
- * Changing the active field of unions
364
- * ``volatile ``
365
- * ``__builtin_constant_p ``
366
- * ``dynamic_cast ``
367
- * ``new `` and ``delete ``
368
- * Fixed Point numbers and arithmetic on Complex numbers
369
- * Several builtin methods, including string operations and
370
- ``__builtin_bit_cast ``
371
- * Continue-after-failure: a form of exception handling at the bytecode
372
- level should be implemented to allow execution to resume. As an example,
373
- argument evaluation should resume after the computation of an argument fails.
374
- * Pointer-to-Integer conversions
375
- * Lazy descriptors: the interpreter creates a ``Record `` and ``Descriptor ``
376
- when it encounters a type: ones which are not yet defined should be lazily
377
- created when required
378
-
379
- Known Bugs
380
- ----------
381
-
382
- * If execution fails, memory storing APInts and APFloats is leaked when the
383
- stack is cleared
296
+ It is part of the taged union in ``Pointer ``.
0 commit comments