Skip to content

Commit 00379d6

Browse files
author
Roland Takacs
committed
Refactor literal-storage to not use C++ features
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent 50d124b commit 00379d6

36 files changed

+2599
-3130
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "lit-globals.h"
2929
#include "lit-magic-strings.h"
3030
#include "mem-allocator.h"
31-
#include "rcs-recordset.h"
3231

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

790-
FIXME (Move to library that should define the type (literal.h /* ? */))
791-
792-
/**
793-
* Literal and compressed pointer to literal
794-
*/
795-
typedef rcs_record_t *literal_t;
796-
typedef rcs_cpointer_t lit_cpointer_t;
797-
798-
#define NOT_A_LITERAL (lit_cpointer_t::null_cp ())
799-
800789
/**
801790
* ECMA string-value descriptor
802791
*/

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "lit-char-helpers.h"
3232
#include "lit-magic-strings.h"
3333
#include "vm.h"
34+
#include "rcs-records.h"
3435

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

331-
literal_t lit = lit_get_literal_by_cp (lit_cp);
332-
if (lit->get_type () == LIT_MAGIC_STR_T)
332+
lit_literal_t lit = lit_get_literal_by_cp (lit_cp);
333+
rcs_record_type_t type = rcs_record_get_type (lit);
334+
335+
if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
333336
{
334337
ecma_init_ecma_string_from_magic_string_id (string_p,
335-
lit_magic_record_get_magic_str_id (lit),
338+
lit_magic_literal_get_magic_str_id (lit),
336339
is_stack_var);
337340

338341
return;
339342
}
340-
else if (lit->get_type () == LIT_MAGIC_STR_EX_T)
343+
344+
if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
341345
{
342346
ecma_init_ecma_string_from_magic_string_ex_id (string_p,
343-
lit_magic_record_ex_get_magic_str_id (lit),
347+
lit_magic_literal_ex_get_magic_str_id (lit),
344348
is_stack_var);
345349
return;
346350
}
347351

348-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
352+
JERRY_ASSERT (RCS_RECORD_TYPE_IS_CHARSET (type));
349353

350354
string_p->refs = 1;
351355
string_p->is_stack_var = (is_stack_var != 0);
@@ -972,8 +976,8 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
972976
}
973977
case ECMA_STRING_CONTAINER_LIT_TABLE:
974978
{
975-
literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
976-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
979+
lit_literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
980+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
977981
lit_literal_to_utf8_string (lit, buffer_p, (size_t) required_buffer_size);
978982
break;
979983
}
@@ -1308,9 +1312,9 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
13081312

13091313
if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
13101314
{
1311-
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1312-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1313-
return lit_charset_record_get_length (lit);
1315+
lit_literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1316+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
1317+
return lit_charset_literal_get_length (lit);
13141318
}
13151319
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
13161320
{
@@ -1385,10 +1389,10 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
13851389

13861390
if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
13871391
{
1388-
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1389-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1392+
lit_literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1393+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
13901394

1391-
return lit_charset_record_get_size (lit);
1395+
return lit_charset_literal_get_size (lit);
13921396
}
13931397
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
13941398
{

jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "lit-strings.h"
3030
#include "vm.h"
3131
#include "jrt-libc-includes.h"
32+
#include "jrt-bit-fields.h"
3233

3334
#define ECMA_BUILTINS_INTERNAL
3435
#include "ecma-builtins-internal.h"

jerry-core/jerry.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "ecma-objects.h"
2929
#include "ecma-objects-general.h"
3030
#include "ecma-try-catch-macro.h"
31-
#include "lit-literal.h"
3231
#include "lit-magic-strings.h"
3332
#include "parser.h"
3433

@@ -1679,7 +1678,8 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16791678
if (!jrt_write_to_buffer_by_offset (buffer_p,
16801679
buffer_size,
16811680
&buffer_write_offset,
1682-
version))
1681+
&version,
1682+
sizeof (version)))
16831683
{
16841684
return 0;
16851685
}
@@ -1732,7 +1732,7 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
17321732
return 0;
17331733
}
17341734

