Skip to content

Refactor literal-storage to not use C++ features #791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "lit-globals.h"
#include "lit-magic-strings.h"
#include "mem-allocator.h"
#include "rcs-recordset.h"

/** \addtogroup compressedpointer Compressed pointer
* @{
Expand Down Expand Up @@ -787,16 +786,6 @@ typedef enum
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
} ecma_string_container_t;

FIXME (Move to library that should define the type (literal.h /* ? */))

/**
* Literal and compressed pointer to literal
*/
typedef rcs_record_t *literal_t;
typedef rcs_cpointer_t lit_cpointer_t;

#define NOT_A_LITERAL (lit_cpointer_t::null_cp ())

/**
* ECMA string-value descriptor
*/
Expand Down
32 changes: 18 additions & 14 deletions jerry-core/ecma/base/ecma-helpers-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "lit-char-helpers.h"
#include "lit-magic-strings.h"
#include "vm.h"
#include "rcs-records.h"

/**
* Maximum length of strings' concatenation
Expand Down Expand Up @@ -328,24 +329,27 @@ ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, /**< descriptor to i
JERRY_ASSERT (is_stack_var == (!mem_is_heap_pointer (string_p)));
#endif /* !JERRY_NDEBUG */

literal_t lit = lit_get_literal_by_cp (lit_cp);
if (lit->get_type () == LIT_MAGIC_STR_T)
lit_literal_t lit = lit_get_literal_by_cp (lit_cp);
rcs_record_type_t type = rcs_record_get_type (lit);

if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
{
ecma_init_ecma_string_from_magic_string_id (string_p,
lit_magic_record_get_magic_str_id (lit),
lit_magic_literal_get_magic_str_id (lit),
is_stack_var);

return;
}
else if (lit->get_type () == LIT_MAGIC_STR_EX_T)

if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
{
ecma_init_ecma_string_from_magic_string_ex_id (string_p,
lit_magic_record_ex_get_magic_str_id (lit),
lit_magic_literal_ex_get_magic_str_id (lit),
is_stack_var);
return;
}

JERRY_ASSERT (lit->get_type () == LIT_STR_T);
JERRY_ASSERT (RCS_RECORD_TYPE_IS_CHARSET (type));

string_p->refs = 1;
string_p->is_stack_var = (is_stack_var != 0);
Expand Down Expand Up @@ -972,8 +976,8 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
}
case ECMA_STRING_CONTAINER_LIT_TABLE:
{
literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
lit_literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
lit_literal_to_utf8_string (lit, buffer_p, (size_t) required_buffer_size);
break;
}
Expand Down Expand Up @@ -1308,9 +1312,9 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */

if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
{
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
return lit_charset_record_get_length (lit);
lit_literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
return lit_charset_literal_get_length (lit);
}
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
{
Expand Down Expand Up @@ -1385,10 +1389,10 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */

if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
{
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
lit_literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));

return lit_charset_record_get_size (lit);
return lit_charset_literal_get_size (lit);
}
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
{
Expand Down
1 change: 1 addition & 0 deletions jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "lit-strings.h"
#include "vm.h"
#include "jrt-libc-includes.h"
#include "jrt-bit-fields.h"

#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
Expand Down
12 changes: 6 additions & 6 deletions jerry-core/jerry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-try-catch-macro.h"
#include "lit-literal.h"
#include "lit-magic-strings.h"
#include "parser.h"

Expand Down Expand Up @@ -1679,7 +1678,8 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
if (!jrt_write_to_buffer_by_offset (buffer_p,
buffer_size,
&buffer_write_offset,
version))
&version,
sizeof (version)))
{
return 0;
}
Expand Down Expand Up @@ -1732,7 +1732,7 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
return 0;
}

is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, header);
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, &header, sizeof (header));
JERRY_ASSERT (is_ok && header_offset < buffer_write_offset);

return buffer_write_offset;
Expand Down Expand Up @@ -1777,7 +1777,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
snapshot_size,
&snapshot_read,
&version))
&version,
sizeof (version)))
{
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
}
Expand Down Expand Up @@ -1806,8 +1807,7 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
if (!lit_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
header_p->lit_table_size,
&lit_map_p,
&literals_num,
is_copy))
&literals_num))
{
JERRY_ASSERT (lit_map_p == NULL);
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
Expand Down
32 changes: 16 additions & 16 deletions jerry-core/jrt/jrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,57 +227,57 @@ inline void *operator new (size_t, void *where)
} /* operator new */

/**
* Read data of specified type (T) from specified buffer
* Read data from a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the read operation completes successfully.
*
* @return true, if read was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
* @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
template<typename T>
bool __attr_always_inline___
inline bool
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
T *out_data_p) /**< out: data */
void *out_data_p, /**< out: data */
size_t out_data_size) /**< size of the readable data */
{
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
{
return false;
}

memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, sizeof (T));
*in_out_buffer_offset_p += sizeof (T);
memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size);
*in_out_buffer_offset_p += out_data_size;

return true;
} /* jrt_read_from_buffer_by_offset */

/**
* Write data of specified type (T) to specified buffer
* Write data to a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the write operation completes successfully.
*
* @return true, if write was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
* @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
template<typename T>
bool __attr_always_inline___
inline bool
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
T data) /**< data */
void *data_p, /**< data */
size_t data_size) /**< size of the writable data */
{
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
if (*in_out_buffer_offset_p + data_size > buffer_size)
{
return false;
}

memcpy (buffer_p + *in_out_buffer_offset_p, &data, sizeof (T));
*in_out_buffer_offset_p += sizeof (T);
memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size);
*in_out_buffer_offset_p += data_size;

return true;
} /* jrt_write_to_buffer_by_offset */
Expand Down
16 changes: 16 additions & 0 deletions jerry-core/lit/lit-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define LIT_GLOBALS_H

#include "jrt.h"
#include "rcs-cpointer.h"

/**
* ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value
Expand Down Expand Up @@ -123,6 +124,21 @@ typedef uint32_t lit_code_point_t;
*/
typedef uint8_t lit_string_hash_t;

/**
* Literal type
*/
typedef rcs_record_t *lit_literal_t;

/**
* Compressed pointer type
*/
typedef rcs_cpointer_t lit_cpointer_t;

/**
* Invalid literal
*/
#define NOT_A_LITERAL (rcs_cpointer_null_cp ())

/**
* ECMA string hash value length, in bits
*/
Expand Down
Loading