Implementing var_decl opcode.

This commit is contained in:
Ruben Ayrapetyan
2014-07-17 22:02:07 +04:00
parent 383853c116
commit f7abe7190d
6 changed files with 65 additions and 15 deletions
+2 -2
View File
@@ -27,8 +27,8 @@ opfunc __opfuncs[LAST_OP];
struct __int_data
{
int pos; /**< current opcode to execute */
ecma_Object_t *pThisBinding; /**< this binding for current context */
ecma_Object_t *pLexEnv; /**< current lexical environment */
ecma_Object_t *this_binding_p; /**< this binding for current context */
ecma_Object_t *lex_env_p; /**< current lexical environment */
int *root_op_addr; /**< pointer to first opcode saved */
};
+1 -1
View File
@@ -383,7 +383,7 @@ OP_CODE_DECL (loop_postcond, T_IDX_IDX,
// Variable declaration
OP_CODE_DECL (var_decl, T_IDX,
variable)
variable_name)
// TODO New constructor
+39 -3
View File
@@ -131,8 +131,7 @@ free_string_literal_copy(string_literal_copy *str_lit_descr_p) /**< string liter
op(remainder) \
op(jmp_up) \
op(jmp_down) \
op(nop) \
op(var_decl)
op(nop)
#define DEFINE_UNIMPLEMENTED_OP(op) \
ecma_CompletionValue_t opfunc_ ## op(OPCODE opdata, struct __int_data *int_data) { \
@@ -191,6 +190,43 @@ opfunc_jmp (OPCODE opdata, struct __int_data *int_data)
ECMA_TARGET_ID_RESERVED);
}
/**
* Variable declaration.
*
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 8).
*/
ecma_CompletionValue_t
opfunc_var_decl(OPCODE opdata, /**< operation data */
struct __int_data *int_data __unused) /**< interpreter context */
{
string_literal_copy variable_name;
init_string_literal_copy( opdata.data.var_decl.variable_name, &variable_name);
if ( ecma_IsCompletionValueNormalFalse( ecma_OpHasBinding( int_data->lex_env_p,
variable_name.str_p)) )
{
ecma_OpCreateMutableBinding( int_data->lex_env_p,
variable_name.str_p,
false); // FIXME: Pass configurableBindings
/* Skipping SetMutableBinding as we have already checked that there were not
* any binding with specified name in current lexical environment
* and CreateMutableBinding sets the created binding's value to undefined */
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value( ecma_OpGetBindingValue( int_data->lex_env_p,
variable_name.str_p,
true),
ECMA_SIMPLE_VALUE_UNDEFINED) );
}
free_string_literal_copy( &variable_name);
int_data->pos++;
return ecma_MakeCompletionValue( ECMA_COMPLETION_TYPE_NORMAL,
ecma_MakeSimpleValue( ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
} /* opfunc_var_decl */
/**
* Exit from script with specified status code:
* 0 - for successful completion
@@ -264,5 +300,5 @@ GETOP_IMPL_3 (loop_init_num, start, stop, step)
GETOP_IMPL_2 (loop_precond_begin_num, condition, after_loop_op)
GETOP_IMPL_3 (loop_precond_end_num, iterator, step, precond_begin)
GETOP_IMPL_2 (loop_postcond, condition, body_root)
GETOP_IMPL_1 (var_decl, variable)
GETOP_IMPL_1 (var_decl, variable_name)
+18 -6
View File
@@ -242,6 +242,22 @@ ecma_MakeThrowValue( ecma_Object_t *exception_p) /**< an object */
ECMA_TARGET_ID_RESERVED);
} /* ecma_MakeThrowValue */
/**
* Check if the completion value is specified normal simple value.
*
* @return true - if the completion type is normal and
* value contains specified simple ecma-value,
* false - otherwise.
*/
bool
ecma_is_completion_value_normal_simple_value(ecma_CompletionValue_t value, /**< completion value */
ecma_SimpleValue_t simple_value) /**< simple value to check for equality with */
{
return ( value.type == ECMA_COMPLETION_TYPE_NORMAL
&& value.value.m_ValueType == ECMA_TYPE_SIMPLE
&& value.value.m_Value == simple_value );
} /* ecma_is_completion_value_normal_simple_value */
/**
* Check if the completion value is normal true.
*
@@ -252,9 +268,7 @@ ecma_MakeThrowValue( ecma_Object_t *exception_p) /**< an object */
bool
ecma_IsCompletionValueNormalTrue( ecma_CompletionValue_t value) /**< completion value */
{
return ( value.type == ECMA_COMPLETION_TYPE_NORMAL
&& value.value.m_ValueType == ECMA_TYPE_SIMPLE
&& value.value.m_Value == ECMA_SIMPLE_VALUE_TRUE );
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_TRUE);
} /* ecma_IsCompletionValueNormalTrue */
/**
@@ -267,9 +281,7 @@ ecma_IsCompletionValueNormalTrue( ecma_CompletionValue_t value) /**< completion
bool
ecma_IsCompletionValueNormalFalse( ecma_CompletionValue_t value) /**< completion value */
{
return ( value.type == ECMA_COMPLETION_TYPE_NORMAL
&& value.value.m_ValueType == ECMA_TYPE_SIMPLE
&& value.value.m_Value == ECMA_SIMPLE_VALUE_FALSE );
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_FALSE);
} /* ecma_IsCompletionValueNormalFalse */
/**
+1
View File
@@ -55,6 +55,7 @@ extern void ecma_FreeValue( const ecma_Value_t value);
extern ecma_CompletionValue_t ecma_MakeCompletionValue( ecma_CompletionType_t type, ecma_Value_t value, uint8_t target);
extern ecma_CompletionValue_t ecma_MakeThrowValue( ecma_Object_t *exception_p);
extern bool ecma_is_completion_value_normal_simple_value( ecma_CompletionValue_t value, ecma_SimpleValue_t simple_value);
extern bool ecma_IsCompletionValueNormalFalse( ecma_CompletionValue_t value);
extern bool ecma_IsCompletionValueNormalTrue( ecma_CompletionValue_t value);
+4 -3
View File
@@ -16,6 +16,10 @@
#ifndef JERRY_ECMA_OPERATIONS_H
#define JERRY_ECMA_OPERATIONS_H
#include "ecma-globals.h"
#include "ecma-lex-env.h"
#include "ecma-reference.h"
/** \addtogroup ecma ---TODO---
* @{
*
@@ -23,9 +27,6 @@
* @{
*/
#include "ecma-globals.h"
#include "ecma-reference.h"
extern ecma_Reference_t ecma_OpGetIdentifierReference( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, bool is_strict);
extern ecma_CompletionValue_t ecma_OpGetValue( ecma_Reference_t *ref_p);