Implement ES2015 class feature (part I.) (#2404)

This patch is the first milestone of the implementation of this new language element.

Currently supported:
 - Class statement
 - Class expression
 - Static methods

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2018-07-12 18:20:08 +02:00
committed by yichoi
parent 62cdb3965f
commit 43aae199ce
18 changed files with 779 additions and 15 deletions
+21 -4
View File
@@ -34,9 +34,11 @@
* @return configuration flags
*/
static inline uint32_t JERRY_ATTR_ALWAYS_INLINE
snapshot_get_global_flags (bool has_regex) /**< regex literal is present */
snapshot_get_global_flags (bool has_regex, /**< regex literal is present */
bool has_class) /**< class literal is present */
{
JERRY_UNUSED (has_regex);
JERRY_UNUSED (has_class);
uint32_t flags = 0;
@@ -45,7 +47,10 @@ snapshot_get_global_flags (bool has_regex) /**< regex literal is present */
#endif /* JERRY_CPOINTER_32_BIT */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
flags |= (has_regex ? JERRY_SNAPSHOT_HAS_REGEX_LITERAL : 0);
#endif /* CONFIG_DISABLE_REGEXP_BUILTIN */
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
#ifndef CONFIG_DISABLE_ES2015_CLASS
flags |= (has_class ? JERRY_SNAPSHOT_HAS_CLASS_LITERAL : 0);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return flags;
} /* snapshot_get_global_flags */
@@ -61,8 +66,11 @@ snapshot_check_global_flags (uint32_t global_flags) /**< global flags */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_REGEX_LITERAL;
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
#ifndef CONFIG_DISABLE_ES2015_CLASS
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_CLASS_LITERAL;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return global_flags == snapshot_get_global_flags (false);
return global_flags == snapshot_get_global_flags (false, false);
} /* snapshot_check_global_flags */
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE || JERRY_ENABLE_SNAPSHOT_EXEC */
@@ -77,6 +85,7 @@ typedef struct
size_t snapshot_buffer_write_offset;
ecma_value_t snapshot_error;
bool regex_found;
bool class_found;
} snapshot_globals_t;
/** \addtogroup jerrysnapshot Jerry snapshot operations
@@ -154,6 +163,13 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
uint8_t *copied_code_start_p = snapshot_buffer_p + globals_p->snapshot_buffer_write_offset;
ecma_compiled_code_t *copied_code_p = (ecma_compiled_code_t *) copied_code_start_p;
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
{
globals_p->class_found = true;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
{
@@ -739,6 +755,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
globals.snapshot_buffer_write_offset = aligned_header_size;
globals.snapshot_error = ECMA_VALUE_EMPTY;
globals.regex_found = false;
globals.class_found = false;
parse_status = parser_parse_script (args_p,
args_size,
@@ -769,7 +786,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
jerry_snapshot_header_t header;
header.magic = JERRY_SNAPSHOT_MAGIC;
header.version = JERRY_SNAPSHOT_VERSION;
header.global_flags = snapshot_get_global_flags (globals.regex_found);
header.global_flags = snapshot_get_global_flags (globals.regex_found, globals.class_found);
header.lit_table_offset = (uint32_t) globals.snapshot_buffer_write_offset;
header.number_of_funcs = 1;
header.func_offsets[0] = aligned_header_size;
+2 -1
View File
@@ -41,7 +41,7 @@ typedef struct
/**
* Jerry snapshot format version.
*/
#define JERRY_SNAPSHOT_VERSION (14u)
#define JERRY_SNAPSHOT_VERSION (15u)
/**
* Snapshot configuration flags.
@@ -50,6 +50,7 @@ typedef enum
{
/* 8 bits are reserved for dynamic features */
JERRY_SNAPSHOT_HAS_REGEX_LITERAL = (1u << 0), /**< byte code has regex literal */
JERRY_SNAPSHOT_HAS_CLASS_LITERAL = (1u << 1), /**< byte code has class literal */
/* 24 bits are reserved for compile time features */
JERRY_SNAPSHOT_FOUR_BYTE_CPOINTER = (1u << 8) /**< compressed pointers are four byte long */
} jerry_snapshot_global_flags_t;