Merge branch 'master' into geppetto

This commit is contained in:
Ilmir Usmanov
2014-07-10 18:09:25 +04:00
12 changed files with 153 additions and 1047 deletions
+3
View File
@@ -35,6 +35,7 @@ SOURCES = \
$(wildcard ./src/libperipherals/actuators.c) \
$(wildcard ./src/libjsparser/*.c) \
$(wildcard ./src/libecmaobjects/*.c) \
$(wildcard ./src/libecmaoperations/*.c) \
$(wildcard ./src/liballocator/*.c) \
$(wildcard ./src/libcoreint/*.c) )
@@ -47,6 +48,7 @@ HEADERS = \
$(wildcard ./src/libperipherals/*.h) \
$(wildcard ./src/libjsparser/*.h) \
$(wildcard ./src/libecmaobjects/*.h) \
$(wildcard ./src/libecmaoperations/*.h) \
$(wildcard ./src/liballocator/*.h) \
$(wildcard ./src/libcoreint/*.h) )
@@ -55,6 +57,7 @@ INCLUDES = \
-I src/libperipherals \
-I src/libjsparser \
-I src/libecmaobjects \
-I src/libecmaoperations \
-I src/liballocator \
-I src/libcoreint
-1
View File
@@ -21,7 +21,6 @@
#include "mem-allocator.h"
#include "mem-heap.h"
#include "mem-poolman.h"
#include "ctx-manager.h"
/**
* Area for heap
+10 -2
View File
@@ -13,9 +13,10 @@
* limitations under the License.
*/
#include "ecma-operations.h"
#include "error.h"
#include "opcodes.h"
#include "interpreter.h"
#include "opcodes.h"
void
save_op_data (int pos, OPCODE opdata)
@@ -40,7 +41,14 @@ void opfunc_varg_3 (OPCODE opdata __unused, struct __int_data *int_data __unused
void opfunc_varg_3_end (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void opfunc_retval (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void opfunc_ret (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void opfunc_assignment (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void
opfunc_assignment(OPCODE opdata __unused,
struct __int_data *int_data __unused)
{
JERRY_UNREACHABLE ();
}
void opfunc_assignment_multiplication (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void opfunc_assignment_devision (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
void opfunc_assignment_remainder (OPCODE opdata __unused, struct __int_data *int_data __unused) { JERRY_UNREACHABLE (); }
-560
View File
@@ -1,560 +0,0 @@
/* 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.
*/
#include "ctx-manager.h"
#include "ctx-reference.h"
#include "globals.h"
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-conversion.h"
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "jerry-libc.h"
#include "mem-poolman.h"
/** \addtogroup ctxman Context manager
* @{
*/
/**
* Maximum depth of varibles' context nestings stack.
*
* TODO: Move to configuration header.
*/
#define CTX_MAX_NUMBER_OF_VARIABLES_CONTEXTS 32
/**
* JerryScript needs at least one variables' context nesting.
*/
JERRY_STATIC_ASSERT( CTX_MAX_NUMBER_OF_VARIABLES_CONTEXTS >= 1 );
/**
* Description of a variables' context
*/
typedef struct
{
/**
* Pointer to object, associated with 'this' keyword.
*/
ecma_Object_t *pThisBinding;
/**
* Chain of lexical environments
*/
ecma_Object_t *pLexicalEnvironment;
} ctx_VariablesContext_t;
/**
* Stack of variables' contexts.
*/
static ctx_VariablesContext_t ctx_Stack[ CTX_MAX_NUMBER_OF_VARIABLES_CONTEXTS ];
/**
* Current nestings' stack depth.
*/
static size_t ctx_ContextsNumber = 0;
/**
* Current variables' context (context on the top of stack)
*/
#define ctx_CurrentContext ( ctx_Stack[ ctx_ContextsNumber - 1 ])
/**
* The global object
*/
ecma_Object_t* ctx_pGlobalObject;
/**
* Get ecma-value from variable
*
* @return value descriptor
*/
static ecma_Value_t
ctx_GetValueDescriptorFromVariable( ctx_SyntacticReference_t *pVar) /**< variable */
{
/*
* TODO:
*/
(void)pVar;
JERRY_UNIMPLEMENTED();
} /* ctx_GetValueDescriptorFromVariable */
/**
* Get ecma-value from variable
*
* @return value descriptor
*/
static void
ctx_SetValueDescriptorToVariable(ctx_SyntacticReference_t *pVar, /**< variable */
ecma_Value_t value) /**< value descriptor */
{
/*
* TODO:
*/
(void)pVar;
(void)value;
JERRY_UNIMPLEMENTED();
} /* ctx_SetValueDescriptorToVariable */
/**
* Allocate a context.
*/
static void
ctx_AllocContext( void)
{
JERRY_ASSERT( ctx_ContextsNumber < CTX_MAX_NUMBER_OF_VARIABLES_CONTEXTS );
ctx_ContextsNumber++;
} /* ctx_AllocContext */
/**
* Create new lexical environment using specified object as binding object,
* setting provideThis to specified value.
* The lexical environment is inherited from current context's lexical environment.
*/
static void
ctx_CreateLexicalEnvironmentFromObject(ecma_Object_t *pObject, /**< pointer to bindingObject */
bool provideThis) /**< value of 'provideThis' attribute */
{
ecma_Object_t *pNewLexicalEnvironment = ecma_CreateLexicalEnvironment(ctx_CurrentContext.pLexicalEnvironment,
true);
/* We don't change reference counter of ctx_CurrentContext.pLexicalEnvironment here,
because we remove one reference from ctx_CurrentContext,
and add one reference from pNewLexicalEnvironment */
ctx_CurrentContext.pLexicalEnvironment = pNewLexicalEnvironment;
ecma_Property_t *pProvideThisProperty = ecma_CreateInternalProperty( pNewLexicalEnvironment, ECMA_INTERNAL_PROPERTY_PROVIDE_THIS);
pProvideThisProperty->u.m_InternalProperty.m_Value = provideThis;
ecma_Property_t *pBindingObjectProperty = ecma_CreateInternalProperty( pNewLexicalEnvironment, ECMA_INTERNAL_PROPERTY_BINDING_OBJECT);
ecma_RefObject( pObject);
ecma_SetPointer( pBindingObjectProperty->u.m_InternalProperty.m_Value, pObject);
} /* ctx_CreateLexicalEnvironmentFromObject */
/**
* Initialize the global object.
*/
static void
ctx_InitGlobalObject( void)
{
ctx_pGlobalObject = ecma_CreateObject( NULL, true);
} /* ctx_InitGlobalObject */
/**
* \addtogroup interface Context manager's interface
* @{
*/
/**
* Initialize context manager and global execution context.
*/
void
ctx_Init(void)
{
JERRY_ASSERT( ctx_ContextsNumber == 0 );
#ifndef JERRY_NDEBUG
__memset( ctx_Stack, 0, sizeof (ctx_Stack));
#endif /* !JERRY_NDEBUG */
ctx_InitGlobalObject();
ctx_NewContextFromGlobalObject();
} /* ctx_Init */
/**
* Create new variables' context using global object
* for ThisBinding and lexical environment.
*/
void
ctx_NewContextFromGlobalObject(void)
{
ctx_AllocContext();
ecma_RefObject( ctx_pGlobalObject);
ctx_CurrentContext.pThisBinding = ctx_pGlobalObject;
ctx_CurrentContext.pLexicalEnvironment = NULL;
ctx_CreateLexicalEnvironmentFromObject( ctx_pGlobalObject, false);
JERRY_ASSERT( ctx_CurrentContext.pLexicalEnvironment != NULL );
} /* ctx_NewContextFromGlobalObject */
/**
* Create new variables' context inheriting lexical environment from specified
* function's [[Scope]], and setting ThisBinding from pThisVar parameter
* (see also ECMA-262 5.1, 10.4.3).
*/
void
ctx_NewContextFromFunctionScope(ctx_SyntacticReference_t *pThisVar, /**< object for ThisBinding */
ctx_SyntacticReference_t *pFunctionVar) /**< Function object */
{
ctx_AllocContext();
ecma_Value_t thisArgValue = ctx_GetValueDescriptorFromVariable( pThisVar);
ecma_Value_t functionArgValue = ctx_GetValueDescriptorFromVariable( pFunctionVar);
ecma_Object_t *pThisBindingObject;
if ( thisArgValue.m_ValueType == ECMA_TYPE_SIMPLE
&& ( thisArgValue.m_Value == ECMA_SIMPLE_VALUE_NULL
|| thisArgValue.m_Value == ECMA_SIMPLE_VALUE_UNDEFINED ) )
{
pThisBindingObject = ctx_pGlobalObject;
} else
{
pThisBindingObject = ecma_ToObject( thisArgValue);
}
ecma_RefObject( pThisBindingObject);
ctx_CurrentContext.pThisBinding = pThisBindingObject;
JERRY_ASSERT( functionArgValue.m_ValueType == ECMA_TYPE_OBJECT );
ecma_Object_t *pFunctionObject = ecma_GetPointer( functionArgValue.m_Value);
ecma_Property_t *pScopeProperty = ecma_GetInternalProperty( pFunctionObject, ECMA_INTERNAL_PROPERTY_SCOPE);
ecma_Object_t *pScopeObject = ecma_GetPointer( pScopeProperty->u.m_InternalProperty.m_Value);
ecma_RefObject( pScopeObject);
ecma_Object_t *pLexicalEnvironment = ecma_CreateLexicalEnvironment(pScopeObject, false);
/* We don't change reference counter of ctx_CurrentContext.pLexicalEnvironment here,
because we remove one reference from ctx_CurrentContext,
and add one reference from pNewLexicalEnvironment */
ctx_CurrentContext.pLexicalEnvironment = pLexicalEnvironment;
} /* ctx_NewContextFromFunctionScope */
/**
* Create new lexical environment using specified object as binding object,
* setting provideThis to specified value.
* The lexical environment is inherited from current context's lexical environment.
*/
void
ctx_NewLexicalEnvironmentFromObject(ctx_SyntacticReference_t *pObjectVar, /**< binding object */
bool provideThis) /**< 'provideThis' attribute */
{
ecma_Object_t *pObject = ecma_ToObject( ctx_GetValueDescriptorFromVariable( pObjectVar));
ctx_CreateLexicalEnvironmentFromObject( pObject, provideThis);
} /* ctx_NewLexicalEnvironmentFromObject */
/**
* Exit from levelsToExit lexical environments (i.e. choose lexical environment
* that is levelsToExit outward current lexical environment as new current context's
* lexical environment).
*/
void
ctx_ExitLexicalEnvironments(uint32_t levelsToExit) /**< number of lexical environments
* to exit from */
{
JERRY_ASSERT( levelsToExit > 0 );
for ( uint32_t count = 0;
count < levelsToExit;
count++ )
{
JERRY_ASSERT( ctx_CurrentContext.pLexicalEnvironment != NULL );
ecma_Object_t *pOuterLexicalEnvironment = ecma_GetPointer( ctx_CurrentContext.pLexicalEnvironment->u_Attributes.m_LexicalEnvironment.m_pOuterReference);
ecma_DerefObject( ctx_CurrentContext.pLexicalEnvironment);
ctx_CurrentContext.pLexicalEnvironment = pOuterLexicalEnvironment;
}
JERRY_ASSERT( ctx_CurrentContext.pLexicalEnvironment != NULL );
} /* ctx_ExitLexicalEnvironments */
/**
* Exit from levelsToExit variables' contexts (i.e. choose context
* that is levelsToExit from current context as new current context).
*/
void
ctx_ExitContexts(uint32_t levelsToExit) /**< number of contexts to exit from */
{
JERRY_ASSERT( levelsToExit > 0 );
for ( uint32_t count = 0;
count < levelsToExit;
count++ )
{
JERRY_ASSERT( ctx_ContextsNumber > 0 );
ecma_DerefObject( ctx_CurrentContext.pThisBinding);
while ( ctx_CurrentContext.pLexicalEnvironment != NULL )
{
ecma_Object_t *pOuterLexicalEnvironment =
ecma_GetPointer(ctx_CurrentContext.pLexicalEnvironment->
u_Attributes.m_LexicalEnvironment.
m_pOuterReference);
ecma_DerefObject( ctx_CurrentContext.pLexicalEnvironment);
ctx_CurrentContext.pLexicalEnvironment = pOuterLexicalEnvironment;
}
ctx_ContextsNumber--;
}
JERRY_ASSERT( ctx_ContextsNumber > 0 );
} /* ctx_ExitContexts */
/**
* Create new variable with undefined value in the current lexical environment.
*/
void
ctx_NewVariable( ctx_SyntacticReference_t *pVar) /**< variable id */
{
ecma_Object_t *lexicalEnvironment = ctx_CurrentContext.pLexicalEnvironment;
/*
* TODO:
*/
(void) pVar;
JERRY_UNIMPLEMENTED();
switch ( (ecma_LexicalEnvironmentType_t) lexicalEnvironment->u_Attributes.m_LexicalEnvironment.m_Type )
{
case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND:
{
ecma_Property_t *pBindingObjectProperty = ecma_FindInternalProperty(lexicalEnvironment,
ECMA_INTERNAL_PROPERTY_BINDING_OBJECT);
JERRY_ASSERT( pBindingObjectProperty != NULL );
ecma_Object_t *pBindingObject = ecma_GetPointer( pBindingObjectProperty->u.m_InternalProperty.m_Value);
JERRY_ASSERT( pBindingObject != NULL );
break;
}
case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE:
{
break;
}
}
} /* ctx_NewVariable */
/**
* Delete specified variable.
*/
void
ctx_DeleteVariable( ctx_SyntacticReference_t *pVar) /**< variable id */
{
/*
* TODO:
*/
(void) pVar;
JERRY_UNIMPLEMENTED();
} /* ctx_DeleteVariable */
/**
* Copy variable's/property's/array's element's value.
*/
void
ctx_CopyVariable(ctx_SyntacticReference_t *pVarFrom, /**< source variable */
ctx_SyntacticReference_t *pVarTo) /**< destination variable */
{
ecma_Value_t sourceVariableValue = ctx_GetValueDescriptorFromVariable( pVarFrom);
ecma_Value_t destinationVariableValue;
destinationVariableValue.m_ValueType = sourceVariableValue.m_ValueType;
switch ( (ecma_Type_t) sourceVariableValue.m_ValueType )
{
case ECMA_TYPE_SIMPLE:
{
destinationVariableValue.m_Value = sourceVariableValue.m_Value;
break;
}
case ECMA_TYPE_NUMBER:
{
ecma_Number_t *pNumberCopy = ecma_AllocNumber();
__memcpy( pNumberCopy,
ecma_GetPointer( sourceVariableValue.m_Value),
sizeof (ecma_Number_t));
ecma_SetPointer( destinationVariableValue.m_Value, pNumberCopy);
break;
}
case ECMA_TYPE_STRING:
{
ecma_SetPointer(destinationVariableValue.m_Value,
ecma_DuplicateEcmaString( ecma_GetPointer( sourceVariableValue.m_Value)));
break;
}
case ECMA_TYPE_OBJECT:
{
ecma_RefObject( ecma_GetPointer( sourceVariableValue.m_Value));
destinationVariableValue.m_Value = sourceVariableValue.m_Value;
break;
}
case ECMA_TYPE__COUNT:
{
JERRY_UNREACHABLE();
}
}
ctx_SetValueDescriptorToVariable( pVarTo, destinationVariableValue);
} /* ctx_CopyVariable */
/**
* Get type of value of specified variable/property/array's element.
*/
ecma_Type_t
ctx_GetVariableType(ctx_SyntacticReference_t *pVar) /**< variable */
{
ecma_Value_t variableValue = ctx_GetValueDescriptorFromVariable( pVar);
return variableValue.m_ValueType;
} /* ctx_GetVariableType */
/**
* Get specified variable's/property's/array's element's value.
*
* @return number of bytes, actually copied to the buffer, if variable value was copied successfully;
* negative number, which is calculated as negation of buffer size, that is required
* to hold the variable's value (in case size of buffer is insuficcient).
*/
ssize_t
ctx_GetVariableValue(ctx_SyntacticReference_t *pVar, /**< variable */
uint8_t *pBuffer, /**< buffer */
size_t bufferSize) /**< size of buffer */
{
ecma_Value_t variableValue = ctx_GetValueDescriptorFromVariable( pVar);
switch ( (ecma_Type_t) variableValue.m_ValueType )
{
case ECMA_TYPE_SIMPLE:
{
if ( bufferSize < sizeof (ecma_SimpleValue_t) )
{
return -(ssize_t)sizeof (ecma_SimpleValue_t);
} else
{
*(ecma_SimpleValue_t*) pBuffer = variableValue.m_Value;
return sizeof (ecma_SimpleValue_t);
}
break;
}
case ECMA_TYPE_NUMBER:
{
if ( bufferSize < sizeof (ecma_Number_t) )
{
return -(ssize_t)sizeof (ecma_Number_t);
} else
{
ecma_Number_t *pNumber = ecma_GetPointer(variableValue.m_Value);
*(ecma_Number_t*) pBuffer = *pNumber;
return sizeof (ecma_Number_t);
}
break;
}
case ECMA_TYPE_STRING:
{
ecma_ArrayFirstChunk_t *pStringFirstChunk = ecma_GetPointer(variableValue.m_Value);
return ecma_CopyEcmaStringCharsToBuffer( pStringFirstChunk, pBuffer, bufferSize);
}
case ECMA_TYPE_OBJECT: /* cannot return object itself (only value of a property or of an array's element */
case ECMA_TYPE__COUNT:
{
/* will trap below */
}
}
JERRY_UNREACHABLE();
} /* ctx_GetVariableValue */
/**
* Set variable's/property's/array's element's value to one of simple values.
*/
void
ctx_SetVariableToSimpleValue(ctx_SyntacticReference_t *pVar, /**< variable */
ecma_SimpleValue_t value) /**< value */
{
ecma_Value_t valueToSet;
valueToSet.m_ValueType = ECMA_TYPE_SIMPLE;
valueToSet.m_Value = value;
ctx_SetValueDescriptorToVariable( pVar, valueToSet);
} /* ctx_SetVariableToSimpleValue */
/**
* Set variable's/property's/array's element's value to a Number.
*/
void
ctx_SetVariableToNumber(ctx_SyntacticReference_t *pVar, /**< variable */
ecma_Number_t value) /**< value */
{
ecma_Number_t *pNumber = ecma_AllocNumber();
*pNumber = value;
ecma_Value_t valueToSet;
valueToSet.m_ValueType = ECMA_TYPE_NUMBER;
ecma_SetPointer( valueToSet.m_Value, pNumber);
ctx_SetValueDescriptorToVariable( pVar, valueToSet);
} /* ctx_SetVariableToNumber */
/**
* Set variable's/property's/array's element's value to a String.
*/
void
ctx_SetVariableToString(ctx_SyntacticReference_t *pVar, /**< variable */
ecma_Char_t *value, /**< string's characters */
ecma_Length_t length) /**< string's length, in characters */
{
ecma_Value_t valueToSet;
valueToSet.m_ValueType = ECMA_TYPE_STRING;
ecma_SetPointer( valueToSet.m_Value, ecma_NewEcmaString( value, length));
ctx_SetValueDescriptorToVariable( pVar, valueToSet);
} /* ctx_SetVariableToString */
/**
* @}
*/
/**
* Static checks that ecma types fit size requirements.
*
* Warning:
* must not be called
*/
static void __unused
ctx_EcmaTypesSizeCheckers( void)
{
JERRY_STATIC_ASSERT( sizeof (ecma_Value_t) <= sizeof (uint16_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_Property_t) <= sizeof (uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_Object_t) <= sizeof (uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayHeader_t) <= sizeof (uint32_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayFirstChunk_t) == ECMA_ARRAY_CHUNK_SIZE_IN_BYTES );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayNonFirstChunk_t) == ECMA_ARRAY_CHUNK_SIZE_IN_BYTES );
JERRY_UNREACHABLE();
} /* ctx_EcmaTypesSizeCheckers */
/**
* @}
*/
-124
View File
@@ -1,124 +0,0 @@
/* 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 JERRY_CTX_MANAGER_H
#define JERRY_CTX_MANAGER_H
#include "ctx-reference.h"
#include "globals.h"
#include "ecma-globals.h"
/** \addtogroup ctxman Context manager
* @{
* \addtogroup interface Context manager's interface
* @{
*/
/**
* Initialize context manager and global execution context.
*/
extern void ctx_Init(void);
/**
* Create new variables' context using global object
* for ThisBinding and lexical environments.
*/
extern void ctx_NewContextFromGlobalObject(void);
/**
* Create new variables' context inheriting lexical environment from specified
* function's [[Scope]], and setting ThisBinding from pThisVar parameter
* (see also ECMA-262 5.1, 10.4.3).
*/
extern void ctx_NewContextFromFunctionScope(ctx_SyntacticReference_t *pThisVar, ctx_SyntacticReference_t *pFunctionVar);
/**
* Create new lexical environment using specified object as binding object,
* setting provideThis to specified value.
* The lexical environment is inherited from current context's lexical environment.
*/
extern void ctx_NewLexicalEnvironmentFromObject(ctx_SyntacticReference_t *pObjectVar, bool provideThis);
/**
* Exit from levelsToExit lexical environments (i.e. choose lexical environment
* that is levelsToExit outward current lexical environment as new current context's
* lexical environment).
*/
extern void ctx_ExitLexicalEnvironments(uint32_t levelsToExit);
/**
* Exit from levelsToExit variables' contexts (i.e. choose context
* that is levelsToExit from current context as new current context).
*/
extern void ctx_ExitContexts(uint32_t levelsToExit);
/**
* Create new variable with undefined value.
*/
extern void ctx_NewVariable(ctx_SyntacticReference_t *pVar);
/**
* Delete specified variable.
*/
extern void ctx_DeleteVariable(ctx_SyntacticReference_t *pVar);
/**
* Check if specified variable exists
*
* @return true, if exists;
* false - otherwise.
*/
extern bool ctx_DoesVariableExist(ctx_SyntacticReference_t *pVar);
/**
* Copy variable's/property's/array's element's value.
*/
extern void ctx_CopyVariable(ctx_SyntacticReference_t *pVarFrom, ctx_SyntacticReference_t *pVarTo);
/**
* Get type of specified of variable/property/array's element.
*/
extern ecma_Type_t ctx_GetVariableType(ctx_SyntacticReference_t *pVar);
/**
* Get specified variable's/property's/array's element's value.
*
* @return number of bytes, actually copied to the buffer, if variable value was copied successfully;
* negative number, which is calculated as negation of buffer size, that is required
* to hold the variable's value (in case size of buffer is insuficcient).
*/
extern ssize_t ctx_GetVariableValue(ctx_SyntacticReference_t *pVar, uint8_t *pBuffer, size_t bufferSize);
/**
* Set variable's/property's/array's element's value to one of simple values.
*/
extern void ctx_SetVariableToSimpleValue(ctx_SyntacticReference_t *pVar, ecma_SimpleValue_t value);
/**
* Set variable's/property's/array's element's value to a Number.
*/
extern void ctx_SetVariableToNumber(ctx_SyntacticReference_t *pVar, ecma_Number_t value);
/**
* Set variable's/property's/array's element's value to a String.
*/
extern void ctx_SetVariableToString(ctx_SyntacticReference_t *pVar, ecma_Char_t *value, ecma_Length_t length);
#endif /* !JERRY_CTX_MANAGER_H */
/**
* @}
* @}
*/
-224
View File
@@ -1,224 +0,0 @@
/* 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.
*/
/** \addtogroup ctxman Context manager
* @{
*
* \addtogroup resolvedreference Resolved reference type
* @{
*/
/**
* Implementation of Reference's operations
*/
#include "globals.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ctx-reference.h"
/**
* GetBase operation of Reference.
*
* @return base value component of reference
*/
ecma_Object_t*
ctx_reference_get_base( ctx_Reference_t *reference_p) /**< reference */
{
return reference_p->m_Base;
} /* ctx_reference_get_base */
/**
* GetReferencedName operation of Reference.
*
* @return pointer to first chunk of ecma-array containing the referenced name
*/
const ecma_ArrayFirstChunk_t*
ctx_reference_get_referenced_name( ctx_Reference_t *reference_p) /**< reference */
{
const ecma_Property_t *property_p = reference_p->m_ReferencedProperty;
switch ( (ecma_PropertyType_t) property_p->m_Type )
{
case ECMA_PROPERTY_NAMEDDATA:
return ecma_GetPointer( property_p->u.m_NamedDataProperty.m_pName);
case ECMA_PROPERTY_NAMEDACCESSOR:
return ecma_GetPointer( property_p->u.m_NamedAccessorProperty.m_pName);
case ECMA_PROPERTY_INTERNAL:
/* will trap below */
break;
}
JERRY_UNREACHABLE();
} /* ctx_reference_get_referenced_name */
/**
* IsStrictReference operation of Reference.
*
* @return strict component of reference:
* true - if reference is strict,
* false - otherwise.
*/
bool
ctx_reference_is_strict_reference( ctx_Reference_t *reference_p) /**< reference */
{
return reference_p->m_Strict;
} /* ctx_reference_is_strict_reference */
/**
* IsPropertyReference operation of Reference.
*
* @return true - if either the base value is an object or HasPrimitiveBase returns true;
* false - otherwise.
*/
bool
ctx_reference_is_property_reference( ctx_Reference_t * reference_p) /**< reference */
{
return (reference_p->m_Base != NULL
&& !reference_p->m_Base->m_IsLexicalEnvironment );
} /* ctx_reference_is_property_reference */
/**
* IsUnresolvableReference operation of Reference.
*
* @return true - if the base value is undefined;
* false - otherwise.
*/
bool
ctx_reference_is_unresolvable_reference( ctx_Reference_t * reference_p) /**< reference */
{
return ( reference_p->m_Base == NULL );
} /* ctx_reference_is_unresolvable_reference */
/**
* Get referenced property.
*
* @return pointer to ecma-property
* (which describes object's property or a lexical environment's binding).
*/
ecma_Property_t*
ctx_reference_get_referenced_component( ctx_Reference_t *reference_p) /**< reference */
{
return reference_p->m_ReferencedProperty;
} /* ctx_reference_get_referenced_component */
/**
* Resolve syntactic reference
*
* Note:
* Returned value must be freed using ctx_free_resolved_reference
*
* @return pointer to resolved reference description
*/
ctx_Reference_t*
ctx_resolve_syntactic_reference(ecma_Object_t *lex_env_p, /**< lexical environment of current context */
ctx_SyntacticReference_t *syntactic_reference_p) /** syntactic reference
* to resolve */
{
JERRY_ASSERT(lex_env_p != NULL
&& lex_env_p->m_GCInfo.m_IsObjectValid
&& lex_env_p->m_IsLexicalEnvironment );
JERRY_ASSERT(syntactic_reference_p != NULL
&& syntactic_reference_p->m_Name != NULL
&& ( !syntactic_reference_p->m_IsPropertyReference
|| syntactic_reference_p->m_PropertyName != NULL ) );
ctx_Reference_t *reference_p = (ctx_Reference_t*) mem_HeapAllocBlock(sizeof (ctx_Reference_t), MEM_HEAP_ALLOC_LONG_TERM);
bool is_variable_resolved = false;
ecma_Property_t *resolved_variable_p = NULL;
/* resolving variable name */
while ( !is_variable_resolved && lex_env_p != NULL )
{
for ( ecma_Property_t *property_p = ecma_GetPointer( lex_env_p->m_pProperties);
property_p != NULL;
property_p = ecma_GetPointer( property_p->m_pNextProperty) )
{
ecma_ArrayFirstChunk_t *property_name_p = NULL;
/*
* TODO: make corresponding helper
*/
switch ( (ecma_PropertyType_t) property_p->m_Type )
{
case ECMA_PROPERTY_NAMEDDATA:
property_name_p = ecma_GetPointer( property_p->u.m_NamedDataProperty.m_pName);
break;
case ECMA_PROPERTY_NAMEDACCESSOR:
property_name_p = ecma_GetPointer( property_p->u.m_NamedAccessorProperty.m_pName);
break;
case ECMA_PROPERTY_INTERNAL:
continue;
}
if ( ecma_CompareCharBufferToEcmaString(syntactic_reference_p->m_Name,
property_name_p) )
{
resolved_variable_p = property_p;
is_variable_resolved = true;
break;
}
}
lex_env_p = ecma_GetPointer( lex_env_p->u_Attributes.m_LexicalEnvironment.m_pOuterReference);
}
if ( !is_variable_resolved )
{
*reference_p = (ctx_Reference_t){
.m_IsValid = true,
.m_Base = NULL,
.m_ReferencedProperty = NULL,
.m_Strict = syntactic_reference_p->m_StrictReference
};
} else
{
if ( !syntactic_reference_p->m_IsPropertyReference )
{
*reference_p = (ctx_Reference_t){
.m_IsValid = true,
.m_Base = lex_env_p,
.m_ReferencedProperty = resolved_variable_p,
.m_Strict = syntactic_reference_p->m_StrictReference
};
} else
{
JERRY_UNIMPLEMENTED();
}
}
return reference_p;
} /* ctx_resolve_syntactic_reference */
void
ctx_free_resolved_reference( ctx_Reference_t *reference_p)
{
(void)reference_p;
JERRY_UNIMPLEMENTED();
} /* ctx_free_resolved_reference */
/**
* @}
* @}
*/
-133
View File
@@ -1,133 +0,0 @@
/* 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 CTX_REFERENCE_H
#define CTX_REFERENCE_H
#include "ctx-reference.h"
#include "globals.h"
#include "ecma-globals.h"
/** \addtogroup ctxman Context manager
* @{
*/
/**
* \addtogroup syntacticreference Textual reference to variable/property
* @{
*/
/**
* Syntactic (textual/unresolved) reference to a variable/object's property.
*/
typedef struct {
/**
* Flag indicating that this is reference to a property.
*
* Note:
* m_PropertyName is valid only if m_IsPropertyReference is true.
*/
uint32_t m_IsPropertyReference : 1;
/**
* Flag indicating that this reference is strict (see also: ECMA-262 v5, 8.7).
*/
uint32_t m_StrictReference : 1;
/**
* Name of variable (Null-terminated string).
*/
ecma_Char_t* m_Name;
/**
* Name of object's property (Null-terminated string).
*/
ecma_Char_t* m_PropertyName;
} ctx_SyntacticReference_t;
/**
* @}
*/
/**
* \addtogroup resolvedreference Resolved reference type
* @{
*/
/**
* Description of resolved reference.
*
* Implementation details:
* 1. In contrast to Reference specification type the referenced name
* is not stored as string, but is resolved and stored as pointer
* to ecma-property.
*
* If the referenced element is deleted, the m_IsValid must be set to false.
*
* 2. Is base is Boolean, String, Number, then it is converted to Object via
* ecma_ToObject and then is stored in the reference.
*
* See also: ECMA-262 v5, 8.7.
*/
typedef struct
{
/**
* Flag indicating whether the reference is valid.
*
* The flag is initially set to true.
*
*/
bool m_IsValid;
/**
* Base value
*
* May be undefined (NULL), Object or Lexical Environment
*/
ecma_Object_t* m_Base;
/**
* Referenced property.
*
* Note:
* in case base is lexical environment this is reference to variable.
*/
ecma_Property_t* m_ReferencedProperty;
/**
* Strict reference flag.
*/
bool m_Strict;
} ctx_Reference_t;
/*
* ctx-reference.c
*/
extern ecma_Object_t* ctx_reference_get_base( ctx_Reference_t *reference_p);
extern const ecma_ArrayFirstChunk_t* ctx_reference_get_referenced_name( ctx_Reference_t *reference_p);
extern bool ctx_reference_is_strict_reference( ctx_Reference_t *reference_p);
extern bool ctx_reference_is_property_reference( ctx_Reference_t *reference_p);
extern bool ctx_reference_is_unresolvable_reference( ctx_Reference_t *reference_p);
extern ecma_Property_t *ctx_reference_get_referenced_component( ctx_Reference_t *reference_p);
extern ctx_Reference_t* ctx_resolve_syntactic_reference( ecma_Object_t *lex_env_p, ctx_SyntacticReference_t *syntactic_reference_p);
extern void ctx_free_resolved_reference( ctx_Reference_t *reference_p);
/**
* @}
* @}
*/
#endif /* !CTX_REFERENCE_H */
+9 -1
View File
@@ -38,6 +38,14 @@
#include "ecma-gc.h"
#include "mem-poolman.h"
JERRY_STATIC_ASSERT( sizeof (ecma_Value_t) <= sizeof (uint16_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_Property_t) <= sizeof (uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_Object_t) <= sizeof (uint64_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayHeader_t) <= sizeof (uint32_t) );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayFirstChunk_t) == ECMA_ARRAY_CHUNK_SIZE_IN_BYTES );
JERRY_STATIC_ASSERT( sizeof (ecma_ArrayNonFirstChunk_t) == ECMA_ARRAY_CHUNK_SIZE_IN_BYTES );
JERRY_STATIC_ASSERT( sizeof (ecma_CompletionValue_t) == sizeof(uint32_t) );
/**
* Template of an allocation routine.
*/
@@ -79,4 +87,4 @@ DECLARE_ROUTINES_FOR (ArrayNonFirstChunk)
/**
* @}
* @}
*/
*/
+33
View File
@@ -67,6 +67,10 @@ typedef enum {
ECMA_SIMPLE_VALUE_NULL, /**< null value */
ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */
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,
but is stored directly in the array's property list
(used for array elements with non-default attribute values) */
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */
} ecma_SimpleValue_t;
@@ -79,6 +83,19 @@ typedef enum {
ECMA_PROPERTY_INTERNAL /**< internal property */
} ecma_PropertyType_t;
/**
* Type of block evaluation (completion) result.
*
* See also: ECMA-262 v5, 8.9.
*/
typedef enum {
ECMA_COMPLETION_TYPE_NORMAL, /**< default block completion */
ECMA_COMPLETION_TYPE_RETURN, /**< block completed with return */
ECMA_COMPLETION_TYPE_BREAK, /**< block completed with break */
ECMA_COMPLETION_TYPE_CONTINUE, /**< block completed with continue */
ECMA_COMPLETION_TYPE_THROW /**< block completed with throw */
} ecma_CompletionType_t;
/**
* Description of an ecma-value
*/
@@ -92,6 +109,22 @@ typedef struct {
uint32_t m_Value : ECMA_POINTER_FIELD_WIDTH;
} __packed ecma_Value_t;
/**
* Description of a block completion value
*
* See also: ECMA-262 v5, 8.9.
*/
typedef struct {
/** Type (ecma_CompletionType_t) */
uint32_t completion_type : 3;
/** Value */
ecma_Value_t completion_value;
/** Target */
uint32_t target : 8;
} __packed ecma_CompletionValue_t;
/**
* Internal properties' identifiers.
*/
+61
View File
@@ -0,0 +1,61 @@
/* 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 ECMA_REFERENCE_H
#define ECMA_REFERENCE_H
/** \addtogroup ecma ---TODO---
* @{
*/
/**
* \addtogroup syntacticreference Textual reference to variable/property
* @{
*/
/**
* Syntactic (textual/unresolved) reference to a variable/object's property.
*/
typedef struct {
/**
* Flag indicating that this is reference to a property.
*
* Note:
* m_PropertyName is valid only if m_IsPropertyReference is true.
*/
uint32_t m_IsPropertyReference : 1;
/**
* Flag indicating that this reference is strict (see also: ECMA-262 v5, 8.7).
*/
uint32_t m_StrictReference : 1;
/**
* Name of variable (Null-terminated string).
*/
ecma_Char_t* m_Name;
/**
* Name of object's property (Null-terminated string).
*/
ecma_Char_t* m_PropertyName;
} ecma_SyntacticReference_t;
/**
* @}
* @}
*/
#endif /* !ECMA_REFERENCE_H */
+37
View File
@@ -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 JERRY_ECMA_OPERATIONS_H
#define JERRY_ECMA_OPERATIONS_H
/** \addtogroup ecma ---TODO---
* @{
*
* \addtogroup ecmaoperations ECMA-defined operations
* @{
*/
#include "ecma-globals.h"
#include "ecma-reference.h"
extern ecma_CompletionValue_t ecma_GetValue( ecma_SyntacticReference_t *ref_p);
extern ecma_CompletionValue_t ecma_SetValue( ecma_SyntacticReference_t *ref_p, ecma_Value_t value);
/**
* @}
* @}
*/
#endif /* JERRY_ECMA_OPERATIONS_H */
-2
View File
@@ -32,7 +32,6 @@
#include "error.h"
#include "ctx-manager.h"
#include "mem-allocator.h"
#include "interpreter.h"
@@ -108,7 +107,6 @@ main (int argc, char **argv)
#endif
mem_Init ();
ctx_Init ();
if (argc > 0)
for (int i = 1; i < argc; i++)