Create extend byte code flags with function types. (#3802)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-06-15 13:40:55 +02:00
committed by GitHub
parent fde0d556ac
commit 1b2e0aec8c
10 changed files with 197 additions and 109 deletions
+69 -17
View File
@@ -814,23 +814,75 @@ typedef struct
*/
typedef enum
{
CBC_CODE_FLAGS_FUNCTION = (1u << 0), /**< compiled code is JavaScript function */
CBC_CODE_FLAGS_FULL_LITERAL_ENCODING = (1u << 1), /**< full literal encoding mode is enabled */
CBC_CODE_FLAGS_UINT16_ARGUMENTS = (1u << 2), /**< compiled code data is cbc_uint16_arguments_t */
CBC_CODE_FLAGS_STRICT_MODE = (1u << 3), /**< strict mode is enabled */
CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED = (1u << 4), /**< mapped arguments object must be constructed */
CBC_CODE_FLAGS_UNMAPPED_ARGUMENTS_NEEDED = (1u << 5), /**< mapped arguments object must be constructed */
CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED = (1u << 6), /**< no need to create a lexical environment */
CBC_CODE_FLAGS_ARROW_FUNCTION = (1u << 7), /**< this function is an arrow function */
CBC_CODE_FLAGS_STATIC_FUNCTION = (1u << 8), /**< this function is a static snapshot function */
CBC_CODE_FLAGS_DEBUGGER_IGNORE = (1u << 9), /**< this function should be ignored by debugger */
CBC_CODE_FLAGS_CLASS_CONSTRUCTOR = (1u << 10), /**< this function is a class constructor */
CBC_CODE_FLAGS_GENERATOR = (1u << 11), /**< this function is a generator */
CBC_CODE_FLAGS_REST_PARAMETER = (1u << 12), /**< this function has rest parameter */
CBC_CODE_FLAG_HAS_TAGGED_LITERALS = (1u << 13), /**< this function has tagged template literal list */
CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED = (1u << 14), /**< compiled code needs a lexical block */
CBC_CODE_FLAGS_ACCESSOR = (1u << 15) /**< accessor propety 'get' and 'set' functions */
} cbc_code_flags;
CBC_CODE_FLAGS_FULL_LITERAL_ENCODING = (1u << 0), /**< full literal encoding mode is enabled */
CBC_CODE_FLAGS_UINT16_ARGUMENTS = (1u << 1), /**< compiled code data is cbc_uint16_arguments_t */
CBC_CODE_FLAGS_STRICT_MODE = (1u << 2), /**< strict mode is enabled */
CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED = (1u << 3), /**< mapped arguments object must be constructed */
CBC_CODE_FLAGS_UNMAPPED_ARGUMENTS_NEEDED = (1u << 4), /**< mapped arguments object must be constructed */
CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED = (1u << 5), /**< no need to create a lexical environment */
CBC_CODE_FLAGS_STATIC_FUNCTION = (1u << 6), /**< this function is a static snapshot function */
CBC_CODE_FLAGS_DEBUGGER_IGNORE = (1u << 7), /**< this function should be ignored by debugger */
CBC_CODE_FLAGS_REST_PARAMETER = (1u << 8), /**< this function has rest parameter */
CBC_CODE_FLAGS_HAS_TAGGED_LITERALS = (1u << 9), /**< this function has tagged template literal list */
CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED = (1u << 10), /**< compiled code needs a lexical block */
/* Bits from bit 13 is reserved for function types (see CBC_FUNCTION_TYPE_SHIFT).
* Note: the last bits are used for type flags because < and >= operators can be used to
check a range of types without decoding the actual type. */
} cbc_code_flags_t;
/**
* Compact byte code function types.
*/
typedef enum
{
/* The first type must be regular expression (see CBC_IS_FUNCTION) */
CBC_REGULAR_EXPRESSION, /**< regular expression literal */
CBC_FUNCTION_NORMAL, /**< function without special properties */
CBC_FUNCTION_CONSTRUCTOR, /**< constructor function */
/* The following functions cannot be constructed (see CBC_FUNCTION_IS_CONSTRUCTABLE) */
CBC_FUNCTION_GENERATOR, /**< generator function */
/* The following functions has no prototype (see CBC_FUNCTION_HAS_PROTOTYPE) */
CBC_FUNCTION_ARROW, /**< arrow function */
CBC_FUNCTION_ACCESSOR, /**< property accessor function */
} cbc_code_function_types_t;
/**
* Shift for getting / setting the function type of a byte code.
*/
#define CBC_FUNCTION_TYPE_SHIFT 13
/**
* Compute function type bits in code flags.
*/
#define CBC_FUNCTION_TO_TYPE_BITS(name) \
((name) << CBC_FUNCTION_TYPE_SHIFT)
/**
* Get function type from code flags.
*/
#define CBC_FUNCTION_GET_TYPE(flags) \
((uint16_t) ((flags) >> CBC_FUNCTION_TYPE_SHIFT))
/**
* Checks whether the byte code is a function or a regular expression.
*/
#define CBC_IS_FUNCTION(flags) \
((flags) >= (CBC_FUNCTION_NORMAL << CBC_FUNCTION_TYPE_SHIFT))
/**
* Checks whether the function can be constructed with new operator.
*/
#define CBC_FUNCTION_IS_CONSTRUCTABLE(flags) \
((flags) < (CBC_FUNCTION_GENERATOR << CBC_FUNCTION_TYPE_SHIFT))
/**
* Checks whether the function has prototype property.
*/
#define CBC_FUNCTION_HAS_PROTOTYPE(flags) \
((flags) < (CBC_FUNCTION_ARROW << CBC_FUNCTION_TYPE_SHIFT))
/**
* Any arguments object is needed
+39 -24
View File
@@ -675,19 +675,28 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
}
#if ENABLED (JERRY_ESNEXT)
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION)
switch (CBC_FUNCTION_GET_TYPE (compiled_code_p->status_flags))
{
JERRY_DEBUG_MSG (",arrow");
}
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR)
{
JERRY_DEBUG_MSG (",constructor");
}
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_GENERATOR)
{
JERRY_DEBUG_MSG (",generator");
case CBC_FUNCTION_CONSTRUCTOR:
{
JERRY_DEBUG_MSG (",constructor");
break;
}
case CBC_FUNCTION_GENERATOR:
{
JERRY_DEBUG_MSG (",generator");
break;
}
case CBC_FUNCTION_ARROW:
{
JERRY_DEBUG_MSG (",arrow");
break;
}
case CBC_FUNCTION_ACCESSOR:
{
JERRY_DEBUG_MSG (",accessor");
break;
}
}
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -1238,7 +1247,12 @@ parser_post_processing (parser_context_t *context_p) /**< context */
byte_code_p = (uint8_t *) compiled_code_p;
compiled_code_p->size = (uint16_t) (total_size >> JMEM_ALIGNMENT_LOG);
compiled_code_p->refs = 1;
compiled_code_p->status_flags = CBC_CODE_FLAGS_FUNCTION;
#if ENABLED (JERRY_ESNEXT)
compiled_code_p->status_flags = 0;
#else /* !ENABLED (JERRY_ESNEXT) */
compiled_code_p->status_flags = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_ESNEXT)
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
@@ -1319,22 +1333,23 @@ parser_post_processing (parser_context_t *context_p) /**< context */
#if ENABLED (JERRY_ESNEXT)
if (context_p->status_flags & (PARSER_IS_PROPERTY_GETTER | PARSER_IS_PROPERTY_SETTER))
{
compiled_code_p->status_flags |= CBC_CODE_FLAGS_ACCESSOR;
compiled_code_p->status_flags |= CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ACCESSOR);
}
if (context_p->status_flags & PARSER_IS_ARROW_FUNCTION)
else if (context_p->status_flags & PARSER_IS_ARROW_FUNCTION)
{
compiled_code_p->status_flags |= CBC_CODE_FLAGS_ARROW_FUNCTION;
compiled_code_p->status_flags |= CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ARROW);
}
if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)
else if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)
{
compiled_code_p->status_flags |= CBC_CODE_FLAGS_CLASS_CONSTRUCTOR;
compiled_code_p->status_flags |= CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_CONSTRUCTOR);
}
if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION)
else if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION)
{
compiled_code_p->status_flags |= CBC_CODE_FLAGS_GENERATOR;
compiled_code_p->status_flags |= CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_GENERATOR);
}
else
{
compiled_code_p->status_flags |= CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);
}
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
@@ -1344,7 +1359,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
if (context_p->tagged_template_literal_cp != JMEM_CP_NULL)
{
compiled_code_p->status_flags |= CBC_CODE_FLAG_HAS_TAGGED_LITERALS;
compiled_code_p->status_flags |= CBC_CODE_FLAGS_HAS_TAGGED_LITERALS;
}
if (context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED)