diff --git a/src/libecmaobjects/ecma-alloc.c b/src/libecmaobjects/ecma-alloc.c index 9457c2993..c9abeaec7 100644 --- a/src/libecmaobjects/ecma-alloc.c +++ b/src/libecmaobjects/ecma-alloc.c @@ -30,6 +30,7 @@ JERRY_STATIC_ASSERT (sizeof (ecma_collection_header_t) == sizeof (uint64_t)); JERRY_STATIC_ASSERT (sizeof (ecma_collection_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)); +JERRY_STATIC_ASSERT (sizeof (ecma_label_descriptor_t) == sizeof (uint64_t)); /** \addtogroup ecma ECMA * @{ @@ -101,6 +102,7 @@ DECLARE_ROUTINES_FOR (number) DECLARE_ROUTINES_FOR (collection_header) DECLARE_ROUTINES_FOR (collection_chunk) DECLARE_ROUTINES_FOR (string) +DECLARE_ROUTINES_FOR (label_descriptor) /** * @} diff --git a/src/libecmaobjects/ecma-alloc.h b/src/libecmaobjects/ecma-alloc.h index d6ce1f7e7..0441a4063 100644 --- a/src/libecmaobjects/ecma-alloc.h +++ b/src/libecmaobjects/ecma-alloc.h @@ -97,6 +97,18 @@ extern ecma_string_t *ecma_alloc_string (void); */ extern void ecma_dealloc_string (ecma_string_t *string_p); +/** + * Allocate memory for label descriptor + * + * @return pointer to allocated memory + */ +extern ecma_label_descriptor_t *ecma_alloc_label_descriptor (void); + +/** + * Dealloc memory from label descriptor + */ +extern void ecma_dealloc_label_descriptor (ecma_label_descriptor_t *label_desc_p); + #endif /* JERRY_ECMA_ALLOC_H */ /** diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 00a5a98b8..1c1f79c1a 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -132,7 +132,10 @@ typedef struct typedef struct { /** Type (ecma_completion_type_t) */ - unsigned int type : 8; + uint8_t type; + + /** Just padding for the structure */ + uint8_t padding; union { @@ -148,16 +151,23 @@ typedef struct * * Used for break and continue completion types. */ - struct - { - /** Levels to label left */ - uint8_t depth; + uint16_t label_desc_cp; + } u; +} ecma_completion_value_t; - /** Target's offset */ - uint16_t offset; - } __packed target; - } __packed u; -} __packed ecma_completion_value_t; +/** + * Label + * + * Used for break and continue completion types. + */ +typedef struct +{ + /** Target's offset */ + uint32_t offset; + + /** Levels to label left */ + uint32_t depth; +} ecma_label_descriptor_t; /** * Target value indicating that target field diff --git a/src/libecmaobjects/ecma-helpers-value.c b/src/libecmaobjects/ecma-helpers-value.c index 1a2905e9d..b276d1815 100644 --- a/src/libecmaobjects/ecma-helpers-value.c +++ b/src/libecmaobjects/ecma-helpers-value.c @@ -319,9 +319,15 @@ ecma_make_label_completion_value (ecma_completion_type_t type, /**< type */ ecma_completion_value_t ret_value; + ecma_label_descriptor_t *label_desc_p = ecma_alloc_label_descriptor (); + *label_desc_p = (ecma_label_descriptor_t) + { + .offset = offset, + .depth = depth_level + }; + ret_value.type = type; - ret_value.u.target.depth = depth_level; - ret_value.u.target.offset = offset; + ECMA_SET_POINTER (ret_value.u.label_desc_cp, label_desc_p); return ret_value; } /* ecma_make_label_completion_value */ @@ -470,6 +476,10 @@ ecma_free_completion_value (ecma_completion_value_t completion_value) /**< compl } case ECMA_COMPLETION_TYPE_CONTINUE: case ECMA_COMPLETION_TYPE_BREAK: + { + ecma_dealloc_label_descriptor (ECMA_GET_POINTER (completion_value.u.label_desc_cp)); + break; + } case ECMA_COMPLETION_TYPE_META: { JERRY_UNREACHABLE ();