From 9e1e32361f2dbd29e47b459fd955020dab09b75e Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sun, 5 Jun 2016 17:04:19 +0300 Subject: [PATCH] Add some more type notes --- doc/types.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/doc/types.rst b/doc/types.rst index f8b03401..b7301064 100644 --- a/doc/types.rst +++ b/doc/types.rst @@ -2,6 +2,11 @@ Duktape typing ============== +Typing overview +=============== + +TBD. + Internal and external type summary ================================== @@ -123,3 +128,31 @@ API and internals. What's missing from the table: +----------------------------+---------------------+------------------------+-----------------------+-------------------------+-------------------------------------+-------------------+-------------------------------+-----------------------------------+ | new Float64Array(1) | DUK_TYPE_OBJECT | duk_is_object() | DUK_TAG_OBJECT | duk_hbufobj | DUK_HOBJECT_CLASS_FLOAT64ARRAY | object | [object Float64Array] | | +----------------------------+---------------------+------------------------+-----------------------+-------------------------+-------------------------------------+-------------------+-------------------------------+-----------------------------------+ + +Options for representing a value +================================ + +There are four basic alternatives to representing a value: + +* **A tagged type with no heap allocation**. This is the lowest footprint + alternative, and memory usage is 8 bytes (for a packed ``duk_tval``) or + (typically) 16 bytes (for a non-packed ``duk_tval``). Example: undefined, + null, boolean, number, pointer. + +* **A heap allocated custom struct**. A tagged value points to a heap + allocated C struct which is customized for a certain purpose. Flags in + the object header allow a base C struct to be extended in certain cases. + Example: fixed buffer, dynamic buffer, external buffer, string. + +* **A heap allocated object**. A tagged value points to a ``duk_hobject``. + Because a ``duk_hobject`` has a property table, type specific values can + be easily added to the property table, but properties have a relatively + high cost. Example: plain Ecmascript object. + +* **A heap allocated extended object**. A tagged value points to a struct + extending ``duk_hobject``. Flags in the shared ``duk_hobject`` header + allow Duktape internals to detect the extended type and to access further + fields in an extended C struct. The extended values may only be available + internally, but may also be accessible via property reads if the properties + are virtualized. Example: Ecmascript function, Duktape/C function, thread, + buffer object.