Merge branch 'master' of git-server:jerry
This commit is contained in:
@@ -227,7 +227,7 @@ lexer_get_string_by_id (uint8_t id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
lexer_get_nums (int *nums)
|
lexer_get_nums (int32_t *nums)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -368,7 +368,7 @@ parse_name (void)
|
|||||||
return known_token;
|
return known_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int32_t
|
||||||
hex_to_int (char hex)
|
hex_to_int (char hex)
|
||||||
{
|
{
|
||||||
switch (hex)
|
switch (hex)
|
||||||
@@ -409,7 +409,7 @@ parse_number (void)
|
|||||||
bool is_fp = false;
|
bool is_fp = false;
|
||||||
bool is_exp = false;
|
bool is_exp = false;
|
||||||
size_t tok_length = 0, i;
|
size_t tok_length = 0, i;
|
||||||
int res = 0;
|
int32_t res = 0;
|
||||||
token known_token;
|
token known_token;
|
||||||
|
|
||||||
JERRY_ASSERT (__isdigit (c) || c == '.');
|
JERRY_ASSERT (__isdigit (c) || c == '.');
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ void lexer_dump_buffer_state (void);
|
|||||||
uint8_t lexer_get_strings (const char **);
|
uint8_t lexer_get_strings (const char **);
|
||||||
uint8_t lexer_get_reserved_ids_count (void);
|
uint8_t lexer_get_reserved_ids_count (void);
|
||||||
const char *lexer_get_string_by_id (uint8_t);
|
const char *lexer_get_string_by_id (uint8_t);
|
||||||
uint8_t lexer_get_nums (int *);
|
uint8_t lexer_get_nums (int32_t *);
|
||||||
void lexer_adjust_num_ids (void);
|
void lexer_adjust_num_ids (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void serializer_init (void);
|
|||||||
|
|
||||||
uint8_t serializer_dump_strings (const char **, uint8_t);
|
uint8_t serializer_dump_strings (const char **, uint8_t);
|
||||||
|
|
||||||
void serializer_dump_nums (const int *, uint8_t, uint8_t, uint8_t);
|
void serializer_dump_nums (const int32_t *, uint8_t, uint8_t, uint8_t);
|
||||||
|
|
||||||
void serializer_dump_opcode (const void *);
|
void serializer_dump_opcode (const void *);
|
||||||
|
|
||||||
|
|||||||
@@ -79,10 +79,9 @@ serializer_dump_strings (const char *strings[], uint8_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_nums (const int nums[], uint8_t size, uint8_t offset, uint8_t strings_num)
|
serializer_dump_nums (const int32_t nums[], uint8_t size, uint8_t offset, uint8_t strings_num)
|
||||||
{
|
{
|
||||||
uint8_t i, *data, num_offset;
|
uint8_t i, *data, num_offset;
|
||||||
JERRY_STATIC_ASSERT (sizeof (int) == 4);
|
|
||||||
|
|
||||||
num_offset = (uint8_t) (offset + size + 1);
|
num_offset = (uint8_t) (offset + size + 1);
|
||||||
__printf ("NUMS %d:\n", size);
|
__printf ("NUMS %d:\n", size);
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/* 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 BYTECODE_STM_H
|
||||||
|
#define BYTECODE_STM_H
|
||||||
|
|
||||||
|
#include "opcodes.h"
|
||||||
|
|
||||||
|
#define MAX_OPCODES 255
|
||||||
|
|
||||||
|
/* bytecode_data contains identifiers, string and num literals.
|
||||||
|
Memory map if the following.
|
||||||
|
|
||||||
|
bytecode_data {
|
||||||
|
U8 strs_count;
|
||||||
|
U8 string_offsets[str_count];
|
||||||
|
U8* strings[str_count];
|
||||||
|
|
||||||
|
U8 nums_count;
|
||||||
|
U32 nums[nums_count];
|
||||||
|
} */
|
||||||
|
uint8_t *bytecode_data;
|
||||||
|
OPCODE bytecode_opcodes[MAX_OPCODES];
|
||||||
|
|
||||||
|
#endif // BYTECODE_STM_H
|
||||||
@@ -14,29 +14,81 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deserializer.h"
|
#include "deserializer.h"
|
||||||
|
#include "bytecode-stm.h"
|
||||||
|
|
||||||
TODO (Implement)
|
TODO (Read from flash)
|
||||||
|
|
||||||
|
int *num_data = NULL;
|
||||||
|
uint8_t num_size = 0;
|
||||||
|
|
||||||
const ecma_char_t *
|
const ecma_char_t *
|
||||||
deserialize_string_by_id (uint8_t id)
|
deserialize_string_by_id (uint8_t id)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (id);
|
uint8_t size, *data, offset;
|
||||||
|
|
||||||
|
if (bytecode_data == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
size = *bytecode_data;
|
||||||
|
|
||||||
|
if (id >= size)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
data = bytecode_data;
|
||||||
|
|
||||||
|
data += id + 1;
|
||||||
|
|
||||||
|
offset = *data;
|
||||||
|
|
||||||
|
return bytecode_data + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
deserialize_num_by_id (uint8_t id)
|
deserialize_num_by_id (uint8_t id)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (id);
|
uint8_t str_size, str_offset, *data;
|
||||||
|
|
||||||
|
str_size = *bytecode_data;
|
||||||
|
if (id < str_size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
id = (uint8_t) (id - str_size);
|
||||||
|
|
||||||
|
if (num_data == NULL)
|
||||||
|
{
|
||||||
|
data = bytecode_data + str_size;
|
||||||
|
str_offset = *data;
|
||||||
|
data = bytecode_data + str_offset;
|
||||||
|
|
||||||
|
while (*data)
|
||||||
|
data++;
|
||||||
|
|
||||||
|
num_size = *(++data);
|
||||||
|
num_data = (int *) ++data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id >= num_size)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return num_data[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *
|
const void *
|
||||||
deserialize_bytecode (void)
|
deserialize_bytecode (void)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED ();
|
return bytecode_opcodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
deserialize_min_temp (void)
|
deserialize_min_temp (void)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED ();
|
uint8_t str_size = *bytecode_data;
|
||||||
|
|
||||||
|
if (num_size == 0)
|
||||||
|
{
|
||||||
|
deserialize_num_by_id (str_size); // Init num_data and num_size
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t) (str_size + num_size);
|
||||||
}
|
}
|
||||||
@@ -15,35 +15,94 @@
|
|||||||
|
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "serializer.h"
|
||||||
|
#include "jerry-libc.h"
|
||||||
|
#include "bytecode-stm.h"
|
||||||
|
#include "deserializer.h"
|
||||||
|
|
||||||
|
TODO (Dump to flash)
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_init (void)
|
serializer_init (void)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
serializer_dump_strings (const char *strings[], uint8_t size)
|
serializer_dump_strings (const char *strings[], uint8_t size)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( strings, size);
|
uint8_t i;
|
||||||
|
uint8_t offset = (uint8_t) (size + 1), res;
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
offset = (uint8_t) (offset + __strlen (strings[i]) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytecode_data = mem_heap_alloc_block (offset, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||||
|
res = offset;
|
||||||
|
|
||||||
|
bytecode_data[0] = size;
|
||||||
|
offset = (uint8_t) (size + 1);
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
bytecode_data[i + 1] = offset;
|
||||||
|
offset = (uint8_t) (offset + __strlen (strings[i]) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
__strncpy ((void *) (bytecode_data + bytecode_data[i + 1]), strings[i], __strlen (strings[i]) + 1);
|
||||||
|
|
||||||
|
#ifndef JERRY_NDEBUG
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (!__strcmp (strings[i], (const char *) deserialize_string_by_id (i)));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_nums (const int nums[], uint8_t size, uint8_t offset, uint8_t strings_num)
|
serializer_dump_nums (const int32_t nums[], uint8_t size, uint8_t offset, uint8_t strings_num __unused)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( nums, size, offset, strings_num);
|
uint8_t i, *data;
|
||||||
|
|
||||||
|
data = mem_heap_alloc_block ((size_t) (offset + size * 4 + 1), MEM_HEAP_ALLOC_LONG_TERM);
|
||||||
|
__memcpy (data, bytecode_data, offset);
|
||||||
|
mem_heap_free_block (bytecode_data);
|
||||||
|
|
||||||
|
bytecode_data = data;
|
||||||
|
data += offset;
|
||||||
|
data[0] = size;
|
||||||
|
data++;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
__memcpy (data, nums + i, 4);
|
||||||
|
data += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef JERRY_NDEBUG
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (nums[i] == deserialize_num_by_id ((uint8_t) (i + strings_num)));
|
||||||
|
}
|
||||||
|
|
||||||
|
JERRY_ASSERT (deserialize_min_temp () == (uint8_t) (size + strings_num));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int opcode_counter = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_opcode (const void *opcode)
|
serializer_dump_opcode (const void *opcode)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( opcode);
|
bytecode_opcodes[opcode_counter++] = *((OPCODE*)opcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_rewrite_opcode (const uint8_t offset, const void *opcode)
|
serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
|
||||||
{
|
{
|
||||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( offset, opcode);
|
bytecode_opcodes[loc] = *((OPCODE*)opcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -51,5 +110,3 @@ serializer_print_opcodes (void)
|
|||||||
{
|
{
|
||||||
JERRY_UNREACHABLE ();
|
JERRY_UNREACHABLE ();
|
||||||
}
|
}
|
||||||
|
|
||||||
TODO (Dump memory)
|
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ jerry_run( const char *script_source,
|
|||||||
size_t script_source_size __unused)
|
size_t script_source_size __unused)
|
||||||
{
|
{
|
||||||
const char *strings[MAX_STRINGS];
|
const char *strings[MAX_STRINGS];
|
||||||
int nums[MAX_NUMS];
|
int32_t nums[MAX_NUMS];
|
||||||
uint8_t strings_num, nums_count;
|
uint8_t strings_num, nums_count;
|
||||||
uint8_t offset;
|
uint8_t offset;
|
||||||
const OPCODE *opcodes;
|
const OPCODE *opcodes;
|
||||||
|
|||||||
Reference in New Issue
Block a user