This commit is contained in:
Ilmir Usmanov
2014-07-24 21:40:30 +04:00
20 changed files with 307 additions and 97 deletions
+1
View File
@@ -22,6 +22,7 @@ nbproject
*~ *~
js.files js.files
core core
**.orig
# ctags and ID database # ctags and ID database
tags tags
+1 -1
View File
@@ -110,7 +110,7 @@ CFLAGS_CORTEXM4 ?= -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb \
# Common # Common
# #
CFLAGS_COMMON ?= $(INCLUDES) -std=c99 -fsanitize=address -fdiagnostics-color=always CFLAGS_COMMON ?= $(INCLUDES) -std=c99 #-fsanitize=address -fdiagnostics-color=always
LDFLAGS ?= LDFLAGS ?=
+2 -13
View File
@@ -15,17 +15,6 @@
#include "globals.h" #include "globals.h"
static const char* generated_source __unused = "" static const char* generated_source = ""
"while (true) {\n" "LEDToggle (14);\n"
"LEDToggle (LED3);\n"
"LEDToggle (LED6);\n"
"LEDToggle (LED7);\n"
"LEDToggle (LED4);\n"
"LEDToggle (LED10);\n"
"LEDToggle (LED8);\n"
"LEDToggle (LED9);\n"
"LEDToggle (LED5);\n"
"\n"
"wait(500);\n"
"}\n"
; ;
+61 -17
View File
@@ -13,8 +13,12 @@
* limitations under the License. * limitations under the License.
*/ */
#include "deserializer.h"
#include "ecma-globals.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "globals.h"
#include "interpreter.h" #include "interpreter.h"
#include "jerry-libc.h"
#define INIT_OP_FUNC(name) [ __op__idx_##name ] = opfunc_##name, #define INIT_OP_FUNC(name) [ __op__idx_##name ] = opfunc_##name,
static const opfunc __opfuncs[LAST_OP] = { static const opfunc __opfuncs[LAST_OP] = {
@@ -42,15 +46,17 @@ run_int (void)
{ {
JERRY_ASSERT( __program != NULL ); JERRY_ASSERT( __program != NULL );
struct __int_data int_data; const int start_pos = 0;
int_data.pos = 0; ecma_object_t *this_binding_p = NULL;
int_data.this_binding_p = NULL; ecma_object_t *lex_env_p = ecma_create_lexical_environment (NULL,
int_data.lex_env_p = ecma_create_lexical_environment( NULL, ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
FIXME( Strict mode ); FIXME( Strict mode );
int_data.is_strict = false; const bool is_strict = false;
ecma_completion_value_t completion = run_int_from_pos( &int_data); ecma_completion_value_t completion = run_int_from_pos (start_pos,
this_binding_p,
lex_env_p,
is_strict);
switch ( (ecma_completion_type_t)completion.type ) switch ( (ecma_completion_type_t)completion.type )
{ {
@@ -82,16 +88,43 @@ run_int (void)
} }
ecma_completion_value_t ecma_completion_value_t
run_int_from_pos (struct __int_data *int_data) run_int_from_pos (int start_pos,
ecma_object_t *this_binding_p,
ecma_object_t *lex_env_p,
bool is_strict)
{ {
ecma_completion_value_t completion; ecma_completion_value_t completion;
const OPCODE *curr = &__program[start_pos];
JERRY_ASSERT( curr->op_idx == __op__idx_reg_var_decl );
const T_IDX min_reg_num = curr->data.reg_var_decl.min;
const T_IDX max_reg_num = curr->data.reg_var_decl.max;
JERRY_ASSERT( max_reg_num >= min_reg_num );
const uint32_t regs_num = (uint32_t) (max_reg_num - min_reg_num + 1);
ecma_value_t regs[ regs_num ];
/* memseting with zero initializes each 'register' to empty value */
__memset (regs, 0, sizeof(regs));
JERRY_ASSERT( ecma_is_value_empty( regs[0]) );
struct __int_data int_data;
int_data.pos = start_pos + 1;
int_data.this_binding_p = this_binding_p;
int_data.lex_env_p = lex_env_p;
int_data.is_strict = is_strict;
int_data.min_reg_num = min_reg_num;
int_data.max_reg_num = max_reg_num;
int_data.regs_p = regs;
while ( true ) while ( true )
{ {
do do
{ {
const OPCODE *curr = &__program[int_data->pos]; const OPCODE *curr = &__program[int_data.pos];
completion = __opfuncs[curr->op_idx](*curr, int_data); completion = __opfuncs[curr->op_idx](*curr, &int_data);
JERRY_ASSERT( !ecma_is_completion_value_normal( completion) JERRY_ASSERT( !ecma_is_completion_value_normal( completion)
|| ecma_is_completion_value_normal_simple_value(completion, || ecma_is_completion_value_normal_simple_value(completion,
@@ -111,6 +144,13 @@ run_int_from_pos (struct __int_data *int_data)
continue; continue;
} }
for ( uint32_t reg_index = 0;
reg_index < regs_num;
reg_index++ )
{
ecma_free_value( regs[ reg_index ] );
}
return completion; return completion;
} }
} }
@@ -128,18 +168,19 @@ try_get_string_by_idx(T_IDX idx, /**< literal id */
{ {
TODO( Actual string literal retrievement ); TODO( Actual string literal retrievement );
ssize_t req_length = 2; // TODO const ecma_char_t *str_p = deserialize_string_by_id( idx);
JERRY_ASSERT( str_p != NULL );
JERRY_ASSERT( idx < 'z' - 'a' + 1 );
FIXME( strlen for ecma_char_t );
ssize_t req_length = (ssize_t)__strlen( (const char*)str_p) + 1;
if ( buffer_size < req_length ) if ( buffer_size < req_length )
{ {
return -req_length; return -req_length;
} }
// TODO FIXME( strncpy for ecma_char_t );
buffer_p[0] = (ecma_char_t) ('a' + idx); __strncpy( (char*)buffer_p, (const char*)str_p, (size_t)req_length);
buffer_p[1] = 0;
return req_length; return req_length;
} /* try_get_string_by_idx */ } /* try_get_string_by_idx */
@@ -154,5 +195,8 @@ get_number_by_idx(T_IDX idx) /**< literal id */
{ {
TODO( Actual number literal retrievement ); TODO( Actual number literal retrievement );
return (ecma_number_t)idx; FIXME( /* conversion of value returned from deserialize_num_by_id to ecma_number_t */ );
ecma_number_t num = (ecma_number_t) deserialize_num_by_id( idx);
return num;
} /* get_number_by_idx */ } /* get_number_by_idx */
+7 -1
View File
@@ -26,11 +26,17 @@ struct __int_data
ecma_object_t *this_binding_p; /**< this binding for current context */ ecma_object_t *this_binding_p; /**< this binding for current context */
ecma_object_t *lex_env_p; /**< current lexical environment */ ecma_object_t *lex_env_p; /**< current lexical environment */
bool is_strict; /**< is current code execution mode strict? */ bool is_strict; /**< is current code execution mode strict? */
T_IDX min_reg_num; /**< minimum idx used for register identification */
T_IDX max_reg_num; /**< maximum idx used for register identification */
ecma_value_t *regs_p; /**< register variables */
}; };
void init_int (const OPCODE* program_p); void init_int (const OPCODE* program_p);
bool run_int (void); bool run_int (void);
ecma_completion_value_t run_int_from_pos (struct __int_data *); ecma_completion_value_t run_int_from_pos (int start_pos,
ecma_object_t *this_binding_p,
ecma_object_t *lex_env_p,
bool is_strict);
ssize_t try_get_string_by_idx( T_IDX idx, ecma_char_t *buffer_p, ssize_t buffer_size); ssize_t try_get_string_by_idx( T_IDX idx, ecma_char_t *buffer_p, ssize_t buffer_size);
ecma_number_t get_number_by_idx(T_IDX idx); ecma_number_t get_number_by_idx(T_IDX idx);
+107 -36
View File
@@ -25,6 +25,10 @@
#include "mem-heap.h" #include "mem-heap.h"
#include "opcodes.h" #include "opcodes.h"
#include "actuators.h"
#include "common-io.h"
#include "sensors.h"
/** /**
* Note: * Note:
* The note describes exception handling in opcode handlers that perform operations, * The note describes exception handling in opcode handlers that perform operations,
@@ -183,27 +187,42 @@ get_variable_value(struct __int_data *int_data, /**< interpreter context */
bool do_eval_or_arguments_check) /** run 'strict eval or arguments reference' check bool do_eval_or_arguments_check) /** run 'strict eval or arguments reference' check
See also: do_strict_eval_arguments_check */ See also: do_strict_eval_arguments_check */
{ {
string_literal_copy var_name;
ecma_reference_t ref;
ecma_completion_value_t ret_value; ecma_completion_value_t ret_value;
init_string_literal_copy( var_idx, &var_name); if ( var_idx >= int_data->min_reg_num
ref = ecma_op_get_identifier_reference( int_data->lex_env_p, && var_idx <= int_data->max_reg_num )
var_name.str_p, {
int_data->is_strict); ecma_value_t reg_value = int_data->regs_p[ var_idx - int_data->min_reg_num ];
if ( unlikely( do_eval_or_arguments_check JERRY_ASSERT( !ecma_is_value_empty( reg_value) );
&& do_strict_eval_arguments_check( ref) ) )
ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_copy_value( reg_value),
ECMA_TARGET_ID_RESERVED);
}
else
{
string_literal_copy var_name;
ecma_reference_t ref;
init_string_literal_copy( var_idx, &var_name);
ref = ecma_op_get_identifier_reference( int_data->lex_env_p,
var_name.str_p,
int_data->is_strict);
if ( unlikely( do_eval_or_arguments_check
&& do_strict_eval_arguments_check( ref) ) )
{ {
ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX)); ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX));
} }
else else
{ {
ret_value = ecma_op_get_value( ref); ret_value = ecma_op_get_value( ref);
} }
ecma_free_reference( ref); ecma_free_reference( ref);
free_string_literal_copy( &var_name); free_string_literal_copy( &var_name);
}
return ret_value; return ret_value;
} /* get_variable_value */ } /* get_variable_value */
@@ -219,26 +238,44 @@ set_variable_value(struct __int_data *int_data, /**< interpreter context */
T_IDX var_idx, /**< variable identifier */ T_IDX var_idx, /**< variable identifier */
ecma_value_t value) /**< value to set */ ecma_value_t value) /**< value to set */
{ {
string_literal_copy var_name;
ecma_reference_t ref;
ecma_completion_value_t ret_value; ecma_completion_value_t ret_value;
init_string_literal_copy( var_idx, &var_name); if ( var_idx >= int_data->min_reg_num
ref = ecma_op_get_identifier_reference( int_data->lex_env_p, && var_idx <= int_data->max_reg_num )
var_name.str_p, {
int_data->is_strict); ecma_value_t reg_value = int_data->regs_p[ var_idx - int_data->min_reg_num ];
if ( unlikely( do_strict_eval_arguments_check( ref) ) ) if ( !ecma_is_value_empty( reg_value) )
{
ecma_free_value( reg_value);
}
int_data->regs_p[ var_idx - int_data->min_reg_num ] = ecma_copy_value( value);
ret_value = ecma_make_empty_completion_value();
}
else
{
string_literal_copy var_name;
ecma_reference_t ref;
init_string_literal_copy( var_idx, &var_name);
ref = ecma_op_get_identifier_reference( int_data->lex_env_p,
var_name.str_p,
int_data->is_strict);
if ( unlikely( do_strict_eval_arguments_check( ref) ) )
{ {
ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX)); ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX));
} }
else else
{ {
ret_value = ecma_op_put_value( ref, value); ret_value = ecma_op_put_value( ref, value);
} }
ecma_free_reference( ref); ecma_free_reference( ref);
free_string_literal_copy( &var_name); free_string_literal_copy( &var_name);
}
return ret_value; return ret_value;
} /* set_variable_value */ } /* set_variable_value */
@@ -376,20 +413,23 @@ do_number_arithmetic(struct __int_data *int_data, /**< interpreter context */
op(post_decr) \ op(post_decr) \
op(pre_incr) \ op(pre_incr) \
op(pre_decr) \ op(pre_decr) \
op(reg_var_decl) static char __unused unimplemented_list_end
#define DEFINE_UNIMPLEMENTED_OP(op) \ #define DEFINE_UNIMPLEMENTED_OP(op) \
ecma_completion_value_t opfunc_ ## op(OPCODE opdata, struct __int_data *int_data) { \ ecma_completion_value_t opfunc_ ## op(OPCODE opdata, struct __int_data *int_data) { \
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( opdata, int_data); \ JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( opdata, int_data); \
} }
OP_UNIMPLEMENTED_LIST(DEFINE_UNIMPLEMENTED_OP) OP_UNIMPLEMENTED_LIST(DEFINE_UNIMPLEMENTED_OP);
#undef DEFINE_UNIMPLEMENTED_OP #undef DEFINE_UNIMPLEMENTED_OP
ecma_completion_value_t ecma_completion_value_t
opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data) opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
{ {
ecma_completion_value_t ret_value;
ret_value = ecma_make_empty_completion_value ();
#ifdef __HOST #ifdef __HOST
__printf ("%d::op_call_1:idx:%d:%d\n", __printf ("%d::op_call_1:idx:%d:%d\t",
int_data->pos, int_data->pos,
opdata.data.call_1.name_lit_idx, opdata.data.call_1.name_lit_idx,
opdata.data.call_1.arg1_lit_idx); opdata.data.call_1.arg1_lit_idx);
@@ -397,8 +437,27 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
int_data->pos++; int_data->pos++;
// FIXME string_literal_copy str_value;
return ecma_make_empty_completion_value(); init_string_literal_copy( opdata.data.call_1.name_lit_idx, &str_value);
#ifdef __HOST
__printf("%s\n", str_value.str_p);
#endif
if (!__strcmp ((const char*)str_value.str_p, "LEDToggle"))
{
TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value);
JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER );
ecma_number_t * num_p = (ecma_number_t*)ecma_get_pointer(cond_value.value.value);
uint32_t int_num = (uint32_t)*num_p;
led_blink_once (int_num);
ret_value = ecma_make_empty_completion_value ();
FINALIZE (cond_value);
}
free_string_literal_copy (&str_value);
return ret_value;
} }
/** /**
@@ -808,6 +867,18 @@ opfunc_remainder(OPCODE opdata, /**< operation data */
return ret_value; return ret_value;
} /* opfunc_remainder */ } /* opfunc_remainder */
/**
* 'Register variable declaration' opcode handler.
*
* The opcode is meta-opcode that is not supposed to be executed.
*/
ecma_completion_value_t
opfunc_reg_var_decl(OPCODE opdata __unused, /**< operation data */
struct __int_data *int_data __unused) /**< interpreter context */
{
JERRY_UNREACHABLE();
} /* opfunc_reg_var_decl */
/** /**
* 'Variable declaration' opcode handler. * 'Variable declaration' opcode handler.
* *
@@ -819,25 +890,25 @@ opfunc_remainder(OPCODE opdata, /**< operation data */
*/ */
ecma_completion_value_t ecma_completion_value_t
opfunc_var_decl(OPCODE opdata, /**< operation data */ opfunc_var_decl(OPCODE opdata, /**< operation data */
struct __int_data *int_data __unused) /**< interpreter context */ struct __int_data *int_data) /**< interpreter context */
{ {
string_literal_copy variable_name; string_literal_copy variable_name;
init_string_literal_copy( opdata.data.var_decl.variable_name, &variable_name); init_string_literal_copy( opdata.data.var_decl.variable_name, &variable_name);
if ( ecma_is_completion_value_normal_false( ecma_op_has_binding( int_data->lex_env_p, if ( ecma_is_completion_value_normal_false( ecma_op_has_binding (int_data->lex_env_p,
variable_name.str_p)) ) variable_name.str_p)) )
{ {
FIXME( Pass configurableBindings that is true if and only if current code is eval code ); FIXME( Pass configurableBindings that is true if and only if current code is eval code );
ecma_op_create_mutable_binding( int_data->lex_env_p, ecma_op_create_mutable_binding (int_data->lex_env_p,
variable_name.str_p, variable_name.str_p,
false); false);
/* Skipping SetMutableBinding as we have already checked that there were not /* Skipping SetMutableBinding as we have already checked that there were not
* any binding with specified name in current lexical environment * any binding with specified name in current lexical environment
* and CreateMutableBinding sets the created binding's value to undefined */ * and CreateMutableBinding sets the created binding's value to undefined */
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value( ecma_op_get_binding_value( int_data->lex_env_p, JERRY_ASSERT( ecma_is_completion_value_normal_simple_value( ecma_op_get_binding_value (int_data->lex_env_p,
variable_name.str_p, variable_name.str_p,
true), true),
ECMA_SIMPLE_VALUE_UNDEFINED) ); ECMA_SIMPLE_VALUE_UNDEFINED) );
} }
+1 -1
View File
@@ -63,11 +63,11 @@ typedef enum {
* Simple ecma-values * Simple ecma-values
*/ */
typedef enum { typedef enum {
ECMA_SIMPLE_VALUE_EMPTY, /**< empty value (see also: ECMA-262 v5, 8.9 Completion specification type) */
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */ ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
ECMA_SIMPLE_VALUE_NULL, /**< null value */ ECMA_SIMPLE_VALUE_NULL, /**< null value */
ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */ ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */
ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */ ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */
ECMA_SIMPLE_VALUE_EMPTY, /**< empty value (see also: ECMA-262 v5, 8.9 Completion specification type) */
ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< special value for an array's elements that exists, ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< special value for an array's elements that exists,
but is stored directly in the array's property list but is stored directly in the array's property list
(used for array elements with non-default attribute values) */ (used for array elements with non-default attribute values) */
+12
View File
@@ -26,6 +26,18 @@
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "globals.h" #include "globals.h"
/**
* Check if the value is empty.
*
* @return true - if the value contains implementation-defined empty simple value,
* false - otherwise.
*/
bool
ecma_is_value_empty( ecma_value_t value) /**< ecma-value */
{
return ( value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_EMPTY );
} /* ecma_is_value_empty */
/** /**
* Check if the value is undefined. * Check if the value is undefined.
* *
+1
View File
@@ -42,6 +42,7 @@ extern void* ecma_decompress_pointer(uintptr_t compressed_pointer);
(field) = ecma_compress_pointer( non_compressed_pointer) & ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1) (field) = ecma_compress_pointer( non_compressed_pointer) & ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1)
/* ecma-helpers-value.c */ /* ecma-helpers-value.c */
extern bool ecma_is_value_empty( ecma_value_t value);
extern bool ecma_is_value_undefined( ecma_value_t value); extern bool ecma_is_value_undefined( ecma_value_t value);
extern bool ecma_is_value_null( ecma_value_t value); extern bool ecma_is_value_null( ecma_value_t value);
extern bool ecma_is_value_boolean( ecma_value_t value); extern bool ecma_is_value_boolean( ecma_value_t value);
+71 -6
View File
@@ -13,20 +13,85 @@
* limitations under the License. * limitations under the License.
*/ */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#ifdef __TARGET_MCU
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#endif
#pragma GCC diagnostic pop
#include "actuators.h" #include "actuators.h"
#include "jerry-libc.h" #include "jerry-libc.h"
void led_toggle(int led_id) #ifdef __TARGET_MCU
void
blink_once (uint32_t led)
{ {
__printf("led_toogle: %d", led_id); uint32_t pin = led;
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2);
TODO (INITIALIZE ONCE);
//
// Initialise the peripheral clock.
//
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
//
// Initilaise the GPIO port.
//
volatile GPIO_TypeDef* gpio = GPIOD;
gpio->MODER |= mode;
gpio->OSPEEDR |= speed;
gpio->OTYPER |= type;
gpio->PUPDR |= pullup;
//
// Toggle the selected LED indefinitely.
//
int index;
int dot = 600000;
int dash = dot * 3;
while (1)
{
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
for (index = 0; index < dash * 7; index++);
}
}
#endif
void led_toggle(uint32_t led_id)
{
__printf("led_toggle: %d\n", led_id);
} }
void led_on(int led_id) void led_on(uint32_t led_id)
{ {
__printf("led_on: %d", led_id); __printf("led_on: %d\n", led_id);
} }
void led_off(int led_id) void led_off(uint32_t led_id)
{ {
__printf("led_off: %d", led_id); __printf("led_off: %d\n", led_id);
}
void led_blink_once(uint32_t led_id)
{
#ifdef __HOST
__printf("led_blink_once: %d\n", led_id);
#endif
#ifdef __TARGET_MCU
blink_once(led_id);
#endif
} }
+7 -3
View File
@@ -16,15 +16,19 @@
#ifndef ACTUATORS_H #ifndef ACTUATORS_H
#define ACTUATORS_H #define ACTUATORS_H
#include "globals.h"
// STM32 F4 // STM32 F4
#define LED_GREEN 12 #define LED_GREEN 12
#define LED_ORANGE 13 #define LED_ORANGE 13
#define LED_RED 14 #define LED_RED 14
#define LED_BLUE 15 #define LED_BLUE 15
void led_toggle(int); void led_toggle(uint32_t);
void led_on(int); void led_on(uint32_t);
void led_off(int); void led_off(uint32_t);
void led_blink_once(uint32_t);
void blink_once (uint32_t);
#endif /* ACTUATORS_H */ #endif /* ACTUATORS_H */
+8 -1
View File
@@ -22,11 +22,18 @@ 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)
{ {
uint8_t size = *bytecode_data, *data = bytecode_data, offset; uint8_t size, *data, offset;
if (bytecode_data == NULL)
return NULL;
size = *bytecode_data;
if (id >= size) if (id >= size)
return NULL; return NULL;
data = bytecode_data;
data += id + 1; data += id + 1;
offset = *data; offset = *data;
+6 -3
View File
@@ -27,9 +27,9 @@
#define LED_ORANGE 13 #define LED_ORANGE 13
#define LED_RED 14 #define LED_RED 14
#define LED_BLUE 15 #define LED_BLUE 15
#include "generated.h"
#endif #endif
#include "generated.h"
#include "globals.h" #include "globals.h"
#include "interpreter.h" #include "interpreter.h"
#include "jerry-libc.h" #include "jerry-libc.h"
@@ -164,7 +164,7 @@ void fake_exit(void);
void void
fake_exit (void) fake_exit (void)
{ {
uint32_t pin = LED_RED; uint32_t pin = LED_ORANGE;
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2); uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2); uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
uint32_t type = (uint32_t)GPIO_OType_PP << pin; uint32_t type = (uint32_t)GPIO_OType_PP << pin;
@@ -185,7 +185,7 @@ fake_exit (void)
// //
// Toggle the selected LED indefinitely. // Toggle the selected LED indefinitely.
// //
int index; volatile int index;
// SOS // SOS
@@ -213,6 +213,9 @@ fake_exit (void)
int int
main(void) main(void)
{ {
//fake_exit();
const char *source_p = generated_source; const char *source_p = generated_source;
const size_t source_size = sizeof(generated_source); const size_t source_size = sizeof(generated_source);
@@ -26,6 +26,7 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_reg_var_decl( 255, 255),
getop_var_decl( 0), getop_var_decl( 0),
getop_var_decl( 1), getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
+12 -11
View File
@@ -26,17 +26,18 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
/* 0: */ getop_var_decl( 0), /* 0: */ getop_reg_var_decl( 255, 255),
/* 1: */ getop_var_decl( 1), /* 1: */ getop_var_decl( 0),
/* 2: */ getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1), /* 2: */ getop_var_decl( 1),
/* 3: */ getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0), /* 3: */ getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
/* 4: */ getop_is_true_jmp( 1, 6), /* 4: */ getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
/* 5: */ getop_jmp_down( 5), /* 5: */ getop_is_true_jmp( 1, 7),
/* 6: */ getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), /* 6: */ getop_jmp_down( 5),
/* 7: */ getop_assignment( 1, OPCODE_ARG_TYPE_NUMBER, 2), /* 7: */ getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
/* 8: */ getop_is_false_jmp( 1, 10), /* 8: */ getop_assignment( 1, OPCODE_ARG_TYPE_NUMBER, 2),
/* 9: */ getop_exitval( 0), /* 9: */ getop_is_false_jmp( 1, 11),
/* 10: */ getop_exitval( 1) /* 10: */ getop_exitval( 0),
/* 11: */ getop_exitval( 1)
}; };
mem_init(); mem_init();
+1
View File
@@ -26,6 +26,7 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_reg_var_decl( 255, 255),
getop_var_decl( 0), getop_var_decl( 0),
getop_var_decl( 1), getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
+1
View File
@@ -26,6 +26,7 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_reg_var_decl( 255, 255),
getop_var_decl( 0), getop_var_decl( 0),
getop_var_decl( 1), getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
+1
View File
@@ -26,6 +26,7 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_reg_var_decl( 255, 255),
getop_var_decl( 0), getop_var_decl( 0),
getop_var_decl( 1), getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
+1
View File
@@ -26,6 +26,7 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_reg_var_decl( 255, 255),
getop_var_decl( 0), getop_var_decl( 0),
getop_var_decl( 1), getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253), getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
@@ -26,10 +26,11 @@ main( int __unused argc,
char __unused **argv) char __unused **argv)
{ {
const OPCODE test_program[] = { const OPCODE test_program[] = {
getop_var_decl( 0), /* 0: */ getop_reg_var_decl( 255, 255),
getop_is_true_jmp( 0, 3), /* 1: */ getop_var_decl( 0),
getop_exitval( 0), /* 2: */ getop_is_true_jmp( 0, 4),
getop_exitval( 1) /* 3: */ getop_exitval( 0),
/* 4: */ getop_exitval( 1)
}; };
mem_init(); mem_init();