1735-
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, header);
1735+
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, &header, sizeof (header));
17361736
JERRY_ASSERT (is_ok && header_offset < buffer_write_offset);
17371737

17381738
return buffer_write_offset;
@@ -1777,7 +1777,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17771777
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
17781778
snapshot_size,
17791779
&snapshot_read,
1780-
&version))
1780+
&version,
1781+
sizeof (version)))
17811782
{
17821783
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
17831784
}
@@ -1806,8 +1807,7 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
18061807
if (!lit_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
18071808
header_p->lit_table_size,
18081809
&lit_map_p,
1809-
&literals_num,
1810-
is_copy))
1810+
&literals_num))
18111811
{
18121812
JERRY_ASSERT (lit_map_p == NULL);
18131813
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;

jerry-core/jrt/jrt.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,57 +227,57 @@ inline void *operator new (size_t, void *where)
227227
} /* operator new */
228228

229229
/**
230-
* Read data of specified type (T) from specified buffer
230+
* Read data from a specified buffer.
231231
*
232232
* Note:
233233
* Offset is in-out and is incremented if the read operation completes successfully.
234234
*
235-
* @return true, if read was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
235+
* @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size,
236236
* false - otherwise.
237237
*/
238-
template<typename T>
239-
bool __attr_always_inline___
238+
inline bool
240239
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
241240
size_t buffer_size, /**< size of buffer */
242241
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
243242
* out: offset, incremented on sizeof (T) */
244-
T *out_data_p) /**< out: data */
243+
void *out_data_p, /**< out: data */
244+
size_t out_data_size) /**< size of the readable data */
245245
{
246-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
246+
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
247247
{
248248
return false;
249249
}
250250

251-
memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, sizeof (T));
252-
*in_out_buffer_offset_p += sizeof (T);
251+
memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size);
252+
*in_out_buffer_offset_p += out_data_size;
253253

254254
return true;
255255
} /* jrt_read_from_buffer_by_offset */
256256

257257
/**
258-
* Write data of specified type (T) to specified buffer
258+
* Write data to a specified buffer.
259259
*
260260
* Note:
261261
* Offset is in-out and is incremented if the write operation completes successfully.
262262
*
263-
* @return true, if write was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
263+
* @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size,
264264
* false - otherwise.
265265
*/
266-
template<typename T>
267-
bool __attr_always_inline___
266+
inline bool
268267
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
269268
size_t buffer_size, /**< size of buffer */
270269
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
271270
* out: offset, incremented on sizeof (T) */
272-
T data) /**< data */
271+
void *data_p, /**< data */
272+
size_t data_size) /**< size of the writable data */
273273
{
274-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
274+
if (*in_out_buffer_offset_p + data_size > buffer_size)
275275
{
276276
return false;
277277
}
278278

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

282282
return true;
283283
} /* jrt_write_to_buffer_by_offset */

jerry-core/lit/lit-globals.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LIT_GLOBALS_H
1818

1919
#include "jrt.h"
20+
#include "rcs-cpointer.h"
2021

2122
/**
2223
* ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value
@@ -123,6 +124,21 @@ typedef uint32_t lit_code_point_t;
123124
*/
124125
typedef uint8_t lit_string_hash_t;
125126

127+
/**
128+
* Literal type
129+
*/
130+
typedef rcs_record_t *lit_literal_t;
131+
132+
/**
133+
* Compressed pointer type
134+
*/
135+
typedef rcs_cpointer_t lit_cpointer_t;
136+
137+
/**
138+
* Invalid literal
139+
*/
140+
#define NOT_A_LITERAL (rcs_cpointer_null_cp ())
141+
126142
/**
127143
* ECMA string hash value length, in bits
128144
*/

0 commit comments

Comments
 (0)