From b66981d19f1937e5b92e58dff2fe5f994f66d08f Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 13 Aug 2014 16:59:45 +0400 Subject: [PATCH] Introducing ecma_string_t type that will be used for ecma-strings instead of ecma_array_first_chunk_t. --- src/libecmaobjects/ecma-alloc.c | 1 + src/libecmaobjects/ecma-globals.h | 47 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/libecmaobjects/ecma-alloc.c b/src/libecmaobjects/ecma-alloc.c index d5ac5d4ee..86fbb135e 100644 --- a/src/libecmaobjects/ecma-alloc.c +++ b/src/libecmaobjects/ecma-alloc.c @@ -47,6 +47,7 @@ JERRY_STATIC_ASSERT(sizeof (ecma_object_t) <= 2 * sizeof (uint64_t)); JERRY_STATIC_ASSERT(sizeof (ecma_array_header_t) <= sizeof (uint32_t)); JERRY_STATIC_ASSERT(sizeof (ecma_array_first_chunk_t) == sizeof (uint64_t)); JERRY_STATIC_ASSERT(sizeof (ecma_array_non_first_chunk_t) == sizeof (uint64_t)); +JERRY_STATIC_ASSERT(sizeof (ecma_string_t) == sizeof (uint64_t)); JERRY_STATIC_ASSERT(sizeof (ecma_completion_value_t) == sizeof (uint32_t)); /** diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 8419915f8..b651c399f 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -521,6 +521,53 @@ typedef struct uint8_t data[ sizeof (uint64_t) - sizeof (uint16_t) ]; } ecma_array_non_first_chunk_t; +/** + * Identifier for ecma-string's actual data container + */ +typedef enum +{ + ECMA_STRING_CONTAINER_HEAP, /**< actual data is on the heap + in ecma_array_non_first_chunk_t */ + ECMA_STRING_CONTAINER_LIT_TABLE, /**< actual data is in literal table */ + ECMA_STRING_CONTAINER_IN_DESCRIPTOR /**< actual data is locally in the string's descriptor */ +} ecma_string_container_t; + +FIXME (Move to library that should define the type (libserializer /* ? */)) +/** + * Index in literal table + */ +typedef uint32_t literal_index_t; + +/** + * ECMA string-value descriptor + */ +typedef struct +{ + /** Reference counter for the string */ + unsigned int refs : CONFIG_ECMA_REFERENCE_COUNTER_WIDTH; + + /** Where the string's data is placed (ecma_string_container_t) */ + unsigned int container : 2; + + /** String's length */ + ecma_length_t length; + + /** + * Actual data or identifier of it's place in container (depending on 'container' field) + */ + union + { + /** Index of string in literal table */ + literal_index_t lit_index; + + /** Compressed pointer to array_non_first_chunk_t */ + unsigned int chunk_cp : ECMA_POINTER_FIELD_WIDTH; + + /** Actual data if placed locally in the descriptor */ + ecma_char_t chars[ sizeof (uint64_t) - sizeof (uint32_t) ]; + } u; +} ecma_string_t; + /** * \addtogroup reference ECMA-reference * @{