Replace array of literals with literal storage.

JerryScript-DCO-1.0-Signed-off-by: Evgeny Gavrin e.gavrin@samsung.com
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-06-10 17:28:53 +03:00
parent 340a9ef002
commit 53801e3b41
36 changed files with 460 additions and 1097 deletions
+2 -9
View File
@@ -758,20 +758,13 @@ typedef enum
} ecma_string_container_t; } ecma_string_container_t;
FIXME (Move to library that should define the type (literal.h /* ? */)) FIXME (Move to library that should define the type (literal.h /* ? */))
/** /**
* Literal and compressed pointer to literal * Literal and compressed pointer to literal
*/ */
typedef rcs_record_t *literal_t; typedef rcs_record_t *literal_t;
typedef rcs_cpointer_t lit_cpointer_t; typedef rcs_cpointer_t lit_cpointer_t;
/**
* Index in literal table
*
* FIXME: Remove after switching to literal storage
*/
typedef uint32_t literal_index_t;
/** /**
* Identifiers of ECMA and implementation-defined magic string constants * Identifiers of ECMA and implementation-defined magic string constants
*/ */
@@ -824,7 +817,7 @@ typedef struct ecma_string_t
union union
{ {
/** Index of string in literal table */ /** Index of string in literal table */
literal_index_t lit_index; lit_cpointer_t lit_cp;
/** Compressed pointer to an ecma_collection_header_t */ /** Compressed pointer to an ecma_collection_header_t */
mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH; mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
+71 -93
View File
@@ -66,9 +66,9 @@ static ecma_length_t ecma_magic_string_max_length;
#endif /* !JERRY_NDEBUG */ #endif /* !JERRY_NDEBUG */
static void static void
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p, ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p,
literal_index_t lit_index, lit_cpointer_t lit_index,
bool is_stack_var); bool is_stack_var);
static void static void
ecma_init_ecma_string_from_magic_string_id (ecma_string_t *string_p, ecma_init_ecma_string_from_magic_string_id (ecma_string_t *string_p,
ecma_magic_string_id_t magic_string_id, ecma_magic_string_id_t magic_string_id,
@@ -370,42 +370,42 @@ ecma_get_magic_string_ex_count (void)
* Initialize ecma-string descriptor with string described by index in literal table * Initialize ecma-string descriptor with string described by index in literal table
*/ */
static void static void
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p, /**< descriptor to initialize */ ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, /**< descriptor to initialize */
literal_index_t lit_index, /**< index in the literal table */ lit_cpointer_t lit_cp, /**< compressed pointer to literal */
bool is_stack_var) /**< flag indicating whether the string descriptor bool is_stack_var) /**< flag indicating whether the string descriptor
is placed on stack (true) or in the heap (false) */ is placed on stack (true) or in the heap (false) */
{ {
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
JERRY_ASSERT (is_stack_var == (!mem_is_heap_pointer (string_p))); JERRY_ASSERT (is_stack_var == (!mem_is_heap_pointer (string_p)));
#endif /* !JERRY_NDEBUG */ #endif /* !JERRY_NDEBUG */
const literal lit = serializer_get_literal_by_id (lit_index); literal_t lit = lit_get_literal_by_cp (lit_cp);
if (lit.type == LIT_MAGIC_STR) if (lit->get_type () == LIT_MAGIC_STR_T)
{ {
ecma_init_ecma_string_from_magic_string_id (string_p, ecma_init_ecma_string_from_magic_string_id (string_p,
lit.data.magic_str_id, lit_magic_record_get_magic_str_id (lit),
is_stack_var); is_stack_var);
return; return;
} }
else if (lit.type == LIT_MAGIC_STR_EX) else if (lit->get_type () == LIT_MAGIC_STR_EX_T)
{ {
ecma_init_ecma_string_from_magic_string_ex_id (string_p, ecma_init_ecma_string_from_magic_string_ex_id (string_p,
lit.data.magic_str_ex_id, lit_magic_record_ex_get_magic_str_id (lit),
is_stack_var); is_stack_var);
return; return;
} }
JERRY_ASSERT (lit.type == LIT_STR);
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
string_p->refs = 1; string_p->refs = 1;
string_p->is_stack_var = (is_stack_var != 0); string_p->is_stack_var = (is_stack_var != 0);
string_p->container = ECMA_STRING_CONTAINER_LIT_TABLE; string_p->container = ECMA_STRING_CONTAINER_LIT_TABLE;
string_p->hash = lit.data.lp.hash; string_p->hash = lit_charset_literal_get_hash (lit);
string_p->u.common_field = 0; string_p->u.common_field = 0;
string_p->u.lit_index = lit_index; string_p->u.lit_cp = lit_cp;
} /* ecma_init_ecma_string_from_lit_index */ } /* ecma_init_ecma_string_from_lit_cp */
/** /**
* Initialize ecma-string descriptor with specified magic string * Initialize ecma-string descriptor with specified magic string
@@ -591,12 +591,12 @@ ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */
* with string described by index in literal table * with string described by index in literal table
*/ */
void void
ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p, /**< pointer to the ecma-string ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p, /**< pointer to the ecma-string
descriptor to initialize */ descriptor to initialize */
literal_index_t lit_index) /**< index in the literal table */ lit_cpointer_t lit_cp) /**< compressed pointer to literal */
{ {
ecma_init_ecma_string_from_lit_index (string_p, lit_index, true); ecma_init_ecma_string_from_lit_cp (string_p, lit_cp, true);
} /* ecma_new_ecma_string_on_stack_from_lit_index */ } /* ecma_new_ecma_string_on_stack_from_lit_cp */
/** /**
* Allocate new ecma-string and fill it with reference to string literal * Allocate new ecma-string and fill it with reference to string literal
@@ -604,14 +604,14 @@ ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p, /**< poin
* @return pointer to ecma-string descriptor * @return pointer to ecma-string descriptor
*/ */
ecma_string_t* ecma_string_t*
ecma_new_ecma_string_from_lit_index (literal_index_t lit_index) /**< index in the literal table */ ecma_new_ecma_string_from_lit_cp (lit_cpointer_t lit_cp) /**< index in the literal table */
{ {
ecma_string_t* string_desc_p = ecma_alloc_string (); ecma_string_t* string_desc_p = ecma_alloc_string ();
ecma_init_ecma_string_from_lit_index (string_desc_p, lit_index, false); ecma_init_ecma_string_from_lit_cp (string_desc_p, lit_cp, false);
return string_desc_p; return string_desc_p;
} /* ecma_new_ecma_string_from_lit_index */ } /* ecma_new_ecma_string_from_lit_cp */
/** /**
* Initialize ecma-string descriptor placed on stack with specified magic string * Initialize ecma-string descriptor placed on stack with specified magic string
@@ -1037,13 +1037,9 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d
} }
case ECMA_STRING_CONTAINER_LIT_TABLE: case ECMA_STRING_CONTAINER_LIT_TABLE:
{ {
const literal lit = serializer_get_literal_by_id (string_desc_p->u.lit_index); literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
JERRY_ASSERT (lit.type == LIT_STR); JERRY_ASSERT (lit->get_type () == LIT_STR_T);
const ecma_char_t *str_p = literal_to_zt (lit); lit_literal_to_charset (lit, buffer_p, (size_t) required_buffer_size);
JERRY_ASSERT (str_p != NULL);
ecma_copy_zt_string_to_buffer (str_p, buffer_p, required_buffer_size);
break; break;
} }
case ECMA_STRING_CONTAINER_UINT32_IN_DESC: case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
@@ -1141,7 +1137,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
{ {
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE)
{ {
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index); JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value);
return false; return false;
} }
@@ -1214,7 +1210,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
} }
case ECMA_STRING_CONTAINER_LIT_TABLE: case ECMA_STRING_CONTAINER_LIT_TABLE:
{ {
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index); JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value);
return false; return false;
} }
@@ -1346,74 +1342,56 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
ecma_char_t zt_string1_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1]; ecma_char_t zt_string1_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
ecma_char_t zt_string2_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1]; ecma_char_t zt_string2_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) ssize_t req_size = ecma_string_to_zt_string (string1_p,
zt_string1_buffer,
sizeof (zt_string1_buffer));
if (req_size < 0)
{ {
const literal lit = serializer_get_literal_by_id (string1_p->u.lit_index); ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
JERRY_ASSERT (lit.type == LIT_STR); if (heap_buffer_p == NULL)
zt_string1_p = literal_to_zt (lit); {
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p,
heap_buffer_p,
-req_size);
JERRY_ASSERT (bytes_copied > 0);
zt_string1_p = heap_buffer_p;
is_zt_string1_on_heap = true;
} }
else else
{ {
ssize_t req_size = ecma_string_to_zt_string (string1_p, zt_string1_p = zt_string1_buffer;
zt_string1_buffer,
sizeof (zt_string1_buffer));
if (req_size < 0)
{
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
if (heap_buffer_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p,
heap_buffer_p,
-req_size);
JERRY_ASSERT (bytes_copied > 0);
zt_string1_p = heap_buffer_p;
is_zt_string1_on_heap = true;
}
else
{
zt_string1_p = zt_string1_buffer;
}
} }
if (string2_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) req_size = ecma_string_to_zt_string (string2_p,
zt_string2_buffer,
sizeof (zt_string2_buffer));
if (req_size < 0)
{ {
const literal lit = serializer_get_literal_by_id (string2_p->u.lit_index); ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
JERRY_ASSERT (lit.type == LIT_STR); if (heap_buffer_p == NULL)
zt_string2_p = literal_to_zt (lit); {
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p,
heap_buffer_p,
-req_size);
JERRY_ASSERT (bytes_copied > 0);
zt_string2_p = heap_buffer_p;
is_zt_string2_on_heap = true;
} }
else else
{ {
ssize_t req_size = ecma_string_to_zt_string (string2_p, zt_string2_p = zt_string2_buffer;
zt_string2_buffer,
sizeof (zt_string2_buffer));
if (req_size < 0)
{
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
if (heap_buffer_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p,
heap_buffer_p,
-req_size);
JERRY_ASSERT (bytes_copied > 0);
zt_string2_p = heap_buffer_p;
is_zt_string2_on_heap = true;
}
else
{
zt_string2_p = zt_string2_buffer;
}
} }
bool is_first_less_than_second = ecma_compare_zt_strings_relational (zt_string1_p, bool is_first_less_than_second = ecma_compare_zt_strings_relational (zt_string1_p,
@@ -1445,9 +1423,9 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
if (container == ECMA_STRING_CONTAINER_LIT_TABLE) if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
{ {
const literal lit = serializer_get_literal_by_id (string_p->u.lit_index); literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
return lit.data.lp.length; return lit_charset_record_get_length (lit);
} }
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING) else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
{ {
+3 -3
View File
@@ -112,9 +112,9 @@ extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p); extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number); extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number); extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number);
extern void ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p, extern void ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p,
literal_index_t lit_index); lit_cpointer_t lit_index);
extern ecma_string_t* ecma_new_ecma_string_from_lit_index (literal_index_t lit_index); extern ecma_string_t *ecma_new_ecma_string_from_lit_cp (lit_cpointer_t lit_cp);
extern void ecma_new_ecma_string_on_stack_from_magic_string_id (ecma_string_t *string_p, extern void ecma_new_ecma_string_on_stack_from_magic_string_id (ecma_string_t *string_p,
ecma_magic_string_id_t id); ecma_magic_string_id_t id);
extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id); extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id);
@@ -18,14 +18,12 @@
#include "ecma-exceptions.h" #include "ecma-exceptions.h"
#include "ecma-function-object.h" #include "ecma-function-object.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-lex-env.h" #include "ecma-lex-env.h"
#include "ecma-objects.h" #include "ecma-objects.h"
#include "ecma-objects-general.h" #include "ecma-objects-general.h"
#include "ecma-objects-arguments.h" #include "ecma-objects-arguments.h"
#include "ecma-try-catch-macro.h" #include "ecma-try-catch-macro.h"
#include "jrt.h"
#define JERRY_INTERNAL #define JERRY_INTERNAL
#include "jerry-internal.h" #include "jerry-internal.h"
-5
View File
@@ -26,13 +26,8 @@
#include "ecma-init-finalize.h" #include "ecma-init-finalize.h"
#include "ecma-objects.h" #include "ecma-objects.h"
#include "ecma-objects-general.h" #include "ecma-objects-general.h"
#include "jerry.h"
#include "jrt.h"
#include "mem-heap.h"
#include "mem-poolman.h"
#include "parser.h" #include "parser.h"
#include "serializer.h" #include "serializer.h"
#include "vm.h"
#define JERRY_INTERNAL #define JERRY_INTERNAL
#include "jerry-internal.h" #include "jerry-internal.h"
+34 -4
View File
@@ -15,6 +15,7 @@
#include "lit-literal-storage.h" #include "lit-literal-storage.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "lit-literal.h"
/** /**
* Literal storage * Literal storage
@@ -258,12 +259,25 @@ lit_magic_record_t *
lit_literal_storage_t::create_magic_record (ecma_magic_string_id_t id) /**< id of a magic string */ lit_literal_storage_t::create_magic_record (ecma_magic_string_id_t id) /**< id of a magic string */
{ {
lit_magic_record_t *ret = alloc_record<lit_magic_record_t> (LIT_MAGIC_STR); lit_magic_record_t *ret = alloc_record<lit_magic_record_t> (LIT_MAGIC_STR);
ret->set_magic_str_id (id); ret->set_magic_str_id (id);
return ret; return ret;
} /* lit_literal_storage_t::create_magic_record */ } /* lit_literal_storage_t::create_magic_record */
/**
* Create external magic string record in the literal storage
*
* @return pointer to the created record
*/
lit_magic_record_t *
lit_literal_storage_t::create_magic_record_ex (ecma_magic_string_ex_id_t id) /**< id of a magic string */
{
lit_magic_record_t *ret = alloc_record<lit_magic_record_t> (LIT_MAGIC_STR_EX);
ret->set_magic_str_id (id);
return ret;
} /* lit_literal_storage_t::create_magic_record_ex */
/** /**
* Create number record in the literal storage * Create number record in the literal storage
* *
@@ -315,10 +329,17 @@ lit_literal_storage_t::dump ()
} }
case LIT_MAGIC_STR: case LIT_MAGIC_STR:
{ {
lit_magic_record_t *lit_p = static_cast<lit_magic_record_t *> (rec_p); ecma_magic_string_id_t id = lit_magic_record_get_magic_str_id (rec_p);
printf ("%s : MAGIC STRING", ecma_get_magic_string_zt (id));
printf (" [id=%d] ", id);
printf ("%s : MAGIC STRING", ecma_get_magic_string_zt (lit_p->get_magic_str_id ())); break;
printf (" [id=%d] ", lit_p->get_magic_str_id ()); }
case LIT_MAGIC_STR_EX:
{
ecma_magic_string_ex_id_t id = lit_magic_record_ex_get_magic_str_id (rec_p);
printf ("%s : EXT MAGIC STRING", ecma_get_magic_string_ex_zt (id));
printf (" [id=%d] ", id);
break; break;
} }
@@ -364,6 +385,7 @@ lit_literal_storage_t::get_prev (rcs_record_t *rec_p) /**< record, relative to w
return (static_cast<lit_charset_record_t *> (rec_p))->get_prev (); return (static_cast<lit_charset_record_t *> (rec_p))->get_prev ();
} }
case LIT_MAGIC_STR: case LIT_MAGIC_STR:
case LIT_MAGIC_STR_EX:
{ {
return (static_cast<lit_magic_record_t *> (rec_p))->get_prev (); return (static_cast<lit_magic_record_t *> (rec_p))->get_prev ();
} }
@@ -394,6 +416,7 @@ lit_literal_storage_t::set_prev (rcs_record_t *rec_p, /**< record to modify */
return (static_cast<lit_charset_record_t *> (rec_p))->set_prev (prev_rec_p); return (static_cast<lit_charset_record_t *> (rec_p))->set_prev (prev_rec_p);
} }
case LIT_MAGIC_STR: case LIT_MAGIC_STR:
case LIT_MAGIC_STR_EX:
{ {
return (static_cast<lit_magic_record_t *> (rec_p))->set_prev (prev_rec_p); return (static_cast<lit_magic_record_t *> (rec_p))->set_prev (prev_rec_p);
} }
@@ -425,6 +448,7 @@ lit_literal_storage_t::get_record_size (rcs_record_t* rec_p) /**< pointer to a r
return (static_cast<lit_charset_record_t *> (rec_p))->get_size (); return (static_cast<lit_charset_record_t *> (rec_p))->get_size ();
} }
case LIT_MAGIC_STR: case LIT_MAGIC_STR:
case LIT_MAGIC_STR_EX:
{ {
return lit_magic_record_t::size (); return lit_magic_record_t::size ();
} }
@@ -454,7 +478,13 @@ template ecma_number_t rcs_record_iterator_t::read<ecma_number_t> ();
template void rcs_record_iterator_t::write<uint16_t> (uint16_t); template void rcs_record_iterator_t::write<uint16_t> (uint16_t);
template uint16_t rcs_record_iterator_t::read<uint16_t> (); template uint16_t rcs_record_iterator_t::read<uint16_t> ();
template ecma_magic_string_id_t lit_magic_record_t::get_magic_str_id<ecma_magic_string_id_t>() const;
template ecma_magic_string_ex_id_t lit_magic_record_t::get_magic_str_id<ecma_magic_string_ex_id_t>() const;
template void lit_magic_record_t::set_magic_str_id<ecma_magic_string_id_t>(ecma_magic_string_id_t);
template void lit_magic_record_t::set_magic_str_id<ecma_magic_string_ex_id_t>(ecma_magic_string_ex_id_t);
template lit_charset_record_t *rcs_recordset_t::alloc_record<lit_charset_record_t> (rcs_record_t::type_t type, template lit_charset_record_t *rcs_recordset_t::alloc_record<lit_charset_record_t> (rcs_record_t::type_t type,
size_t size); size_t size);
template lit_magic_record_t *rcs_recordset_t::alloc_record<lit_magic_record_t> (rcs_record_t::type_t type); template lit_magic_record_t *rcs_recordset_t::alloc_record<lit_magic_record_t> (rcs_record_t::type_t type);
template lit_number_record_t *rcs_recordset_t::alloc_record<lit_number_record_t> (rcs_record_t::type_t type); template lit_number_record_t *rcs_recordset_t::alloc_record<lit_number_record_t> (rcs_record_t::type_t type);
+9 -5
View File
@@ -238,11 +238,12 @@ public:
* *
* @return magic string id * @return magic string id
*/ */
ecma_magic_string_id_t get_magic_str_id () const template <typename magic_string_id_t>
magic_string_id_t get_magic_str_id () const
{ {
uint32_t id = get_field (magic_field_pos, magic_field_width); uint32_t id = get_field (magic_field_pos, magic_field_width);
JERRY_ASSERT (id < ECMA_MAGIC_STRING__COUNT); // JERRY_ASSERT (id < ECMA_MAGIC_STRING__COUNT);
return (ecma_magic_string_id_t) id; return (magic_string_id_t) id;
} /* get_magic_str_id */ } /* get_magic_str_id */
private: private:
@@ -254,7 +255,8 @@ private:
JERRY_ASSERT (size == get_size ()); JERRY_ASSERT (size == get_size ());
} /* set_size */ } /* set_size */
void set_magic_str_id (ecma_magic_string_id_t id) template <typename magic_string_id_t>
void set_magic_str_id (magic_string_id_t id)
{ {
set_field (magic_field_pos, magic_field_width, id); set_field (magic_field_pos, magic_field_width, id);
} /* set_magic_str_id */ } /* set_magic_str_id */
@@ -294,7 +296,6 @@ private:
static const size_t _size = RCS_DYN_STORAGE_LENGTH_UNIT; static const size_t _size = RCS_DYN_STORAGE_LENGTH_UNIT;
}; /* lit_magic_record_t */ }; /* lit_magic_record_t */
/** /**
* Number record * Number record
* Doesn't hold any characters, holds a number. Numbers from source code are represented as number literals. * Doesn't hold any characters, holds a number. Numbers from source code are represented as number literals.
@@ -412,11 +413,13 @@ public:
{ {
LIT_STR = _first_type_id, LIT_STR = _first_type_id,
LIT_MAGIC_STR, LIT_MAGIC_STR,
LIT_MAGIC_STR_EX,
LIT_NUMBER LIT_NUMBER
}; };
lit_charset_record_t *create_charset_record (const ecma_char_t *, size_t); lit_charset_record_t *create_charset_record (const ecma_char_t *, size_t);
lit_magic_record_t *create_magic_record (ecma_magic_string_id_t); lit_magic_record_t *create_magic_record (ecma_magic_string_id_t);
lit_magic_record_t *create_magic_record_ex (ecma_magic_string_ex_id_t);
lit_number_record_t *create_number_record (ecma_number_t); lit_number_record_t *create_number_record (ecma_number_t);
void dump (); void dump ();
@@ -429,6 +432,7 @@ private:
#define LIT_STR_T (lit_literal_storage_t::LIT_STR) #define LIT_STR_T (lit_literal_storage_t::LIT_STR)
#define LIT_MAGIC_STR_T (lit_literal_storage_t::LIT_MAGIC_STR) #define LIT_MAGIC_STR_T (lit_literal_storage_t::LIT_MAGIC_STR)
#define LIT_MAGIC_STR_EX_T (lit_literal_storage_t::LIT_MAGIC_STR_EX)
#define LIT_NUMBER_T (lit_literal_storage_t::LIT_NUMBER) #define LIT_NUMBER_T (lit_literal_storage_t::LIT_NUMBER)
#endif /* LIT_LITERAL_STORAGE_H */ #endif /* LIT_LITERAL_STORAGE_H */
+62 -11
View File
@@ -72,6 +72,21 @@ lit_create_literal_from_charset (const ecma_char_t *str, /**< string to initiali
} }
} }
for (ecma_magic_string_ex_id_t msi = (ecma_magic_string_ex_id_t) 0;
msi < ecma_get_magic_string_ex_count ();
msi = (ecma_magic_string_ex_id_t) (msi + 1))
{
if (ecma_zt_string_length (ecma_get_magic_string_ex_zt (msi)) != len)
{
continue;
}
if (!strncmp ((const char *) str, (const char *) ecma_get_magic_string_ex_zt (msi), len))
{
return lit_storage.create_magic_record_ex (msi);
}
}
return lit_storage.create_charset_record (str, len * sizeof (ecma_char_t)); return lit_storage.create_charset_record (str, len * sizeof (ecma_char_t));
} /* lit_create_literal_from_charset */ } /* lit_create_literal_from_charset */
@@ -104,8 +119,23 @@ lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for
} }
else if (type == LIT_MAGIC_STR_T) else if (type == LIT_MAGIC_STR_T)
{ {
ecma_magic_string_id_t magic_id = static_cast<lit_magic_record_t *>(lit)->get_magic_str_id (); ecma_magic_string_id_t magic_id = lit_magic_record_get_magic_str_id (lit);
const char *magic_str = (const char *)ecma_get_magic_string_zt (magic_id); const char *magic_str = (const char *) ecma_get_magic_string_zt (magic_id);
if (strlen (magic_str) != len)
{
continue;
}
if (!strncmp (magic_str, (const char *) str, strlen (magic_str)))
{
return lit;
}
}
else if (type == LIT_MAGIC_STR_EX_T)
{
ecma_magic_string_ex_id_t magic_id = lit_magic_record_ex_get_magic_str_id (lit);
const char *magic_str = (const char *) ecma_get_magic_string_ex_zt (magic_id);
if (strlen (magic_str) != len) if (strlen (magic_str) != len)
{ {
@@ -218,7 +248,11 @@ lit_literal_equal_charset_rec (literal_t lit, /**< literal to com
} }
case LIT_MAGIC_STR_T: case LIT_MAGIC_STR_T:
{ {
return record->equal_zt (ecma_get_magic_string_zt (static_cast<lit_magic_record_t *>(lit)->get_magic_str_id ())); return record->equal_zt (ecma_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit)));
}
case LIT_MAGIC_STR_EX_T:
{
return record->equal_zt (ecma_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit)));
} }
case LIT_NUMBER_T: case LIT_NUMBER_T:
{ {
@@ -254,10 +288,14 @@ lit_literal_equal_zt (literal_t lit, /**< literal to compare */
} }
case LIT_MAGIC_STR_T: case LIT_MAGIC_STR_T:
{ {
ecma_magic_string_id_t magic_id = static_cast<lit_magic_record_t *>(lit)->get_magic_str_id (); ecma_magic_string_id_t magic_id = lit_magic_record_get_magic_str_id (lit);
return ecma_compare_zt_strings (str, ecma_get_magic_string_zt (magic_id)); return ecma_compare_zt_strings (str, ecma_get_magic_string_zt (magic_id));
} }
case LIT_MAGIC_STR_EX_T:
{
ecma_magic_string_ex_id_t magic_id = lit_magic_record_ex_get_magic_str_id (lit);
return ecma_compare_zt_strings (str, ecma_get_magic_string_ex_zt (magic_id));
}
case LIT_NUMBER_T: case LIT_NUMBER_T:
{ {
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
@@ -308,9 +346,11 @@ lit_literal_equal (literal_t lit1, /**< first literal */
} }
case lit_literal_storage_t::LIT_MAGIC_STR: case lit_literal_storage_t::LIT_MAGIC_STR:
{ {
ecma_magic_string_id_t magic_id = static_cast<lit_magic_record_t *>(lit2)->get_magic_str_id (); return lit_literal_equal_zt (lit1, ecma_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit2)));
}
return lit_literal_equal_zt (lit1, ecma_get_magic_string_zt (magic_id)); case lit_literal_storage_t::LIT_MAGIC_STR_EX:
{
return lit_literal_equal_zt (lit1, ecma_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit2)));
} }
case lit_literal_storage_t::LIT_NUMBER: case lit_literal_storage_t::LIT_NUMBER:
{ {
@@ -335,7 +375,8 @@ lit_literal_equal_type_zt (literal_t lit, /**< literal to compare */
const ecma_char_t *str) /**< zero-terminated string */ const ecma_char_t *str) /**< zero-terminated string */
{ {
if (lit->get_type () != LIT_STR_T if (lit->get_type () != LIT_STR_T
&& lit->get_type () != LIT_MAGIC_STR_T) && lit->get_type () != LIT_MAGIC_STR_T
&& lit->get_type () != LIT_MAGIC_STR_EX_T)
{ {
return false; return false;
} }
@@ -414,7 +455,11 @@ lit_literal_to_charset (literal_t lit, /**< literal to be processed */
} }
case LIT_MAGIC_STR_T: case LIT_MAGIC_STR_T:
{ {
return ecma_get_magic_string_zt (static_cast<lit_magic_record_t *> (lit)->get_magic_str_id ()); return ecma_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit));
}
case LIT_MAGIC_STR_EX_T:
{
return ecma_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit));
} }
case LIT_NUMBER_T: case LIT_NUMBER_T:
{ {
@@ -488,9 +533,15 @@ lit_charset_literal_get_hash (literal_t lit) /**< literal */
ecma_magic_string_id_t ecma_magic_string_id_t
lit_magic_record_get_magic_str_id (literal_t lit) /**< literal */ lit_magic_record_get_magic_str_id (literal_t lit) /**< literal */
{ {
return static_cast<lit_magic_record_t *> (lit)->get_magic_str_id (); return static_cast<lit_magic_record_t *> (lit)->get_magic_str_id<ecma_magic_string_id_t> ();
} /* lit_magic_record_get_magic_str_id */ } /* lit_magic_record_get_magic_str_id */
ecma_magic_string_ex_id_t
lit_magic_record_ex_get_magic_str_id (literal_t lit) /**< literal */
{
return static_cast<lit_magic_record_t *> (lit)->get_magic_str_id<ecma_magic_string_ex_id_t> ();
} /* lit_magic_record_ex_get_magic_str_id */
int32_t int32_t
lit_charset_record_get_length (literal_t lit) /**< literal */ lit_charset_record_get_length (literal_t lit) /**< literal */
{ {
+1
View File
@@ -51,5 +51,6 @@ ecma_number_t lit_charset_literal_get_number (literal_t);
int32_t lit_charset_record_get_length (literal_t); int32_t lit_charset_record_get_length (literal_t);
ecma_magic_string_id_t lit_magic_record_get_magic_str_id (literal_t); ecma_magic_string_id_t lit_magic_record_get_magic_str_id (literal_t);
ecma_magic_string_ex_id_t lit_magic_record_ex_get_magic_str_id (literal_t);
#endif /* LIT_LITERAL_H */ #endif /* LIT_LITERAL_H */
@@ -15,9 +15,7 @@
#include "linked-list.h" #include "linked-list.h"
#include "jrt-libc-includes.h" #include "jrt-libc-includes.h"
#include "jrt.h"
#include "mem-heap.h" #include "mem-heap.h"
#include "lp-string.h"
typedef struct linked_list_header typedef struct linked_list_header
{ {
@@ -15,8 +15,6 @@
#include "lit-id-hash-table.h" #include "lit-id-hash-table.h"
#include "bytecode-data.h" #include "bytecode-data.h"
#include "mem-heap.h"
#include "jrt-libc-includes.h"
lit_id_hash_table * lit_id_hash_table *
lit_id_hash_table_init (size_t buckets_count, size_t blocks_count) lit_id_hash_table_init (size_t buckets_count, size_t blocks_count)
@@ -24,11 +22,11 @@ lit_id_hash_table_init (size_t buckets_count, size_t blocks_count)
size_t size = mem_heap_recommend_allocation_size (sizeof (lit_id_hash_table)); size_t size = mem_heap_recommend_allocation_size (sizeof (lit_id_hash_table));
lit_id_hash_table *table = (lit_id_hash_table *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM); lit_id_hash_table *table = (lit_id_hash_table *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
memset (table, 0, size); memset (table, 0, size);
size = mem_heap_recommend_allocation_size (sizeof (literal_index_t) * buckets_count); size = mem_heap_recommend_allocation_size (sizeof (lit_cpointer_t) * buckets_count);
table->raw_buckets = (literal_index_t *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM); table->raw_buckets = (lit_cpointer_t *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
memset (table->raw_buckets, 0, size); memset (table->raw_buckets, 0, size);
size = mem_heap_recommend_allocation_size (sizeof (literal_index_t *) * blocks_count); size = mem_heap_recommend_allocation_size (sizeof (lit_cpointer_t *) * blocks_count);
table->buckets = (literal_index_t **) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM); table->buckets = (lit_cpointer_t **) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
memset (table->buckets, 0, size); memset (table->buckets, 0, size);
table->current_bucket_pos = 0; table->current_bucket_pos = 0;
return table; return table;
@@ -44,7 +42,7 @@ lit_id_hash_table_free (lit_id_hash_table *table)
} }
void void
lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc, literal_index_t lit_id) lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc, lit_cpointer_t lit_cp)
{ {
JERRY_ASSERT (table); JERRY_ASSERT (table);
size_t block_id = oc / BLOCK_SIZE; size_t block_id = oc / BLOCK_SIZE;
@@ -52,11 +50,11 @@ lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t
{ {
table->buckets[block_id] = table->raw_buckets + table->current_bucket_pos; table->buckets[block_id] = table->raw_buckets + table->current_bucket_pos;
} }
table->buckets[block_id][uid] = lit_id; table->buckets[block_id][uid] = lit_cp;
table->current_bucket_pos++; table->current_bucket_pos++;
} }
literal_index_t lit_cpointer_t
lit_id_hash_table_lookup (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc) lit_id_hash_table_lookup (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc)
{ {
JERRY_ASSERT (table); JERRY_ASSERT (table);
@@ -19,17 +19,18 @@
#include "jrt.h" #include "jrt.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "opcodes.h" #include "opcodes.h"
#include "lit-literal.h"
typedef struct typedef struct
{ {
size_t current_bucket_pos; size_t current_bucket_pos;
literal_index_t *raw_buckets; lit_cpointer_t *raw_buckets;
literal_index_t **buckets; lit_cpointer_t **buckets;
} lit_id_hash_table; } lit_id_hash_table;
lit_id_hash_table *lit_id_hash_table_init (size_t, size_t); lit_id_hash_table *lit_id_hash_table_init (size_t, size_t);
void lit_id_hash_table_free (lit_id_hash_table *); void lit_id_hash_table_free (lit_id_hash_table *);
void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, opcode_counter_t, literal_index_t); void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, opcode_counter_t, lit_cpointer_t);
literal_index_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, opcode_counter_t); lit_cpointer_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, opcode_counter_t);
#endif /* LIT_ID_HASH_TABLE */ #endif /* LIT_ID_HASH_TABLE */
@@ -1,63 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "lp-string.h"
#include "jrt-libc-includes.h"
bool
lp_string_equal (lp_string s1, lp_string s2)
{
if (s1.length != s2.length)
{
return false;
}
for (ecma_length_t i = 0; i < s1.length; i++)
{
JERRY_ASSERT (s1.str[i] != '\0' && s1.str[i] != '\0');
if (s1.str[i] != s2.str[i])
{
return false;
}
}
return true;
}
bool
lp_string_equal_s (lp_string lp, const char *s)
{
return lp_string_equal_zt (lp, (const ecma_char_t *) s);
}
bool
lp_string_equal_zt (lp_string lp, const ecma_char_t *s)
{
for (ecma_length_t i = 0; i < lp.length; i++)
{
JERRY_ASSERT (lp.str[i] != '\0');
if (lp.str[i] != s[i])
{
return false;
}
}
if (s[lp.length] != '\0')
{
return false;
}
return true;
}
-33
View File
@@ -1,33 +0,0 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LP_STRING
#define LP_STRING
#include "ecma-globals.h"
/* Length-prefixed or "pascal" string. */
typedef struct
{
const ecma_char_t *str;
ecma_length_t length;
ecma_string_hash_t hash;
} lp_string;
bool lp_string_equal (lp_string, lp_string);
bool lp_string_equal_s (lp_string, const char *);
bool lp_string_equal_zt (lp_string, const ecma_char_t *);
#endif /* LP_STRING */
-3
View File
@@ -17,7 +17,6 @@
#define BYTECODE_DATA_H #define BYTECODE_DATA_H
#include "opcodes.h" #include "opcodes.h"
#include "literal.h"
#include "lit-id-hash-table.h" #include "lit-id-hash-table.h"
/* /*
@@ -38,10 +37,8 @@
typedef struct typedef struct
{ {
const ecma_char_t *strings_buffer; const ecma_char_t *strings_buffer;
const literal *literals;
const opcode_t *opcodes; const opcode_t *opcodes;
lit_id_hash_table *lit_id_hash; lit_id_hash_table *lit_id_hash;
literal_index_t literals_count;
opcode_counter_t opcodes_count; opcode_counter_t opcodes_count;
} bytecode_data_t; } bytecode_data_t;
+33 -198
View File
@@ -16,11 +16,7 @@
#include "mem-allocator.h" #include "mem-allocator.h"
#include "jrt-libc-includes.h" #include "jrt-libc-includes.h"
#include "lexer.h" #include "lexer.h"
#include "parser.h"
#include "stack.h"
#include "opcodes.h"
#include "syntax-errors.h" #include "syntax-errors.h"
#include "parser.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
static token saved_token, prev_token, sent_token, empty_token; static token saved_token, prev_token, sent_token, empty_token;
@@ -32,18 +28,9 @@ static size_t buffer_size = 0;
static const char *buffer_start = NULL; static const char *buffer_start = NULL;
static const char *buffer = NULL; static const char *buffer = NULL;
static const char *token_start; static const char *token_start;
static ecma_char_t *strings_cache;
static size_t strings_cache_size;
static size_t strings_cache_used_size;
#define LA(I) (get_char (I)) #define LA(I) (get_char (I))
enum
{
literals_global_size
};
STATIC_STACK (literals, literal)
static bool static bool
is_empty (token tok) is_empty (token tok)
{ {
@@ -93,7 +80,25 @@ dump_current_line (void)
} }
static token static token
create_token (token_type type, literal_index_t uid) create_token_from_lit (token_type type, literal_t lit)
{
token ret;
ret.type = type;
ret.loc = current_locus () - (type == TOK_STRING ? 1 : 0);
ret.uid = lit_cpointer_t::compress (lit).packed_value;
return ret;
}
/**
* Create token of specified type
*
* @return token descriptor
*/
static token
create_token (token_type type, /**< type of token */
uint16_t uid) /**< uid of token */
{ {
token ret; token ret;
@@ -102,92 +107,7 @@ create_token (token_type type, literal_index_t uid)
ret.uid = uid; ret.uid = uid;
return ret; return ret;
} } /* create_token */
/**
* Compare specified string to literal
*
* @return true - if the literal contains exactly the specified string,
* false - otherwise.
*/
static bool
string_equals_to_literal (const ecma_char_t *str_p, /**< characters buffer */
ecma_length_t length, /**< string's length */
literal lit) /**< literal */
{
if (lit.type == LIT_STR)
{
if (lit.data.lp.length == length
&& strncmp ((const char *) lit.data.lp.str, (const char*) str_p, length) == 0)
{
return true;
}
}
else if (lit.type == LIT_MAGIC_STR)
{
const char *magic_str_p = (const char *) ecma_get_magic_string_zt (lit.data.magic_str_id);
if (strlen (magic_str_p) == length
&& strncmp (magic_str_p, (const char*) str_p, length) == 0)
{
return true;
}
}
else if (lit.type == LIT_MAGIC_STR_EX)
{
const char *magic_str_p = (const char *) ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id);
if (strlen (magic_str_p) == length
&& strncmp (magic_str_p, (const char*) str_p, length) == 0)
{
return true;
}
}
return false;
} /* string_equals_to_literal */
static literal
adjust_string_ptrs (literal lit, size_t diff)
{
if (lit.type != LIT_STR)
{
return lit;
}
literal ret;
ret.type = LIT_STR;
ret.data.lp.length = lit.data.lp.length;
ret.data.lp.hash = lit.data.lp.hash;
ret.data.lp.str = lit.data.lp.str + diff;
return ret;
}
static literal
add_string_to_string_cache (const ecma_char_t* str, ecma_length_t length)
{
if (strings_cache_used_size + length * sizeof (ecma_char_t) >= strings_cache_size)
{
strings_cache_size = mem_heap_recommend_allocation_size (strings_cache_used_size
+ ((size_t) length + 1) * sizeof (ecma_char_t));
ecma_char_t *temp = (ecma_char_t *) mem_heap_alloc_block (strings_cache_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (strings_cache)
{
memcpy (temp, strings_cache, strings_cache_used_size);
STACK_ITERATE_VARG_SET (literals, adjust_string_ptrs, 0, (size_t) (temp - strings_cache));
mem_heap_free_block ((uint8_t *) strings_cache);
}
strings_cache = temp;
}
strncpy ((char *) (strings_cache + strings_cache_used_size), (const char*) str, length);
(strings_cache + strings_cache_used_size)[length] = '\0';
const literal res = create_literal_from_zt (strings_cache + strings_cache_used_size, length);
strings_cache_used_size = (size_t) (((size_t) length + 1) * sizeof (ecma_char_t) + strings_cache_used_size);
return res;
}
/** /**
* Convert string to token of specified type * Convert string to token of specified type
@@ -201,30 +121,22 @@ convert_string_to_token (token_type tt, /**< token type */
{ {
JERRY_ASSERT (str_p != NULL); JERRY_ASSERT (str_p != NULL);
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++) literal_t lit = lit_find_literal_by_charset (str_p, length);
if (lit != NULL)
{ {
const literal lit = STACK_ELEMENT (literals, i); return create_token_from_lit (tt, lit);
if ((lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX)
&& string_equals_to_literal (str_p, length, lit))
{
return create_token (tt, i);
}
} }
literal lit = create_literal_from_str (str_p, length); lit = lit_create_literal_from_charset (str_p, length);
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX); JERRY_ASSERT (lit->get_type () == LIT_STR_T
if (lit.type == LIT_STR) || lit->get_type () == LIT_MAGIC_STR_T
{ || lit->get_type () == LIT_MAGIC_STR_EX_T);
lit = add_string_to_string_cache (str_p, length);
}
STACK_PUSH (literals, lit); return create_token_from_lit (tt, lit);
return create_token (tt, (literal_index_t) (STACK_SIZE (literals) - 1));
} }
/** /**
* Try to decore specified string as keyword * Try to decode specified string as keyword
* *
* @return if specified string represents a keyword, return corresponding keyword token, * @return if specified string represents a keyword, return corresponding keyword token,
* else if it is 'null' - return TOK_NULL token, * else if it is 'null' - return TOK_NULL token,
@@ -360,85 +272,13 @@ decode_keyword (const ecma_char_t *str_p, /**< characters buffer */
static token static token
convert_seen_num_to_token (ecma_number_t num) convert_seen_num_to_token (ecma_number_t num)
{ {
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++) literal_t lit = lit_find_literal_by_num (num);
if (lit != NULL)
{ {
const literal lit = STACK_ELEMENT (literals, i); return create_token_from_lit (TOK_NUMBER, lit);
if (lit.type != LIT_NUMBER)
{
continue;
}
if (lit.data.num == num)
{
return create_token (TOK_NUMBER, i);
}
} }
STACK_PUSH (literals, create_literal_from_num (num)); return create_token_from_lit (TOK_NUMBER, lit_create_literal_from_num (num));
return create_token (TOK_NUMBER, (literal_index_t) (STACK_SIZE (literals) - 1));
}
const literal *
lexer_get_literals (void)
{
literal *data = NULL;
if (STACK_SIZE (literals) > 0)
{
STACK_CONVERT_TO_RAW_DATA (literals, data);
}
return data;
}
literal_index_t
lexer_get_literals_count (void)
{
return (literal_index_t) STACK_SIZE (literals);
}
literal_index_t
lexer_lookup_literal_uid (literal lit)
{
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++)
{
if (literal_equal_type (STACK_ELEMENT (literals, i), lit))
{
return i;
}
}
return INVALID_VALUE;
}
literal
lexer_get_literal_by_id (literal_index_t id)
{
JERRY_ASSERT (id != INVALID_LITERAL);
JERRY_ASSERT (id < STACK_SIZE (literals));
return STACK_ELEMENT (literals, id);
}
const ecma_char_t *
lexer_get_strings_cache (void)
{
return strings_cache;
}
void
lexer_add_keyword_or_numeric_literal_if_not_present (literal lit)
{
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++)
{
if (literal_equal_type (STACK_ELEMENT (literals, i), lit))
{
return;
}
}
if (lit.type == LIT_STR)
{
lit = add_string_to_string_cache (lit.data.lp.str, lit.data.lp.length);
}
STACK_PUSH (literals, lit);
} }
static void static void
@@ -1644,15 +1484,10 @@ lexer_init (const char *source, size_t source_size, bool show_opcodes)
buffer_size = source_size; buffer_size = source_size;
lexer_set_source (source); lexer_set_source (source);
strings_cache = NULL;
strings_cache_used_size = strings_cache_size = 0;
lexer_set_strict_mode (false); lexer_set_strict_mode (false);
STACK_INIT (literals);
} }
void void
lexer_free (void) lexer_free (void)
{ {
STACK_FREE (literals);
} }
+3 -10
View File
@@ -16,10 +16,10 @@
#ifndef LEXER_H #ifndef LEXER_H
#define LEXER_H #define LEXER_H
#include "literal.h" #include "lit-literal.h"
#define INVALID_VALUE 255 #define INVALID_VALUE 255
#define INVALID_LITERAL ((uint32_t) -1) #define INVALID_LITERAL (rcs_cpointer_t::null_cp ())
/* Keywords. */ /* Keywords. */
typedef enum __attr_packed___ typedef enum __attr_packed___
@@ -160,7 +160,7 @@ typedef struct
{ {
locus loc; locus loc;
token_type type; token_type type;
literal_index_t uid; uint16_t uid;
} token; } token;
/** /**
@@ -175,13 +175,6 @@ token lexer_next_token (void);
void lexer_save_token (token); void lexer_save_token (token);
token lexer_prev_token (void); token lexer_prev_token (void);
const literal *lexer_get_literals (void);
const ecma_char_t *lexer_get_strings_cache (void);
void lexer_add_keyword_or_numeric_literal_if_not_present (literal);
literal_index_t lexer_get_literals_count (void);
literal lexer_get_literal_by_id (literal_index_t);
literal_index_t lexer_lookup_literal_uid (literal lit);
void lexer_seek (locus); void lexer_seek (locus);
void lexer_locus_to_line_and_column (locus, size_t *, size_t *); void lexer_locus_to_line_and_column (locus, size_t *, size_t *);
void lexer_dump_line (size_t); void lexer_dump_line (size_t);
-275
View File
@@ -1,275 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "literal.h"
#include "ecma-helpers.h"
#include "jrt-libc-includes.h"
literal
create_empty_literal (void)
{
literal ret;
ret.type = LIT_UNKNOWN;
ret.data.none = NULL;
return ret;
}
literal
create_literal_from_num (ecma_number_t num)
{
literal ret;
ret.type = LIT_NUMBER;
ret.data.num = num;
return ret;
}
/**
* Create literal from string
*
* @return literal descriptor
*/
literal
create_literal_from_str (const ecma_char_t *s, /**< characters buffer */
ecma_length_t len) /**< string's length */
{
return create_literal_from_zt (s, len);
} /* create_literal_from_str */
literal
create_literal_from_str_compute_len (const char *s)
{
return create_literal_from_zt ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
}
literal
create_literal_from_zt (const ecma_char_t *s, ecma_length_t len)
{
for (ecma_magic_string_id_t msi = (ecma_magic_string_id_t) 0;
msi < ECMA_MAGIC_STRING__COUNT;
msi = (ecma_magic_string_id_t) (msi + 1))
{
if (ecma_zt_string_length (ecma_get_magic_string_zt (msi)) != len)
{
continue;
}
if (!strncmp ((const char *) s, (const char *) ecma_get_magic_string_zt (msi), len))
{
literal ret;
ret.type = LIT_MAGIC_STR;
ret.data.magic_str_id = msi;
return ret;
}
}
uint32_t ex_count = ecma_get_magic_string_ex_count ();
for (ecma_magic_string_ex_id_t msi = (ecma_magic_string_ex_id_t) 0;
msi < ex_count;
msi = (ecma_magic_string_id_t) (msi + 1))
{
const ecma_char_t* ex_string = ecma_get_magic_string_ex_zt (msi);
if (ecma_zt_string_length (ex_string) != len)
{
continue;
}
if (!strncmp ((const char *) s, (const char *) ex_string, len))
{
literal ret;
ret.type = LIT_MAGIC_STR_EX;
ret.data.magic_str_ex_id = msi;
return ret;
}
}
literal ret;
ret.type = LIT_STR;
ret.data.lp.length = len;
ret.data.lp.str = s;
ret.data.lp.hash = ecma_chars_buffer_calc_hash_last_chars (s, len);
return ret;
}
bool
literal_equal_type (literal lit1, literal lit2)
{
if (lit1.type != lit2.type)
{
return false;
}
return literal_equal (lit1, lit2);
}
bool
literal_equal_type_s (literal lit, const char *s)
{
return literal_equal_type_zt (lit, (const ecma_char_t *) s);
}
bool
literal_equal_type_zt (literal lit, const ecma_char_t *s)
{
if (lit.type != LIT_STR && lit.type != LIT_MAGIC_STR && lit.type != LIT_MAGIC_STR_EX)
{
return false;
}
return literal_equal_zt (lit, s);
}
bool
literal_equal_type_num (literal lit, ecma_number_t num)
{
if (lit.type != LIT_NUMBER)
{
return false;
}
return literal_equal_num (lit, num);
}
static bool
literal_equal_lp (literal lit, lp_string lp)
{
switch (lit.type)
{
case LIT_UNKNOWN:
{
return false;
}
case LIT_STR:
{
return lp_string_equal (lit.data.lp, lp);
}
case LIT_MAGIC_STR:
{
return lp_string_equal_zt (lp, ecma_get_magic_string_zt (lit.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return lp_string_equal_zt (lp, ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (lit.data.num, buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
return lp_string_equal_zt (lp, buff);
}
default:
{
JERRY_UNREACHABLE ();
}
}
}
bool
literal_equal (literal lit1, literal lit2)
{
switch (lit2.type)
{
case LIT_UNKNOWN:
{
return lit2.type == LIT_UNKNOWN;
}
case LIT_STR:
{
return literal_equal_lp (lit1, lit2.data.lp);
}
case LIT_MAGIC_STR:
{
return literal_equal_zt (lit1, ecma_get_magic_string_zt (lit2.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return literal_equal_zt (lit1, ecma_get_magic_string_ex_zt (lit2.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
return literal_equal_num (lit1, lit2.data.num);
}
default:
{
JERRY_UNREACHABLE ();
}
}
}
bool
literal_equal_s (literal lit, const char *s)
{
return literal_equal_zt (lit, (const ecma_char_t *) s);
}
bool
literal_equal_zt (literal lit, const ecma_char_t *s)
{
switch (lit.type)
{
case LIT_UNKNOWN:
{
return false;
}
case LIT_STR:
{
return lp_string_equal_zt (lit.data.lp, s);
}
case LIT_MAGIC_STR:
{
return ecma_compare_zt_strings (s, ecma_get_magic_string_zt (lit.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return ecma_compare_zt_strings (s, ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (lit.data.num, buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
return ecma_compare_zt_strings (s, buff);
}
default:
{
JERRY_UNREACHABLE ();
}
}
}
bool
literal_equal_num (literal lit, ecma_number_t num)
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (num, buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
return literal_equal_zt (lit, buff);
}
const ecma_char_t *
literal_to_zt (literal lit)
{
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX);
switch (lit.type)
{
case LIT_STR: return lit.data.lp.str;
case LIT_MAGIC_STR: return ecma_get_magic_string_zt (lit.data.magic_str_id);
case LIT_MAGIC_STR_EX: return ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id);
default: JERRY_UNREACHABLE ();
}
}
-61
View File
@@ -1,61 +0,0 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LITERAL_H
#define LITERAL_H
#include "ecma-globals.h"
#include "lp-string.h"
typedef enum __attr_packed___
{
LIT_UNKNOWN,
LIT_STR,
LIT_MAGIC_STR,
LIT_MAGIC_STR_EX,
LIT_NUMBER
} literal_type;
typedef struct
{
union
{
ecma_magic_string_id_t magic_str_id;
ecma_magic_string_ex_id_t magic_str_ex_id;
ecma_number_t num;
lp_string lp;
void *none;
} data;
literal_type type;
} literal;
#define LITERAL_TO_REWRITE (INVALID_VALUE - 1)
literal create_empty_literal (void);
literal create_literal_from_num (ecma_number_t);
literal create_literal_from_str (const ecma_char_t*, ecma_length_t);
literal create_literal_from_str_compute_len (const char *);
literal create_literal_from_zt (const ecma_char_t *, ecma_length_t);
bool literal_equal (literal, literal);
bool literal_equal_s (literal, const char *);
bool literal_equal_zt (literal, const ecma_char_t *);
bool literal_equal_num (literal, ecma_number_t);
bool literal_equal_type (literal, literal);
bool literal_equal_type_s (literal, const char *);
bool literal_equal_type_zt (literal, const ecma_char_t *);
bool literal_equal_type_num (literal, ecma_number_t);
const ecma_char_t *literal_to_zt (literal);
#endif /* LITERAL_H */
+49 -44
View File
@@ -14,14 +14,11 @@
*/ */
#include "opcodes-dumper.h" #include "opcodes-dumper.h"
#include "serializer.h" #include "serializer.h"
#include "jrt.h"
#include "lexer.h"
#include "stack.h" #include "stack.h"
#include "syntax-errors.h" #include "syntax-errors.h"
#include "jrt-libc-includes.h"
#include "opcodes-native-call.h" #include "opcodes-native-call.h"
#include "serializer.h"
#define MIN_TEMP_NAME 128 #define MIN_TEMP_NAME 128
static idx_t temp_name, max_temp_name; static idx_t temp_name, max_temp_name;
@@ -136,7 +133,7 @@ next_temp_name (void)
} }
static op_meta static op_meta
create_op_meta (opcode_t op, literal_index_t lit_id1, literal_index_t lit_id2, literal_index_t lit_id3) create_op_meta (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3)
{ {
op_meta ret; op_meta ret;
@@ -155,43 +152,43 @@ create_op_meta_000 (opcode_t op)
} }
static op_meta static op_meta
create_op_meta_001 (opcode_t op, literal_index_t lit_id) create_op_meta_001 (opcode_t op, lit_cpointer_t lit_id)
{ {
return create_op_meta (op, NOT_A_LITERAL, NOT_A_LITERAL, lit_id); return create_op_meta (op, NOT_A_LITERAL, NOT_A_LITERAL, lit_id);
} }
static op_meta static op_meta
create_op_meta_010 (opcode_t op, literal_index_t lit_id) create_op_meta_010 (opcode_t op, lit_cpointer_t lit_id)
{ {
return create_op_meta (op, NOT_A_LITERAL, lit_id, NOT_A_LITERAL); return create_op_meta (op, NOT_A_LITERAL, lit_id, NOT_A_LITERAL);
} }
static op_meta static op_meta
create_op_meta_011 (opcode_t op, literal_index_t lit_id2, literal_index_t lit_id3) create_op_meta_011 (opcode_t op, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3)
{ {
return create_op_meta (op, NOT_A_LITERAL, lit_id2, lit_id3); return create_op_meta (op, NOT_A_LITERAL, lit_id2, lit_id3);
} }
static op_meta static op_meta
create_op_meta_100 (opcode_t op, literal_index_t lit_id) create_op_meta_100 (opcode_t op, lit_cpointer_t lit_id)
{ {
return create_op_meta (op, lit_id, NOT_A_LITERAL, NOT_A_LITERAL); return create_op_meta (op, lit_id, NOT_A_LITERAL, NOT_A_LITERAL);
} }
static op_meta static op_meta
create_op_meta_101 (opcode_t op, literal_index_t lit_id1, literal_index_t lit_id3) create_op_meta_101 (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id3)
{ {
return create_op_meta (op, lit_id1, NOT_A_LITERAL, lit_id3); return create_op_meta (op, lit_id1, NOT_A_LITERAL, lit_id3);
} }
static op_meta static op_meta
create_op_meta_110 (opcode_t op, literal_index_t lit_id1, literal_index_t lit_id2) create_op_meta_110 (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2)
{ {
return create_op_meta (op, lit_id1, lit_id2, NOT_A_LITERAL); return create_op_meta (op, lit_id1, lit_id2, NOT_A_LITERAL);
} }
static op_meta static op_meta
create_op_meta_111 (opcode_t op, literal_index_t lit_id1, literal_index_t lit_id2, literal_index_t lit_id3) create_op_meta_111 (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3)
{ {
return create_op_meta (op, lit_id1, lit_id2, lit_id3); return create_op_meta (op, lit_id1, lit_id2, lit_id3);
} }
@@ -214,27 +211,27 @@ name_to_native_call_id (operand obj)
{ {
return OPCODE_NATIVE_CALL__COUNT; return OPCODE_NATIVE_CALL__COUNT;
} }
if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "LEDToggle")) if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDToggle"))
{ {
return OPCODE_NATIVE_CALL_LED_TOGGLE; return OPCODE_NATIVE_CALL_LED_TOGGLE;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "LEDOn")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOn"))
{ {
return OPCODE_NATIVE_CALL_LED_ON; return OPCODE_NATIVE_CALL_LED_ON;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "LEDOff")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOff"))
{ {
return OPCODE_NATIVE_CALL_LED_OFF; return OPCODE_NATIVE_CALL_LED_OFF;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "LEDOnce")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOnce"))
{ {
return OPCODE_NATIVE_CALL_LED_ONCE; return OPCODE_NATIVE_CALL_LED_ONCE;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "wait")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "wait"))
{ {
return OPCODE_NATIVE_CALL_WAIT; return OPCODE_NATIVE_CALL_WAIT;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "print")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "print"))
{ {
return OPCODE_NATIVE_CALL_PRINT; return OPCODE_NATIVE_CALL_PRINT;
} }
@@ -614,11 +611,11 @@ dump_prop_setter_op_meta (op_meta last, operand op)
} }
static operand static operand
create_operand_from_tmp_and_lit (idx_t tmp, literal_index_t lit_id) create_operand_from_tmp_and_lit (idx_t tmp, lit_cpointer_t lit_id)
{ {
if (tmp != LITERAL_TO_REWRITE) if (tmp != LITERAL_TO_REWRITE)
{ {
JERRY_ASSERT (lit_id == NOT_A_LITERAL); JERRY_ASSERT (lit_id.packed_value == MEM_CP_NULL);
operand ret; operand ret;
@@ -629,7 +626,7 @@ create_operand_from_tmp_and_lit (idx_t tmp, literal_index_t lit_id)
} }
else else
{ {
JERRY_ASSERT (lit_id != NOT_A_LITERAL); JERRY_ASSERT (lit_id.packed_value != MEM_CP_NULL);
operand ret; operand ret;
@@ -688,12 +685,12 @@ empty_operand (void)
} }
operand operand
literal_operand (literal_index_t lit_id) literal_operand (lit_cpointer_t lit_cp)
{ {
operand ret; operand ret;
ret.type = OPERAND_LITERAL; ret.type = OPERAND_LITERAL;
ret.data.lit_id = lit_id; ret.data.lit_id = lit_cp;
return ret; return ret;
} }
@@ -733,7 +730,7 @@ dumper_is_intrinsic (operand obj)
{ {
if (obj.type == OPERAND_LITERAL) if (obj.type == OPERAND_LITERAL)
{ {
if (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "assert")) if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "assert"))
{ {
return true; return true;
} }
@@ -746,7 +743,7 @@ dump_intrinsic (operand obj, operand arg)
{ {
JERRY_ASSERT (obj.type == OPERAND_LITERAL); JERRY_ASSERT (obj.type == OPERAND_LITERAL);
TODO (/* Rewrite when there will be more intrinsics. */) TODO (/* Rewrite when there will be more intrinsics. */)
JERRY_ASSERT (literal_equal_type_s (lexer_get_literal_by_id (obj.data.lit_id), "assert")); JERRY_ASSERT (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "assert"));
dump_assert (arg); dump_assert (arg);
return dump_undefined_assignment_res (); return dump_undefined_assignment_res ();
} }
@@ -786,7 +783,7 @@ dump_boolean_assignment_res (bool is_true)
} }
void void
dump_string_assignment (operand op, literal_index_t lit_id) dump_string_assignment (operand op, lit_cpointer_t lit_id)
{ {
switch (op.type) switch (op.type)
{ {
@@ -806,7 +803,7 @@ dump_string_assignment (operand op, literal_index_t lit_id)
} }
operand operand
dump_string_assignment_res (literal_index_t lit_id) dump_string_assignment_res (lit_cpointer_t lit_id)
{ {
operand op = tmp_operand (); operand op = tmp_operand ();
dump_string_assignment (op, lit_id); dump_string_assignment (op, lit_id);
@@ -814,7 +811,7 @@ dump_string_assignment_res (literal_index_t lit_id)
} }
void void
dump_number_assignment (operand op, literal_index_t lit_id) dump_number_assignment (operand op, lit_cpointer_t lit_id)
{ {
switch (op.type) switch (op.type)
{ {
@@ -834,7 +831,7 @@ dump_number_assignment (operand op, literal_index_t lit_id)
} }
operand operand
dump_number_assignment_res (literal_index_t lit_id) dump_number_assignment_res (lit_cpointer_t lit_id)
{ {
operand op = tmp_operand (); operand op = tmp_operand ();
dump_number_assignment (op, lit_id); dump_number_assignment (op, lit_id);
@@ -1097,15 +1094,17 @@ void
dump_prop_name_and_value (operand name, operand value) dump_prop_name_and_value (operand name, operand value)
{ {
JERRY_ASSERT (name.type == OPERAND_LITERAL); JERRY_ASSERT (name.type == OPERAND_LITERAL);
const literal lit = lexer_get_literal_by_id (name.data.lit_id); literal_t lit = lit_get_literal_by_cp (name.data.lit_id);
operand tmp; operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX) if (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T)
{ {
tmp = dump_string_assignment_res (name.data.lit_id); tmp = dump_string_assignment_res (name.data.lit_id);
} }
else else
{ {
JERRY_ASSERT (lit.type == LIT_NUMBER); JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
tmp = dump_number_assignment_res (name.data.lit_id); tmp = dump_number_assignment_res (name.data.lit_id);
} }
switch (value.type) switch (value.type)
@@ -1130,15 +1129,17 @@ dump_prop_getter_decl (operand name, operand func)
{ {
JERRY_ASSERT (name.type == OPERAND_LITERAL); JERRY_ASSERT (name.type == OPERAND_LITERAL);
JERRY_ASSERT (func.type == OPERAND_TMP); JERRY_ASSERT (func.type == OPERAND_TMP);
const literal lit = lexer_get_literal_by_id (name.data.lit_id); literal_t lit = lit_get_literal_by_cp (name.data.lit_id);
operand tmp; operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX) if (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T)
{ {
tmp = dump_string_assignment_res (name.data.lit_id); tmp = dump_string_assignment_res (name.data.lit_id);
} }
else else
{ {
JERRY_ASSERT (lit.type == LIT_NUMBER); JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
tmp = dump_number_assignment_res (name.data.lit_id); tmp = dump_number_assignment_res (name.data.lit_id);
} }
const opcode_t opcode = getop_meta (OPCODE_META_TYPE_VARG_PROP_GETTER, tmp.data.uid, func.data.uid); const opcode_t opcode = getop_meta (OPCODE_META_TYPE_VARG_PROP_GETTER, tmp.data.uid, func.data.uid);
@@ -1150,15 +1151,17 @@ dump_prop_setter_decl (operand name, operand func)
{ {
JERRY_ASSERT (name.type == OPERAND_LITERAL); JERRY_ASSERT (name.type == OPERAND_LITERAL);
JERRY_ASSERT (func.type == OPERAND_TMP); JERRY_ASSERT (func.type == OPERAND_TMP);
const literal lit = lexer_get_literal_by_id (name.data.lit_id); literal_t lit = lit_get_literal_by_cp (name.data.lit_id);
operand tmp; operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX) if (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T)
{ {
tmp = dump_string_assignment_res (name.data.lit_id); tmp = dump_string_assignment_res (name.data.lit_id);
} }
else else
{ {
JERRY_ASSERT (lit.type == LIT_NUMBER); JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
tmp = dump_number_assignment_res (name.data.lit_id); tmp = dump_number_assignment_res (name.data.lit_id);
} }
const opcode_t opcode = getop_meta (OPCODE_META_TYPE_VARG_PROP_SETTER, tmp.data.uid, func.data.uid); const opcode_t opcode = getop_meta (OPCODE_META_TYPE_VARG_PROP_SETTER, tmp.data.uid, func.data.uid);
@@ -1347,8 +1350,10 @@ dump_delete (operand res, operand op, bool is_strict, locus loc)
{ {
case OPERAND_LITERAL: case OPERAND_LITERAL:
{ {
const literal lit = lexer_get_literal_by_id (op.data.lit_id); literal_t lit = lit_get_literal_by_cp (op.data.lit_id);
if (lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX || lit.type == LIT_STR) if (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T)
{ {
syntax_check_delete (is_strict, loc); syntax_check_delete (is_strict, loc);
switch (res.type) switch (res.type)
@@ -1368,7 +1373,7 @@ dump_delete (operand res, operand op, bool is_strict, locus loc)
} }
break; break;
} }
else if (lit.type == LIT_NUMBER) else if (lit->get_type () == LIT_NUMBER_T)
{ {
dump_boolean_assignment (res, true); dump_boolean_assignment (res, true);
} }
@@ -2372,7 +2377,7 @@ dump_throw (operand op)
} }
bool bool
dumper_variable_declaration_exists (literal_index_t lit_id) dumper_variable_declaration_exists (lit_cpointer_t lit_id)
{ {
for (opcode_counter_t oc = (opcode_counter_t) (serializer_get_current_opcode_counter () - 1); for (opcode_counter_t oc = (opcode_counter_t) (serializer_get_current_opcode_counter () - 1);
oc > 0; oc--) oc > 0; oc--)
@@ -2382,7 +2387,7 @@ dumper_variable_declaration_exists (literal_index_t lit_id)
{ {
break; break;
} }
if (var_decl_op_meta.lit_id[0] == lit_id) if (var_decl_op_meta.lit_id[0].packed_value == lit_id.packed_value)
{ {
return true; return true;
} }
@@ -2391,7 +2396,7 @@ dumper_variable_declaration_exists (literal_index_t lit_id)
} }
void void
dump_variable_declaration (literal_index_t lit_id) dump_variable_declaration (lit_cpointer_t lit_id)
{ {
const opcode_t opcode = getop_var_decl (LITERAL_TO_REWRITE); const opcode_t opcode = getop_var_decl (LITERAL_TO_REWRITE);
serializer_dump_op_meta (create_op_meta_100 (opcode, lit_id)); serializer_dump_op_meta (create_op_meta_100 (opcode, lit_id));
+8 -8
View File
@@ -32,7 +32,7 @@ typedef struct
union union
{ {
idx_t uid; idx_t uid;
literal_index_t lit_id; lit_cpointer_t lit_id;
} data; } data;
} operand; } operand;
@@ -47,7 +47,7 @@ typedef enum __attr_packed___
} varg_list_type; } varg_list_type;
operand empty_operand (void); operand empty_operand (void);
operand literal_operand (literal_index_t); operand literal_operand (lit_cpointer_t);
bool operand_is_empty (operand); bool operand_is_empty (operand);
void dumper_init (void); void dumper_init (void);
@@ -62,10 +62,10 @@ operand dump_intrinsic (operand, operand);
void dump_boolean_assignment (operand, bool); void dump_boolean_assignment (operand, bool);
operand dump_boolean_assignment_res (bool); operand dump_boolean_assignment_res (bool);
void dump_string_assignment (operand, literal_index_t); void dump_string_assignment (operand, lit_cpointer_t);
operand dump_string_assignment_res (literal_index_t); operand dump_string_assignment_res (lit_cpointer_t);
void dump_number_assignment (operand, literal_index_t); void dump_number_assignment (operand, lit_cpointer_t);
operand dump_number_assignment_res (literal_index_t); operand dump_number_assignment_res (lit_cpointer_t);
void dump_smallint_assignment (operand, idx_t); void dump_smallint_assignment (operand, idx_t);
operand dump_smallint_assignment_res (idx_t); operand dump_smallint_assignment_res (idx_t);
void dump_undefined_assignment (operand); void dump_undefined_assignment (operand);
@@ -215,8 +215,8 @@ void rewrite_finally (void);
void dump_end_try_catch_finally (void); void dump_end_try_catch_finally (void);
void dump_throw (operand); void dump_throw (operand);
bool dumper_variable_declaration_exists (literal_index_t); bool dumper_variable_declaration_exists (lit_cpointer_t);
void dump_variable_declaration (literal_index_t); void dump_variable_declaration (lit_cpointer_t);
opcode_counter_t dump_scope_code_flags_for_rewrite (void); opcode_counter_t dump_scope_code_flags_for_rewrite (void);
void rewrite_scope_code_flags (opcode_counter_t scope_code_flags_oc, void rewrite_scope_code_flags (opcode_counter_t scope_code_flags_oc,
+55 -45
View File
@@ -59,12 +59,26 @@ token_is (token_type tt)
return tok.type == tt; return tok.type == tt;
} }
static literal_index_t static uint16_t
token_data (void) token_data (void)
{ {
return tok.uid; return tok.uid;
} }
/**
* Get token data as `lit_cpointer_t`
*
* @return compressed pointer to token data
*/
static lit_cpointer_t
token_data_as_lit_cp (void)
{
lit_cpointer_t cp;
cp.packed_value = tok.uid;
return cp;
} /* token_data_as_lit_cp */
static void static void
skip_token (void) skip_token (void)
{ {
@@ -158,21 +172,18 @@ parse_property_name (void)
case TOK_STRING: case TOK_STRING:
case TOK_NUMBER: case TOK_NUMBER:
{ {
return literal_operand (token_data ()); return literal_operand (token_data_as_lit_cp ());
} }
case TOK_SMALL_INT: case TOK_SMALL_INT:
{ {
const literal lit = create_literal_from_num ((ecma_number_t) token_data ()); literal_t lit = lit_find_or_create_literal_from_num ((ecma_number_t) token_data ());
lexer_add_keyword_or_numeric_literal_if_not_present (lit); return literal_operand (lit_cpointer_t::compress (lit));
const literal_index_t lit_id = lexer_lookup_literal_uid (lit);
return literal_operand (lit_id);
} }
case TOK_KEYWORD: case TOK_KEYWORD:
{ {
const literal lit = create_literal_from_str_compute_len (lexer_keyword_to_string ((keyword) token_data ())); const char *s = lexer_keyword_to_string ((keyword) token_data ());
lexer_add_keyword_or_numeric_literal_if_not_present (lit); literal_t lit = lit_find_or_create_literal_from_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
const literal_index_t lit_id = lexer_lookup_literal_uid (lit); return literal_operand (lit_cpointer_t::compress (lit));
return literal_operand (lit_id);
} }
default: default:
{ {
@@ -207,11 +218,11 @@ parse_property_assignment (void)
{ {
bool is_setter; bool is_setter;
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get")) if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "get"))
{ {
is_setter = false; is_setter = false;
} }
else if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set")) else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "set"))
{ {
is_setter = true; is_setter = true;
} }
@@ -344,7 +355,7 @@ parse_argument_list (varg_list_type vlt, operand obj, uint8_t *args_count, opera
case VARG_FUNC_EXPR: case VARG_FUNC_EXPR:
{ {
current_token_must_be (TOK_NAME); current_token_must_be (TOK_NAME);
op = literal_operand (token_data ()); op = literal_operand (token_data_as_lit_cp ());
syntax_add_varg (op); syntax_add_varg (op);
syntax_check_for_eval_and_arguments_in_strict_mode (op, is_strict_mode (), tok.loc); syntax_check_for_eval_and_arguments_in_strict_mode (op, is_strict_mode (), tok.loc);
break; break;
@@ -451,7 +462,7 @@ parse_function_declaration (void)
jsp_label_t *masked_label_set_p = jsp_label_mask_set (); jsp_label_t *masked_label_set_p = jsp_label_mask_set ();
token_after_newlines_must_be (TOK_NAME); token_after_newlines_must_be (TOK_NAME);
const operand name = literal_operand (token_data ()); const operand name = literal_operand (token_data_as_lit_cp ());
skip_newlines (); skip_newlines ();
STACK_PUSH (scopes, scopes_tree_init (STACK_TOP (scopes))); STACK_PUSH (scopes, scopes_tree_init (STACK_TOP (scopes)));
@@ -495,7 +506,7 @@ parse_function_expression (void)
skip_newlines (); skip_newlines ();
if (token_is (TOK_NAME)) if (token_is (TOK_NAME))
{ {
const operand name = literal_operand (token_data ()); const operand name = literal_operand (token_data_as_lit_cp ());
skip_newlines (); skip_newlines ();
res = parse_argument_list (VARG_FUNC_EXPR, name, NULL, NULL); res = parse_argument_list (VARG_FUNC_EXPR, name, NULL, NULL);
} }
@@ -556,8 +567,8 @@ parse_literal (void)
{ {
switch (tok.type) switch (tok.type)
{ {
case TOK_NUMBER: return dump_number_assignment_res (token_data ()); case TOK_NUMBER: return dump_number_assignment_res (token_data_as_lit_cp ());
case TOK_STRING: return dump_string_assignment_res (token_data ()); case TOK_STRING: return dump_string_assignment_res (token_data_as_lit_cp ());
case TOK_NULL: return dump_null_assignment_res (); case TOK_NULL: return dump_null_assignment_res ();
case TOK_BOOL: return dump_boolean_assignment_res ((bool) token_data ()); case TOK_BOOL: return dump_boolean_assignment_res ((bool) token_data ());
case TOK_SMALL_INT: return dump_smallint_assignment_res ((idx_t) token_data ()); case TOK_SMALL_INT: return dump_smallint_assignment_res ((idx_t) token_data ());
@@ -592,7 +603,7 @@ parse_primary_expression (void)
case TOK_SMALL_INT: case TOK_SMALL_INT:
case TOK_NUMBER: case TOK_NUMBER:
case TOK_STRING: return parse_literal (); case TOK_STRING: return parse_literal ();
case TOK_NAME: return literal_operand (token_data ()); case TOK_NAME: return literal_operand (token_data_as_lit_cp ());
case TOK_OPEN_SQUARE: return parse_array_literal (); case TOK_OPEN_SQUARE: return parse_array_literal ();
case TOK_OPEN_BRACE: return parse_object_literal (); case TOK_OPEN_BRACE: return parse_object_literal ();
case TOK_OPEN_PAREN: case TOK_OPEN_PAREN:
@@ -680,17 +691,17 @@ parse_member_expression (operand *this_arg, operand *prop_gl)
skip_newlines (); skip_newlines ();
if (token_is (TOK_NAME)) if (token_is (TOK_NAME))
{ {
prop = dump_string_assignment_res (token_data ()); prop = dump_string_assignment_res (token_data_as_lit_cp ());
} }
else if (token_is (TOK_KEYWORD)) else if (token_is (TOK_KEYWORD))
{ {
const literal lit = create_literal_from_str_compute_len (lexer_keyword_to_string ((keyword) token_data ())); const char *s = lexer_keyword_to_string ((keyword) token_data ());
const literal_index_t lit_id = lexer_lookup_literal_uid (lit); literal_t lit = lit_find_literal_by_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
if (lit_id == INVALID_LITERAL) if (lit == NULL)
{ {
EMIT_ERROR ("Expected identifier"); EMIT_ERROR ("Expected identifier");
} }
prop = dump_string_assignment_res (lit_id); prop = dump_string_assignment_res (lit_cpointer_t::compress (lit));
} }
else else
{ {
@@ -769,7 +780,7 @@ parse_call_expression (operand *this_arg_gl, operand *prop_gl)
else if (tok.type == TOK_DOT) else if (tok.type == TOK_DOT)
{ {
token_after_newlines_must_be (TOK_NAME); token_after_newlines_must_be (TOK_NAME);
prop = dump_string_assignment_res (token_data ()); prop = dump_string_assignment_res (token_data_as_lit_cp ());
} }
expr = dump_prop_getter_res (expr, prop); expr = dump_prop_getter_res (expr, prop);
skip_newlines (); skip_newlines ();
@@ -1557,7 +1568,7 @@ static void
parse_variable_declaration (void) parse_variable_declaration (void)
{ {
current_token_must_be (TOK_NAME); current_token_must_be (TOK_NAME);
const operand name = literal_operand (token_data ()); const operand name = literal_operand (token_data_as_lit_cp ());
skip_newlines (); skip_newlines ();
if (token_is (TOK_EQ)) if (token_is (TOK_EQ))
@@ -2036,7 +2047,7 @@ parse_catch_clause (void)
token_after_newlines_must_be (TOK_OPEN_PAREN); token_after_newlines_must_be (TOK_OPEN_PAREN);
token_after_newlines_must_be (TOK_NAME); token_after_newlines_must_be (TOK_NAME);
const operand exception = literal_operand (token_data ()); const operand exception = literal_operand (token_data_as_lit_cp ());
syntax_check_for_eval_and_arguments_in_strict_mode (exception, is_strict_mode (), tok.loc); syntax_check_for_eval_and_arguments_in_strict_mode (exception, is_strict_mode (), tok.loc);
token_after_newlines_must_be (TOK_CLOSE_PAREN); token_after_newlines_must_be (TOK_CLOSE_PAREN);
@@ -2471,8 +2482,8 @@ static void process_keyword_names ()
skip_newlines (); skip_newlines ();
if (token_is (TOK_COLON)) if (token_is (TOK_COLON))
{ {
lexer_add_keyword_or_numeric_literal_if_not_present ( const char *s = lexer_keyword_to_string (kw);
create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); lit_find_or_create_literal_from_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
} }
else else
{ {
@@ -2481,8 +2492,8 @@ static void process_keyword_names ()
} }
else if (token_is (TOK_NAME)) else if (token_is (TOK_NAME))
{ {
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get") if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "get")
|| literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set")) || lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "set"))
{ {
skip_newlines (); skip_newlines ();
if (token_is (TOK_KEYWORD)) if (token_is (TOK_KEYWORD))
@@ -2491,8 +2502,8 @@ static void process_keyword_names ()
skip_newlines (); skip_newlines ();
if (token_is (TOK_OPEN_PAREN)) if (token_is (TOK_OPEN_PAREN))
{ {
lexer_add_keyword_or_numeric_literal_if_not_present ( const char *s = lexer_keyword_to_string (kw);
create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); lit_find_or_create_literal_from_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
} }
else else
{ {
@@ -2581,9 +2592,9 @@ skip_parens (void)
} }
static bool static bool
var_declared (literal_index_t var_id) var_declared (lit_cpointer_t var_cp)
{ {
return dumper_variable_declaration_exists (var_id); return dumper_variable_declaration_exists (var_cp);
} }
static void static void
@@ -2596,12 +2607,12 @@ preparse_var_decls (void)
{ {
if (token_is (TOK_NAME)) if (token_is (TOK_NAME))
{ {
if (!var_declared (token_data ())) if (!var_declared (token_data_as_lit_cp ()))
{ {
syntax_check_for_eval_and_arguments_in_strict_mode (literal_operand (token_data ()), syntax_check_for_eval_and_arguments_in_strict_mode (literal_operand (token_data_as_lit_cp ()),
is_strict_mode (), is_strict_mode (),
tok.loc); tok.loc);
dump_variable_declaration (token_data ()); dump_variable_declaration (token_data_as_lit_cp ());
} }
skip_token (); skip_token ();
continue; continue;
@@ -2653,7 +2664,8 @@ preparse_scope (bool is_global)
bool is_ref_eval_identifier = false; bool is_ref_eval_identifier = false;
bool is_use_strict = false; bool is_use_strict = false;
if (token_is (TOK_STRING) && literal_equal_s (lexer_get_literal_by_id (token_data ()), "use strict")) if (token_is (TOK_STRING) && lit_literal_equal_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
(const ecma_char_t *) "use strict"))
{ {
scopes_tree_set_strict_mode (STACK_TOP (scopes), true); scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
is_use_strict = true; is_use_strict = true;
@@ -2690,14 +2702,13 @@ preparse_scope (bool is_global)
{ {
if (token_is (TOK_NAME)) if (token_is (TOK_NAME))
{ {
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
"arguments")) (const ecma_char_t *) "arguments"))
{ {
is_ref_arguments_identifier = true; is_ref_arguments_identifier = true;
} }
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), (const ecma_char_t *) "eval"))
"eval"))
{ {
is_ref_eval_identifier = true; is_ref_eval_identifier = true;
} }
@@ -2774,10 +2785,9 @@ parser_parse_program (void)
JERRY_ASSERT (token_is (TOK_EOF)); JERRY_ASSERT (token_is (TOK_EOF));
dump_exit (); dump_exit ();
serializer_dump_literals (lexer_get_literals (), lexer_get_literals_count ()); serializer_dump_literals ();
serializer_merge_scopes_into_bytecode (); serializer_merge_scopes_into_bytecode ();
serializer_set_scope (NULL); serializer_set_scope (NULL);
serializer_set_strings_buffer (lexer_get_strings_cache ());
scopes_tree_free (STACK_TOP (scopes)); scopes_tree_free (STACK_TOP (scopes));
STACK_DROP (scopes, 1); STACK_DROP (scopes, 1);
+10 -13
View File
@@ -15,9 +15,6 @@
#include "scopes-tree.h" #include "scopes-tree.h"
#include "bytecode-data.h" #include "bytecode-data.h"
#include "mem-heap.h"
#include "jrt-libc-includes.h"
#include "lexer.h"
#define OPCODE(op) (__op__idx_##op) #define OPCODE(op) (__op__idx_##op)
#define HASH_SIZE 128 #define HASH_SIZE 128
@@ -103,7 +100,7 @@ scopes_tree_count_opcodes (scopes_tree t)
static uint16_t static uint16_t
lit_id_hash (void * lit_id) lit_id_hash (void * lit_id)
{ {
return *(literal_index_t *) lit_id % HASH_SIZE; return ((lit_cpointer_t *) lit_id)->packed_value % HASH_SIZE;
} }
static void static void
@@ -117,7 +114,7 @@ start_new_block_if_necessary (void)
hash_table_free (lit_id_to_uid); hash_table_free (lit_id_to_uid);
lit_id_to_uid = null_hash; lit_id_to_uid = null_hash;
} }
lit_id_to_uid = hash_table_init (sizeof (literal_index_t), sizeof (idx_t), HASH_SIZE, lit_id_hash, lit_id_to_uid = hash_table_init (sizeof (lit_cpointer_t), sizeof (idx_t), HASH_SIZE, lit_id_hash,
MEM_HEAP_ALLOC_SHORT_TERM); MEM_HEAP_ALLOC_SHORT_TERM);
} }
} }
@@ -157,8 +154,8 @@ change_uid (op_meta *om, lit_id_hash_table *lit_ids, uint16_t mask)
{ {
if (get_uid (om, i) == LITERAL_TO_REWRITE) if (get_uid (om, i) == LITERAL_TO_REWRITE)
{ {
JERRY_ASSERT (om->lit_id[i] != NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value != MEM_CP_NULL);
literal_index_t lit_id = om->lit_id[i]; lit_cpointer_t lit_id = om->lit_id[i];
idx_t *uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id); idx_t *uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id);
if (uid == NULL) if (uid == NULL)
{ {
@@ -173,12 +170,12 @@ change_uid (op_meta *om, lit_id_hash_table *lit_ids, uint16_t mask)
} }
else else
{ {
JERRY_ASSERT (om->lit_id[i] == NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
} }
} }
else else
{ {
JERRY_ASSERT (om->lit_id[i] == NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
} }
} }
} }
@@ -192,8 +189,8 @@ insert_uids_to_lit_id_map (op_meta *om, uint16_t mask)
{ {
if (get_uid (om, i) == LITERAL_TO_REWRITE) if (get_uid (om, i) == LITERAL_TO_REWRITE)
{ {
JERRY_ASSERT (om->lit_id[i] != NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value != MEM_CP_NULL);
literal_index_t lit_id = om->lit_id[i]; lit_cpointer_t lit_id = om->lit_id[i];
idx_t *uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id); idx_t *uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id);
if (uid == NULL) if (uid == NULL)
{ {
@@ -206,12 +203,12 @@ insert_uids_to_lit_id_map (op_meta *om, uint16_t mask)
} }
else else
{ {
JERRY_ASSERT (om->lit_id[i] == NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
} }
} }
else else
{ {
JERRY_ASSERT (om->lit_id[i] == NOT_A_LITERAL); JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
} }
} }
} }
+3 -2
View File
@@ -22,12 +22,13 @@
#include "hash-table.h" #include "hash-table.h"
#include "opcodes.h" #include "opcodes.h"
#include "lit-id-hash-table.h" #include "lit-id-hash-table.h"
#include "lit-literal.h"
#define NOT_A_LITERAL (INVALID_LITERAL - 1) #define NOT_A_LITERAL (lit_cpointer_t::null_cp ())
typedef struct typedef struct
{ {
literal_index_t lit_id[3]; lit_cpointer_t lit_id[3];
opcode_t op; opcode_t op;
} op_meta; } op_meta;
+9 -23
View File
@@ -15,9 +15,6 @@
#include "serializer.h" #include "serializer.h"
#include "bytecode-data.h" #include "bytecode-data.h"
#include "jrt.h"
#include "parser.h"
#include "jrt-libc-includes.h"
#include "pretty-printer.h" #include "pretty-printer.h"
static bytecode_data_t bytecode_data; static bytecode_data_t bytecode_data;
@@ -43,16 +40,8 @@ serializer_get_opcode (opcode_counter_t oc)
return bytecode_data.opcodes[oc]; return bytecode_data.opcodes[oc];
} }
literal lit_cpointer_t
serializer_get_literal_by_id (literal_index_t id) serializer_get_literal_cp_by_uid (uint8_t id, opcode_counter_t oc)
{
JERRY_ASSERT (id != INVALID_LITERAL);
JERRY_ASSERT (id < bytecode_data.literals_count);
return bytecode_data.literals[id];
}
literal_index_t
serializer_get_literal_id_by_uid (uint8_t id, opcode_counter_t oc)
{ {
if (bytecode_data.lit_id_hash == null_hash) if (bytecode_data.lit_id_hash == null_hash)
{ {
@@ -91,17 +80,14 @@ serializer_merge_scopes_into_bytecode (void)
} }
void void
serializer_dump_literals (const literal *literals, literal_index_t literals_count) serializer_dump_literals (void)
{ {
#ifdef JERRY_ENABLE_PRETTY_PRINTER #ifdef JERRY_ENABLE_PRETTY_PRINTER
if (print_opcodes) if (print_opcodes)
{ {
pp_literals (literals, literals_count); lit_dump_literals ();
} }
#endif #endif
bytecode_data.literals_count = literals_count;
bytecode_data.literals = literals;
} }
void void
@@ -185,9 +171,10 @@ serializer_init ()
print_opcodes = false; print_opcodes = false;
bytecode_data.strings_buffer = NULL; bytecode_data.strings_buffer = NULL;
bytecode_data.literals = NULL;
bytecode_data.opcodes = NULL; bytecode_data.opcodes = NULL;
bytecode_data.lit_id_hash = null_hash; bytecode_data.lit_id_hash = null_hash;
lit_init ();
} }
void serializer_set_show_opcodes (bool show_opcodes) void serializer_set_show_opcodes (bool show_opcodes)
@@ -206,9 +193,8 @@ serializer_free (void)
{ {
lit_id_hash_table_free (bytecode_data.lit_id_hash); lit_id_hash_table_free (bytecode_data.lit_id_hash);
} }
if (bytecode_data.literals != NULL)
{
mem_heap_free_block ((uint8_t *) bytecode_data.literals);
}
mem_heap_free_block ((uint8_t *) bytecode_data.opcodes); mem_heap_free_block ((uint8_t *) bytecode_data.opcodes);
lit_finalize ();
} }
+2 -4
View File
@@ -20,18 +20,16 @@
#include "ecma-globals.h" #include "ecma-globals.h"
#include "opcodes.h" #include "opcodes.h"
#include "vm.h" #include "vm.h"
#include "literal.h"
#include "scopes-tree.h" #include "scopes-tree.h"
void serializer_init (); void serializer_init ();
void serializer_set_show_opcodes (bool show_opcodes); void serializer_set_show_opcodes (bool show_opcodes);
op_meta serializer_get_op_meta (opcode_counter_t); op_meta serializer_get_op_meta (opcode_counter_t);
opcode_t serializer_get_opcode (opcode_counter_t); opcode_t serializer_get_opcode (opcode_counter_t);
literal serializer_get_literal_by_id (literal_index_t); lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, opcode_counter_t);
literal_index_t serializer_get_literal_id_by_uid (uint8_t, opcode_counter_t);
const void *serializer_get_bytecode (void); const void *serializer_get_bytecode (void);
void serializer_set_strings_buffer (const ecma_char_t *); void serializer_set_strings_buffer (const ecma_char_t *);
void serializer_dump_literals (const literal *, literal_index_t); void serializer_dump_literals ();
void serializer_set_scope (scopes_tree); void serializer_set_scope (scopes_tree);
void serializer_merge_scopes_into_bytecode (void); void serializer_merge_scopes_into_bytecode (void);
void serializer_dump_op_meta (op_meta); void serializer_dump_op_meta (op_meta);
+23 -19
View File
@@ -23,7 +23,7 @@
typedef struct typedef struct
{ {
prop_type type; prop_type type;
literal lit; literal_t lit;
} prop_literal; } prop_literal;
enum enum
@@ -39,7 +39,7 @@ enum
STATIC_STACK (U8, uint8_t) STATIC_STACK (U8, uint8_t)
static prop_literal static prop_literal
create_prop_literal (literal lit, prop_type type) create_prop_literal (literal_t lit, prop_type type)
{ {
prop_literal ret; prop_literal ret;
@@ -59,7 +59,7 @@ void
syntax_add_prop_name (operand op, prop_type pt) syntax_add_prop_name (operand op, prop_type pt)
{ {
JERRY_ASSERT (op.type == OPERAND_LITERAL); JERRY_ASSERT (op.type == OPERAND_LITERAL);
STACK_PUSH (props, create_prop_literal (lexer_get_literal_by_id (op.data.lit_id), pt)); STACK_PUSH (props, create_prop_literal (lit_get_literal_by_cp (op.data.lit_id), pt));
} }
void void
@@ -94,34 +94,34 @@ syntax_check_for_duplication_of_prop_names (bool is_strict, locus loc __attr_unu
JERRY_ASSERT (current.type == PROP_DATA JERRY_ASSERT (current.type == PROP_DATA
|| current.type == PROP_GET || current.type == PROP_GET
|| current.type == PROP_SET); || current.type == PROP_SET);
if (literal_equal (previous.lit, current.lit)) if (lit_literal_equal (previous.lit, current.lit))
{ {
/*a*/ /*a*/
if (is_strict && previous.type == PROP_DATA && current.type == PROP_DATA) if (is_strict && previous.type == PROP_DATA && current.type == PROP_DATA)
{ {
PARSE_ERROR_VARG ("Duplication of parameter name '%s' in ObjectDeclaration is not allowed in strict mode", PARSE_ERROR_VARG ("Duplication of parameter name '%s' in ObjectDeclaration is not allowed in strict mode",
loc, (const char *) literal_to_zt (current.lit)); loc, lit_literal_to_str_internal_buf (current.lit));
} }
/*b*/ /*b*/
if (previous.type == PROP_DATA if (previous.type == PROP_DATA
&& (current.type == PROP_SET || current.type == PROP_GET)) && (current.type == PROP_SET || current.type == PROP_GET))
{ {
PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be both data and accessor", PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be both data and accessor",
loc, (const char *) literal_to_zt (current.lit)); loc, lit_literal_to_str_internal_buf (current.lit));
} }
/*c*/ /*c*/
if (current.type == PROP_DATA if (current.type == PROP_DATA
&& (previous.type == PROP_SET || previous.type == PROP_GET)) && (previous.type == PROP_SET || previous.type == PROP_GET))
{ {
PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be both data and accessor", PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be both data and accessor",
loc, (const char *) literal_to_zt (current.lit)); loc, lit_literal_to_str_internal_buf (current.lit));
} }
/*d*/ /*d*/
if ((previous.type == PROP_SET && current.type == PROP_SET) if ((previous.type == PROP_SET && current.type == PROP_SET)
|| (previous.type == PROP_GET && current.type == PROP_GET)) || (previous.type == PROP_GET && current.type == PROP_GET))
{ {
PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be accessor of same type", PARSE_ERROR_VARG ("Parameter name '%s' in ObjectDeclaration may not be accessor of same type",
loc, (const char *) literal_to_zt (current.lit)); loc, lit_literal_to_str_internal_buf (current.lit));
} }
} }
} }
@@ -140,7 +140,7 @@ syntax_start_checking_of_vargs (void)
void syntax_add_varg (operand op) void syntax_add_varg (operand op)
{ {
JERRY_ASSERT (op.type == OPERAND_LITERAL); JERRY_ASSERT (op.type == OPERAND_LITERAL);
STACK_PUSH (props, create_prop_literal (lexer_get_literal_by_id (op.data.lit_id), VARG)); STACK_PUSH (props, create_prop_literal (lit_get_literal_by_cp (op.data.lit_id), VARG));
} }
static void static void
@@ -148,10 +148,10 @@ emit_error_on_eval_and_arguments (operand op, locus loc __attr_unused___)
{ {
if (op.type == OPERAND_LITERAL) if (op.type == OPERAND_LITERAL)
{ {
if (literal_equal_type_zt (lexer_get_literal_by_id (op.data.lit_id), if (lit_literal_equal_type_zt (lit_get_literal_by_cp (op.data.lit_id),
ecma_get_magic_string_zt (ECMA_MAGIC_STRING_ARGUMENTS)) ecma_get_magic_string_zt (ECMA_MAGIC_STRING_ARGUMENTS))
|| literal_equal_type_zt (lexer_get_literal_by_id (op.data.lit_id), || lit_literal_equal_type_zt (lit_get_literal_by_cp (op.data.lit_id),
ecma_get_magic_string_zt (ECMA_MAGIC_STRING_EVAL))) ecma_get_magic_string_zt (ECMA_MAGIC_STRING_EVAL)))
{ {
PARSE_ERROR ("'eval' and 'arguments' are not allowed here in strict mode", loc); PARSE_ERROR ("'eval' and 'arguments' are not allowed here in strict mode", loc);
} }
@@ -179,17 +179,21 @@ syntax_check_for_syntax_errors_in_formal_param_list (bool is_strict, locus loc _
for (uint8_t i = (uint8_t) (STACK_TOP (U8) + 1); i < STACK_SIZE (props); i = (uint8_t) (i + 1)) for (uint8_t i = (uint8_t) (STACK_TOP (U8) + 1); i < STACK_SIZE (props); i = (uint8_t) (i + 1))
{ {
JERRY_ASSERT (STACK_ELEMENT (props, i).type == VARG); JERRY_ASSERT (STACK_ELEMENT (props, i).type == VARG);
const literal previous = STACK_ELEMENT (props, i).lit; literal_t previous = STACK_ELEMENT (props, i).lit;
JERRY_ASSERT (previous.type == LIT_STR || previous.type == LIT_MAGIC_STR || previous.type == LIT_MAGIC_STR_EX); JERRY_ASSERT (previous->get_type () == LIT_STR_T
|| previous->get_type () == LIT_MAGIC_STR_T
|| previous->get_type () == LIT_MAGIC_STR_EX_T);
for (uint8_t j = STACK_TOP (U8); j < i; j = (uint8_t) (j + 1)) for (uint8_t j = STACK_TOP (U8); j < i; j = (uint8_t) (j + 1))
{ {
JERRY_ASSERT (STACK_ELEMENT (props, j).type == VARG); JERRY_ASSERT (STACK_ELEMENT (props, j).type == VARG);
const literal current = STACK_ELEMENT (props, j).lit; literal_t current = STACK_ELEMENT (props, j).lit;
JERRY_ASSERT (current.type == LIT_STR || current.type == LIT_MAGIC_STR || current.type == LIT_MAGIC_STR_EX); JERRY_ASSERT (current->get_type () == LIT_STR_T
if (literal_equal_type (previous, current)) || current->get_type () == LIT_MAGIC_STR_T
|| current->get_type () == LIT_MAGIC_STR_EX_T);
if (lit_literal_equal_type (previous, current))
{ {
PARSE_ERROR_VARG ("Duplication of literal '%s' in FormalParameterList is not allowed in strict mode", PARSE_ERROR_VARG ("Duplication of literal '%s' in FormalParameterList is not allowed in strict mode",
loc, (const char *) literal_to_zt (previous)); loc, lit_literal_to_str_internal_buf (previous));
} }
} }
} }
-1
View File
@@ -16,7 +16,6 @@
#ifndef SYNTAX_ERRORS_H #ifndef SYNTAX_ERRORS_H
#define SYNTAX_ERRORS_H #define SYNTAX_ERRORS_H
#include "literal.h"
#include "opcodes-dumper.h" #include "opcodes-dumper.h"
#include "lexer.h" #include "lexer.h"
@@ -63,12 +63,12 @@ opfunc_try_block (opcode_t opdata, /**< operation data */
JERRY_ASSERT (next_opcode.op_idx == __op__idx_meta); JERRY_ASSERT (next_opcode.op_idx == __op__idx_meta);
JERRY_ASSERT (next_opcode.data.meta.type == OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER); JERRY_ASSERT (next_opcode.data.meta.type == OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER);
const literal_index_t catch_exc_val_var_name_lit_idx = serializer_get_literal_id_by_uid ( lit_cpointer_t catch_exc_val_var_name_lit_cp = serializer_get_literal_cp_by_uid (
next_opcode.data.meta.data_1, next_opcode.data.meta.data_1,
int_data->pos); int_data->pos);
int_data->pos++; int_data->pos++;
ecma_string_t *catch_exc_var_name_str_p = ecma_new_ecma_string_from_lit_index (catch_exc_val_var_name_lit_idx); ecma_string_t *catch_exc_var_name_str_p = ecma_new_ecma_string_from_lit_cp (catch_exc_val_var_name_lit_cp);
ecma_object_t *old_env_p = int_data->lex_env_p; ecma_object_t *old_env_p = int_data->lex_env_p;
ecma_object_t *catch_env_p = ecma_create_decl_lex_env (old_env_p); ecma_object_t *catch_env_p = ecma_create_decl_lex_env (old_env_p);
+6 -6
View File
@@ -91,9 +91,9 @@ get_variable_value (int_data_t *int_data, /**< interpreter context */
else else
{ {
ecma_string_t var_name_string; ecma_string_t var_name_string;
const literal_index_t lit_id = serializer_get_literal_id_by_uid (var_idx, int_data->pos); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, int_data->pos);
JERRY_ASSERT (lit_id != INVALID_LITERAL); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_new_ecma_string_on_stack_from_lit_index (&var_name_string, lit_id); ecma_new_ecma_string_on_stack_from_lit_cp (&var_name_string, lit_cp);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p, ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p,
&var_name_string); &var_name_string);
@@ -158,9 +158,9 @@ set_variable_value (int_data_t *int_data, /**< interpreter context */
else else
{ {
ecma_string_t var_name_string; ecma_string_t var_name_string;
const literal_index_t lit_id = serializer_get_literal_id_by_uid (var_idx, lit_oc); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, lit_oc);
JERRY_ASSERT (lit_id != INVALID_LITERAL); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_new_ecma_string_on_stack_from_lit_index (&var_name_string, lit_id); ecma_new_ecma_string_on_stack_from_lit_cp (&var_name_string, lit_cp);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p, ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p,
&var_name_string); &var_name_string);
+3 -3
View File
@@ -96,10 +96,10 @@ fill_params_list (int_data_t *int_data, /**< interpreter context */
JERRY_ASSERT (next_opcode.op_idx == __op__idx_meta); JERRY_ASSERT (next_opcode.op_idx == __op__idx_meta);
JERRY_ASSERT (next_opcode.data.meta.type == OPCODE_META_TYPE_VARG); JERRY_ASSERT (next_opcode.data.meta.type == OPCODE_META_TYPE_VARG);
const literal_index_t param_name_lit_idx = serializer_get_literal_id_by_uid (next_opcode.data.meta.data_1, const lit_cpointer_t param_name_lit_idx = serializer_get_literal_cp_by_uid (next_opcode.data.meta.data_1,
int_data->pos); int_data->pos);
params_names[param_index] = ecma_new_ecma_string_from_lit_index (param_name_lit_idx); params_names[param_index] = ecma_new_ecma_string_from_lit_cp (param_name_lit_idx);
int_data->pos++; int_data->pos++;
} }
+27 -33
View File
@@ -16,8 +16,6 @@
#include "jrt.h" #include "jrt.h"
#include "opcodes.h" #include "opcodes.h"
#include "opcodes-ecma-support.h" #include "opcodes-ecma-support.h"
#include "serializer.h"
#include "vm.h"
/** /**
* Note: * Note:
@@ -98,8 +96,8 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
} }
else if (type_value_right == OPCODE_ARG_TYPE_STRING) else if (type_value_right == OPCODE_ARG_TYPE_STRING)
{ {
const literal_index_t lit_id = serializer_get_literal_id_by_uid (src_val_descr, int_data->pos); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, int_data->pos);
ecma_string_t *string_p = ecma_new_ecma_string_from_lit_index (lit_id); ecma_string_t *string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ret_value = set_variable_value (int_data, ret_value = set_variable_value (int_data,
int_data->pos, int_data->pos,
@@ -127,11 +125,11 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
{ {
ecma_number_t *num_p = int_data->tmp_num_p; ecma_number_t *num_p = int_data->tmp_num_p;
const literal_index_t lit_id = serializer_get_literal_id_by_uid (src_val_descr, int_data->pos); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, int_data->pos);
const literal lit = serializer_get_literal_by_id (lit_id); literal_t lit = lit_get_literal_by_cp (lit_cp);
JERRY_ASSERT (lit.type == LIT_NUMBER); JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
*num_p = lit.data.num; *num_p = lit_charset_literal_get_number (lit);
ret_value = set_variable_value (int_data, ret_value = set_variable_value (int_data,
int_data->pos, int_data->pos,
@@ -142,11 +140,11 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
{ {
ecma_number_t *num_p = int_data->tmp_num_p; ecma_number_t *num_p = int_data->tmp_num_p;
const literal_index_t lit_id = serializer_get_literal_id_by_uid (src_val_descr, int_data->pos); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, int_data->pos);
const literal lit = serializer_get_literal_by_id (lit_id); literal_t lit = lit_get_literal_by_cp (lit_cp);
JERRY_ASSERT (lit.type == LIT_NUMBER); JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
*num_p = ecma_number_negate (lit.data.num); *num_p = lit_charset_literal_get_number (lit);
ret_value = set_variable_value (int_data, ret_value = set_variable_value (int_data,
int_data->pos, int_data->pos,
@@ -397,11 +395,10 @@ ecma_completion_value_t
opfunc_var_decl (opcode_t opdata, /**< operation data */ opfunc_var_decl (opcode_t opdata, /**< operation data */
int_data_t *int_data) /**< interpreter context */ int_data_t *int_data) /**< interpreter context */
{ {
const literal_index_t lit_id = serializer_get_literal_id_by_uid (opdata.data.var_decl.variable_name, lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (opdata.data.var_decl.variable_name, int_data->pos);
int_data->pos); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
JERRY_ASSERT (lit_id != INVALID_LITERAL);
ecma_string_t *var_name_string_p = ecma_new_ecma_string_from_lit_index (lit_id); ecma_string_t *var_name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
if (!ecma_op_has_binding (int_data->lex_env_p, var_name_string_p)) if (!ecma_op_has_binding (int_data->lex_env_p, var_name_string_p))
{ {
@@ -437,8 +434,7 @@ opfunc_var_decl (opcode_t opdata, /**< operation data */
*/ */
static ecma_completion_value_t static ecma_completion_value_t
function_declaration (int_data_t *int_data, /**< interpreter context */ function_declaration (int_data_t *int_data, /**< interpreter context */
literal_index_t function_name_lit_id, /**< index of literal lit_cpointer_t function_name_lit_cp, /**< compressed pointer to literal with function name */
with function name */
ecma_string_t* args_names[], /**< names of arguments */ ecma_string_t* args_names[], /**< names of arguments */
ecma_length_t args_number) /**< number of arguments */ ecma_length_t args_number) /**< number of arguments */
{ {
@@ -465,7 +461,7 @@ function_declaration (int_data_t *int_data, /**< interpreter context */
do_instantiate_arguments_object = false; do_instantiate_arguments_object = false;
} }
ecma_string_t *function_name_string_p = ecma_new_ecma_string_from_lit_index (function_name_lit_id); ecma_string_t *function_name_string_p = ecma_new_ecma_string_from_lit_cp (function_name_lit_cp);
ecma_completion_value_t ret_value = ecma_op_function_declaration (int_data->lex_env_p, ecma_completion_value_t ret_value = ecma_op_function_declaration (int_data->lex_env_p,
function_name_string_p, function_name_string_p,
@@ -495,8 +491,7 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
const idx_t function_name_idx = opdata.data.func_decl_n.name_lit_idx; const idx_t function_name_idx = opdata.data.func_decl_n.name_lit_idx;
const ecma_length_t params_number = opdata.data.func_decl_n.arg_list; const ecma_length_t params_number = opdata.data.func_decl_n.arg_list;
literal_index_t function_name_lit_id = serializer_get_literal_id_by_uid (function_name_idx, lit_cpointer_t function_name_lit_cp = serializer_get_literal_cp_by_uid (function_name_idx, int_data->pos);
int_data->pos);
int_data->pos++; int_data->pos++;
@@ -507,7 +502,7 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
fill_params_list (int_data, params_number, params_names); fill_params_list (int_data, params_number, params_names);
ret_value = function_declaration (int_data, ret_value = function_declaration (int_data,
function_name_lit_id, function_name_lit_cp,
params_names, params_names,
params_number); params_number);
@@ -578,12 +573,11 @@ opfunc_func_expr_n (opcode_t opdata, /**< operation data */
{ {
scope_p = ecma_create_decl_lex_env (int_data->lex_env_p); scope_p = ecma_create_decl_lex_env (int_data->lex_env_p);
const literal_index_t lit_id = serializer_get_literal_id_by_uid (function_name_lit_idx, lit_oc); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (function_name_lit_idx, lit_oc);
JERRY_ASSERT (lit_id != INVALID_LITERAL); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
function_name_string_p = ecma_new_ecma_string_from_lit_index (lit_id); function_name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ecma_op_create_immutable_binding (scope_p, ecma_op_create_immutable_binding (scope_p, function_name_string_p);
function_name_string_p);
} }
else else
{ {
@@ -1413,10 +1407,10 @@ evaluate_arg_for_typeof (int_data_t *int_data, /**< interpreter context */
} }
else else
{ {
const literal_index_t lit_id = serializer_get_literal_id_by_uid (var_idx, int_data->pos); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, int_data->pos);
JERRY_ASSERT (lit_id != INVALID_LITERAL); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_string_t *var_name_string_p = ecma_new_ecma_string_from_lit_index (lit_id); ecma_string_t *var_name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p, ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data->lex_env_p,
var_name_string_p); var_name_string_p);
@@ -1529,10 +1523,10 @@ opfunc_delete_var (opcode_t opdata, /**< operation data */
ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
const literal_index_t lit_id = serializer_get_literal_id_by_uid (name_lit_idx, lit_oc); lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (name_lit_idx, lit_oc);
JERRY_ASSERT (lit_id != INVALID_LITERAL); JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_string_t *name_string_p = ecma_new_ecma_string_from_lit_index (lit_id); ecma_string_t *name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ecma_reference_t ref = ecma_op_get_identifier_reference (int_data->lex_env_p, ecma_reference_t ref = ecma_op_get_identifier_reference (int_data->lex_env_p,
name_string_p, name_string_p,
+30 -94
View File
@@ -23,6 +23,7 @@
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "serializer.h" #include "serializer.h"
#include "lit-literal.h"
#define NAME_TO_ID(op) (__op__idx_##op) #define NAME_TO_ID(op) (__op__idx_##op)
@@ -44,57 +45,6 @@ static uint8_t opcode_sizes[] =
0 0
}; };
static void
dump_literal (literal lit)
{
switch (lit.type)
{
case LIT_NUMBER:
{
if (ecma_number_is_nan (lit.data.num))
{
printf ("%s : NUMBER", "NaN");
}
else
{
printf ("%d : Truncated NUMBER", (int) lit.data.num);
}
break;
}
case LIT_MAGIC_STR:
{
printf ("%s : MAGIC STRING", (const char *) ecma_get_magic_string_zt (lit.data.magic_str_id));
break;
}
case LIT_MAGIC_STR_EX:
{
printf ("%s : EXT MAGIC STRING", (const char *) ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id));
break;
}
case LIT_STR:
{
printf ("%s : STRING", (const char *) (lit.data.lp.str));
break;
}
default:
{
JERRY_UNREACHABLE ();
}
}
}
void
pp_literals (const literal *lits, literal_index_t size)
{
printf ("LITERALS %lu:\n", (unsigned long) size);
for (literal_index_t i = 0; i < size; i++)
{
printf ("%3lu ", (unsigned long) i);
dump_literal (lits[i]);
putchar ('\n');
}
}
static char buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; static char buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
static void static void
@@ -104,20 +54,10 @@ clear_temp_buffer (void)
} }
static const char * static const char *
lit_id_to_str (literal_index_t id) lit_cp_to_str (lit_cpointer_t cp)
{ {
literal lit = lexer_get_literal_by_id (id); literal_t lit = lit_get_literal_by_cp (cp);
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX) return lit_literal_to_str_internal_buf (lit);
{
return (char *) literal_to_zt (lit);
}
else
{
JERRY_ASSERT (lit.type == LIT_NUMBER);
clear_temp_buffer ();
ecma_number_to_zt_string (lit.data.num, (ecma_char_t *) buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
return buff;
}
} }
static const char * static const char *
@@ -146,7 +86,7 @@ tmp_id_to_str (idx_t id)
} }
static const char * static const char *
var_to_str (opcode_t opcode, literal_index_t lit_ids[], opcode_counter_t oc, uint8_t current_arg) var_to_str (opcode_t opcode, lit_cpointer_t lit_ids[], opcode_counter_t oc, uint8_t current_arg)
{ {
raw_opcode raw = *(raw_opcode*) &opcode; raw_opcode raw = *(raw_opcode*) &opcode;
if (raw.uids[current_arg] == LITERAL_TO_REWRITE) if (raw.uids[current_arg] == LITERAL_TO_REWRITE)
@@ -155,9 +95,8 @@ var_to_str (opcode_t opcode, literal_index_t lit_ids[], opcode_counter_t oc, uin
{ {
return "hz"; return "hz";
} }
JERRY_ASSERT (lit_ids[current_arg - 1] != NOT_A_LITERAL JERRY_ASSERT (lit_ids[current_arg - 1].packed_value != MEM_CP_NULL);
&& lit_ids[current_arg - 1] != INVALID_LITERAL); return lit_cp_to_str (lit_ids[current_arg - 1]);
return lit_id_to_str (lit_ids[current_arg - 1]);
} }
else if (raw.uids[current_arg] >= 128) else if (raw.uids[current_arg] >= 128)
{ {
@@ -165,14 +104,15 @@ var_to_str (opcode_t opcode, literal_index_t lit_ids[], opcode_counter_t oc, uin
} }
else else
{ {
return lit_id_to_str (serializer_get_literal_id_by_uid (raw.uids[current_arg], oc)); return lit_cp_to_str (serializer_get_literal_cp_by_uid (raw.uids[current_arg], oc));
} }
} }
static void static void
pp_printf (const char *format, opcode_t opcode, literal_index_t lit_ids[], opcode_counter_t oc) pp_printf (const char *format, opcode_t opcode, lit_cpointer_t lit_ids[], opcode_counter_t oc, uint8_t start_arg)
{ {
uint8_t current_arg = 1; uint8_t current_arg = start_arg;
JERRY_ASSERT (current_arg <= 3);
while (*format) while (*format)
{ {
if (*format != '%') if (*format != '%')
@@ -187,12 +127,14 @@ pp_printf (const char *format, opcode_t opcode, literal_index_t lit_ids[], opcod
{ {
case 'd': case 'd':
{ {
JERRY_ASSERT (current_arg <= 3);
raw_opcode raw = *(raw_opcode*) &opcode; raw_opcode raw = *(raw_opcode*) &opcode;
printf ("%d", raw.uids[current_arg]); printf ("%d", raw.uids[current_arg]);
break; break;
} }
case 's': case 's':
{ {
JERRY_ASSERT (current_arg <= 3);
printf ("%s", var_to_str (opcode, lit_ids, oc, current_arg)); printf ("%s", var_to_str (opcode, lit_ids, oc, current_arg));
break; break;
} }
@@ -208,7 +150,7 @@ pp_printf (const char *format, opcode_t opcode, literal_index_t lit_ids[], opcod
} }
#define PP_OP(op_name, format) \ #define PP_OP(op_name, format) \
case NAME_TO_ID (op_name): pp_printf (format, opm.op, opm.lit_id, oc); break; case NAME_TO_ID (op_name): pp_printf (format, opm.op, opm.lit_id, oc, 1); break;
#define VAR(i) var_to_str (opm.op, opm.lit_id, oc, i) #define VAR(i) var_to_str (opm.op, opm.lit_id, oc, i)
#define OC(i, j) __extension__({ raw_opcode* raw = (raw_opcode *) &opm.op; \ #define OC(i, j) __extension__({ raw_opcode* raw = (raw_opcode *) &opm.op; \
calc_opcode_counter_from_idx_idx (raw->uids[i], raw->uids[j]); }) calc_opcode_counter_from_idx_idx (raw->uids[i], raw->uids[j]); })
@@ -326,7 +268,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
{ {
if (opm.op.data.call_n.arg_list == 0) if (opm.op.data.call_n.arg_list == 0)
{ {
printf ("%s = %s ();", VAR (1), VAR (2)); pp_printf ("%s = %s ();", opm.op, opm.lit_id, oc, 1);
} }
else else
{ {
@@ -362,7 +304,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
{ {
if (opm.op.data.construct_n.arg_list == 0) if (opm.op.data.construct_n.arg_list == 0)
{ {
printf ("%s = new %s;", VAR (1), VAR (2)); pp_printf ("%s = new %s;", opm.op, opm.lit_id, oc, 1);
} }
else else
{ {
@@ -394,7 +336,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
} }
else else
{ {
printf ("%s = function %s ();", VAR (1), VAR (2)); pp_printf ("%s = function %s ();", opm.op, opm.lit_id, oc, 1);
} }
} }
else else
@@ -473,13 +415,12 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
{ {
case NAME_TO_ID (call_n): case NAME_TO_ID (call_n):
{ {
printf ("%s = %s (", var_to_str (start_op, NULL, start, 1), pp_printf ("%s = %s (", start_op, NULL, start, 1);
var_to_str (start_op, NULL, start, 2));
break; break;
} }
case NAME_TO_ID (native_call): case NAME_TO_ID (native_call):
{ {
printf ("%s = ", var_to_str (start_op, NULL, start, 1)); pp_printf ("%s = ", start_op, NULL, start, 1);
switch (start_op.data.native_call.name) switch (start_op.data.native_call.name)
{ {
case OPCODE_NATIVE_CALL_LED_TOGGLE: printf ("LEDToggle ("); break; case OPCODE_NATIVE_CALL_LED_TOGGLE: printf ("LEDToggle ("); break;
@@ -494,36 +435,34 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
} }
case NAME_TO_ID (construct_n): case NAME_TO_ID (construct_n):
{ {
printf ("%s = new %s (", var_to_str (start_op, NULL, start, 1), pp_printf ("%s = new %s (", start_op, NULL, start, 1);
var_to_str (start_op, NULL, start, 2));
break; break;
} }
case NAME_TO_ID (func_decl_n): case NAME_TO_ID (func_decl_n):
{ {
printf ("function %s (", var_to_str (start_op, NULL, start, 1)); pp_printf ("function %s (", start_op, NULL, start, 1);
break; break;
} }
case NAME_TO_ID (func_expr_n): case NAME_TO_ID (func_expr_n):
{ {
if (start_op.data.func_expr_n.name_lit_idx == INVALID_VALUE) if (start_op.data.func_expr_n.name_lit_idx == INVALID_VALUE)
{ {
printf ("%s = function (", var_to_str (start_op, NULL, start, 1)); pp_printf ("%s = function (", start_op, NULL, start, 1);
} }
else else
{ {
printf ("%s = function %s (", var_to_str (start_op, NULL, start, 1), pp_printf ("%s = function %s (", start_op, NULL, start, 1);
var_to_str (start_op, NULL, start, 2));
} }
break; break;
} }
case NAME_TO_ID (array_decl): case NAME_TO_ID (array_decl):
{ {
printf ("%s = [", var_to_str (start_op, NULL, start, 1)); pp_printf ("%s = [", start_op, NULL, start, 1);
break; break;
} }
case NAME_TO_ID (obj_decl): case NAME_TO_ID (obj_decl):
{ {
printf ("%s = {", var_to_str (start_op, NULL, start, 1)); pp_printf ("%s = {", start_op, NULL, start, 1);
break; break;
} }
default: default:
@@ -542,30 +481,27 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
{ {
case OPCODE_META_TYPE_THIS_ARG: case OPCODE_META_TYPE_THIS_ARG:
{ {
printf ("this_arg = %s", var_to_str (meta_op, NULL, counter, 2)); pp_printf ("this_arg = %s", meta_op, NULL, counter, 2);
break; break;
} }
case OPCODE_META_TYPE_VARG: case OPCODE_META_TYPE_VARG:
{ {
printf ("%s", var_to_str (meta_op, NULL, counter, 2)); pp_printf ("%s", meta_op, NULL, counter, 2);
break; break;
} }
case OPCODE_META_TYPE_VARG_PROP_DATA: case OPCODE_META_TYPE_VARG_PROP_DATA:
{ {
printf ("%s:%s", var_to_str (meta_op, NULL, counter, 2), pp_printf ("%s:%s", meta_op, NULL, counter, 2);
var_to_str (meta_op, NULL, counter, 3));
break; break;
} }
case OPCODE_META_TYPE_VARG_PROP_GETTER: case OPCODE_META_TYPE_VARG_PROP_GETTER:
{ {
printf ("%s = get %s ();", var_to_str (meta_op, NULL, counter, 2), pp_printf ("%s = get %s ();", meta_op, NULL, counter, 2);
var_to_str (meta_op, NULL, counter, 3));
break; break;
} }
case OPCODE_META_TYPE_VARG_PROP_SETTER: case OPCODE_META_TYPE_VARG_PROP_SETTER:
{ {
printf ("%s = set (%s);", var_to_str (meta_op, NULL, counter, 2), pp_printf ("%s = set (%s);", meta_op, NULL, counter, 2);
var_to_str (meta_op, NULL, counter, 3));
break; break;
} }
default: default:
-2
View File
@@ -19,12 +19,10 @@
#include "jrt.h" #include "jrt.h"
#ifdef JERRY_ENABLE_PRETTY_PRINTER #ifdef JERRY_ENABLE_PRETTY_PRINTER
#include "vm.h" #include "vm.h"
#include "literal.h"
#include "scopes-tree.h" #include "scopes-tree.h"
void pp_opcode (opcode_counter_t, opcode_t, bool); void pp_opcode (opcode_counter_t, opcode_t, bool);
void pp_op_meta (opcode_counter_t, op_meta, bool); void pp_op_meta (opcode_counter_t, op_meta, bool);
void pp_literals (const literal *, literal_index_t);
#endif // JERRY_ENABLE_PRETTY_PRINTER #endif // JERRY_ENABLE_PRETTY_PRINTER
#endif // PRETTY_PRINTER #endif // PRETTY_PRINTER
+1 -1
View File
@@ -96,7 +96,7 @@ memcmp (const void *s1, /**< first area */
/** /**
* memcpy * memcpy
*/ */
void * void * __attr_used___ // FIXME
memcpy (void *s1, /**< destination */ memcpy (void *s1, /**< destination */
const void *s2, /**< source */ const void *s2, /**< source */
size_t n) /**< bytes number */ size_t n) /**< bytes number */
-5
View File
@@ -16,16 +16,11 @@
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
#include "literal.h"
#define NAME_TO_ID(op) (__op__idx_##op) #define NAME_TO_ID(op) (__op__idx_##op)
#define __OPCODE_SIZE(name, arg1, arg2, arg3) \ #define __OPCODE_SIZE(name, arg1, arg2, arg3) \
(uint8_t) (sizeof (__op_##name) + 1), (uint8_t) (sizeof (__op_##name) + 1),
#define LP(s) create_literal_from_str_compute_len (s)
#define NUM(s) create_literal_from_num (s)
static uint8_t opcode_sizes[] = static uint8_t opcode_sizes[] =
{ {
OP_LIST (OPCODE_SIZE) OP_LIST (OPCODE_SIZE)