manualy generated blinky opcodes
This commit is contained in:
@@ -0,0 +1,560 @@
|
||||
/* 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
|
||||
libc_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();
|
||||
libc_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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,124 @@
|
||||
/* 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,224 @@
|
||||
/* 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,133 @@
|
||||
/* 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 */
|
||||
@@ -0,0 +1,82 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of routins for allocation/freeing memory for ECMA data types.
|
||||
*
|
||||
* All allocation routines from this module have the same structure:
|
||||
* 1. Try to allocate memory.
|
||||
* 2. If allocation was successful, return pointer to the allocated block.
|
||||
* 3. Run garbage collection.
|
||||
* 4. Try to allocate memory.
|
||||
* 5. If allocation was successful, return pointer to the allocated block;
|
||||
* else - shutdown engine.
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "mem-poolman.h"
|
||||
|
||||
/**
|
||||
* Template of an allocation routine.
|
||||
*/
|
||||
#define ALLOC( ecmaType) ecma_ ## ecmaType ## _t * \
|
||||
ecma_Alloc ## ecmaType (void) \
|
||||
{ \
|
||||
ecma_ ## ecmaType ## _t *p ## ecmaType = (ecma_ ## ecmaType ## _t *) \
|
||||
mem_PoolsAlloc( mem_SizeToPoolChunkType( sizeof(ecma_ ## ecmaType ## _t))); \
|
||||
\
|
||||
ecma_GCRun(); \
|
||||
JERRY_ASSERT( p ## ecmaType != NULL ); \
|
||||
\
|
||||
return p ## ecmaType; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Free routine template
|
||||
*/
|
||||
#define FREE( ecmaType) void \
|
||||
ecma_Free ## ecmaType( ecma_ ## ecmaType ## _t *p ## ecmaType) \
|
||||
{ \
|
||||
mem_PoolsFree( mem_SizeToPoolChunkType( sizeof(ecma_ ## ecmaType ## _t)), \
|
||||
(uint8_t*) p ## ecmaType); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Declaration of alloc/free routine for specified ecma-type.
|
||||
*/
|
||||
#define DECLARE_ROUTINES_FOR( ecmaType) \
|
||||
ALLOC( ecmaType) \
|
||||
FREE( ecmaType)
|
||||
|
||||
DECLARE_ROUTINES_FOR (Object)
|
||||
DECLARE_ROUTINES_FOR (Property)
|
||||
DECLARE_ROUTINES_FOR (Number)
|
||||
DECLARE_ROUTINES_FOR (ArrayFirstChunk)
|
||||
DECLARE_ROUTINES_FOR (ArrayNonFirstChunk)
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,93 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ECMA_ALLOC_H
|
||||
#define JERRY_ECMA_ALLOC_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-object
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
extern ecma_Object_t *ecma_AllocObject(void);
|
||||
|
||||
/**
|
||||
* Free memory from an ecma-object
|
||||
*/
|
||||
extern void ecma_FreeObject( ecma_Object_t *pObject);
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-property
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
extern ecma_Property_t *ecma_AllocProperty(void);
|
||||
|
||||
/**
|
||||
* Free memory from an ecma-property
|
||||
*/
|
||||
extern void ecma_FreeProperty( ecma_Property_t *pProperty);
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-number
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
extern ecma_Number_t *ecma_AllocNumber(void);
|
||||
|
||||
/**
|
||||
* Free memory from an ecma-number
|
||||
*/
|
||||
extern void ecma_FreeNumber( ecma_Number_t *pNumber);
|
||||
|
||||
/**
|
||||
* Allocate memory for first chunk of an ecma-array
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
extern ecma_ArrayFirstChunk_t *ecma_AllocArrayFirstChunk(void);
|
||||
|
||||
/**
|
||||
* Free memory from first chunk of an ecma-array
|
||||
*/
|
||||
extern void ecma_FreeArrayFirstChunk( ecma_ArrayFirstChunk_t *pFirstChunk);
|
||||
|
||||
/**
|
||||
* Allocate memory for non-first chunk of an ecma-array
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
extern ecma_ArrayNonFirstChunk_t *ecma_AllocArrayNonFirstChunk(void);
|
||||
|
||||
/**
|
||||
* Free memory from non-first chunk of an ecma-array
|
||||
*/
|
||||
extern void ecma_FreeArrayNonFirstChunk( ecma_ArrayNonFirstChunk_t *pNumber);
|
||||
|
||||
#endif /* JERRY_ECMA_ALLOC_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,59 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaconversion ECMA conversion
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ECMA_CONVERSION_H
|
||||
#define JERRY_ECMA_CONVERSION_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
extern ecma_Object_t* ecma_ToObject( ecma_Value_t value);
|
||||
|
||||
/*
|
||||
* Stubs
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert value to ecma-object.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 5.1, 9.9.
|
||||
*
|
||||
* @return pointer to ecma-object descriptor
|
||||
*/
|
||||
ecma_Object_t*
|
||||
ecma_ToObject(ecma_Value_t value) /**< ecma-value */
|
||||
{
|
||||
if ( value.m_ValueType == ECMA_TYPE_OBJECT )
|
||||
{
|
||||
return ecma_DecompressPointer( value.m_Value);
|
||||
}
|
||||
|
||||
JERRY_UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
#endif /* !JERRY_ECMA_CONVERSION_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,284 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmagc Garbage collector
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Garbage collector implementation
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/**
|
||||
* Queue of objects, awaiting for GC
|
||||
*/
|
||||
static ecma_Object_t *ecma_GC_Queue;
|
||||
|
||||
/**
|
||||
* Queue object for GC.
|
||||
*
|
||||
* Warning:
|
||||
* After this operation the object is not longer valid for general use.
|
||||
*/
|
||||
static void
|
||||
ecma_GCQueue( ecma_Object_t *pObject) /**< object */
|
||||
{
|
||||
JERRY_ASSERT( pObject != NULL );
|
||||
JERRY_ASSERT( pObject->m_GCInfo.m_IsObjectValid );
|
||||
JERRY_ASSERT( pObject->m_GCInfo.u.m_Refs == 0 );
|
||||
|
||||
pObject->m_GCInfo.m_IsObjectValid = false;
|
||||
ecma_SetPointer( pObject->m_GCInfo.u.m_NextQueuedForGC, ecma_GC_Queue);
|
||||
|
||||
ecma_GC_Queue = pObject;
|
||||
} /* ecma_QueueGC */
|
||||
|
||||
/**
|
||||
* Increase reference counter of an object
|
||||
*/
|
||||
void
|
||||
ecma_RefObject(ecma_Object_t *pObject) /**< object */
|
||||
{
|
||||
JERRY_ASSERT(pObject->m_GCInfo.m_IsObjectValid);
|
||||
|
||||
pObject->m_GCInfo.u.m_Refs++;
|
||||
|
||||
/**
|
||||
* Check that value was not overflowed
|
||||
*/
|
||||
JERRY_ASSERT(pObject->m_GCInfo.u.m_Refs > 0);
|
||||
} /* ecma_RefObject */
|
||||
|
||||
/**
|
||||
* Decrease reference counter of an object
|
||||
*/
|
||||
void
|
||||
ecma_DerefObject(ecma_Object_t *pObject) /**< object */
|
||||
{
|
||||
JERRY_ASSERT(pObject != NULL);
|
||||
JERRY_ASSERT(pObject->m_GCInfo.m_IsObjectValid);
|
||||
JERRY_ASSERT(pObject->m_GCInfo.u.m_Refs > 0);
|
||||
|
||||
pObject->m_GCInfo.u.m_Refs--;
|
||||
|
||||
if ( pObject->m_GCInfo.u.m_Refs == 0 )
|
||||
{
|
||||
ecma_GCQueue( pObject);
|
||||
}
|
||||
} /* ecma_DerefObject */
|
||||
|
||||
/**
|
||||
* Initialize garbage collector
|
||||
*/
|
||||
void
|
||||
ecma_GCInit( void)
|
||||
{
|
||||
ecma_GC_Queue = NULL;
|
||||
} /* ecma_GCInit */
|
||||
|
||||
/**
|
||||
* Garbage collect described value
|
||||
*/
|
||||
static void
|
||||
ecma_GCValue( ecma_Value_t valueDescription) /**< value description */
|
||||
{
|
||||
switch ( (ecma_Type_t) valueDescription.m_ValueType )
|
||||
{
|
||||
case ECMA_TYPE_SIMPLE:
|
||||
{
|
||||
/* doesn't hold additional memory */
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_TYPE_NUMBER:
|
||||
{
|
||||
ecma_Number_t *pNumber = ecma_GetPointer( valueDescription.m_Value);
|
||||
ecma_FreeNumber( pNumber);
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_ArrayFirstChunk_t *pString = ecma_GetPointer( valueDescription.m_Value);
|
||||
ecma_FreeArray( pString);
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_TYPE_OBJECT:
|
||||
{
|
||||
ecma_DerefObject( ecma_GetPointer( valueDescription.m_Value));
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_TYPE__COUNT:
|
||||
{
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
} /* ecma_GCValue */
|
||||
|
||||
/**
|
||||
* Garbage collect a named data property
|
||||
*/
|
||||
static void
|
||||
ecma_GCNamedDataProperty( ecma_Property_t *pProperty) /**< the property */
|
||||
{
|
||||
JERRY_ASSERT( pProperty->m_Type == ECMA_PROPERTY_NAMEDDATA );
|
||||
|
||||
ecma_FreeArray( ecma_GetPointer( pProperty->u.m_NamedDataProperty.m_pName));
|
||||
ecma_GCValue( pProperty->u.m_NamedDataProperty.m_Value);
|
||||
} /* ecma_GCNamedDataProperty */
|
||||
|
||||
/**
|
||||
* Garbage collect a named accessor property
|
||||
*/
|
||||
static void
|
||||
ecma_GCNamedAccessorProperty( ecma_Property_t *pProperty) /**< the property */
|
||||
{
|
||||
JERRY_ASSERT( pProperty->m_Type == ECMA_PROPERTY_NAMEDACCESSOR );
|
||||
|
||||
ecma_FreeArray( ecma_GetPointer( pProperty->u.m_NamedAccessorProperty.m_pName));
|
||||
|
||||
ecma_Object_t *pGet = ecma_GetPointer(pProperty->u.m_NamedAccessorProperty.m_pGet);
|
||||
ecma_Object_t *pSet = ecma_GetPointer(pProperty->u.m_NamedAccessorProperty.m_pSet);
|
||||
|
||||
if ( pGet != NULL )
|
||||
{
|
||||
ecma_DerefObject( pGet);
|
||||
}
|
||||
|
||||
if ( pSet != NULL )
|
||||
{
|
||||
ecma_DerefObject( pSet);
|
||||
}
|
||||
} /* ecma_GCNamedAccessorProperty */
|
||||
|
||||
/**
|
||||
* Garbage collect an internal property
|
||||
*/
|
||||
static void
|
||||
ecma_GCInternalProperty( ecma_Property_t *pProperty) /**< the property */
|
||||
{
|
||||
JERRY_ASSERT( pProperty->m_Type == ECMA_PROPERTY_INTERNAL );
|
||||
|
||||
ecma_InternalPropertyId_t propertyId = pProperty->u.m_InternalProperty.m_InternalPropertyType;
|
||||
uint32_t propertyValue = pProperty->u.m_InternalProperty.m_Value;
|
||||
|
||||
switch ( propertyId )
|
||||
{
|
||||
case ECMA_INTERNAL_PROPERTY_CLASS: /* a string */
|
||||
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */
|
||||
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */
|
||||
{
|
||||
ecma_FreeArray( ecma_GetPointer( propertyValue));
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
|
||||
case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */
|
||||
{
|
||||
ecma_DerefObject( ecma_GetPointer( propertyValue));
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_Object_t */
|
||||
case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_Object_t */
|
||||
case ECMA_INTERNAL_PROPERTY_PROVIDE_THIS: /* a boolean flag */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* ecma_GCInternalProperty */
|
||||
|
||||
/**
|
||||
* Run garbage collecting
|
||||
*/
|
||||
void
|
||||
ecma_GCRun( void)
|
||||
{
|
||||
while ( ecma_GC_Queue != NULL )
|
||||
{
|
||||
ecma_Object_t *pObject = ecma_GC_Queue;
|
||||
ecma_GC_Queue = ecma_GetPointer( pObject->m_GCInfo.u.m_NextQueuedForGC);
|
||||
|
||||
JERRY_ASSERT( !pObject->m_GCInfo.m_IsObjectValid );
|
||||
|
||||
for ( ecma_Property_t *property = ecma_GetPointer( pObject->m_pProperties), *pNextProperty;
|
||||
property != NULL;
|
||||
property = pNextProperty )
|
||||
{
|
||||
switch ( (ecma_PropertyType_t) property->m_Type )
|
||||
{
|
||||
case ECMA_PROPERTY_NAMEDDATA:
|
||||
{
|
||||
ecma_GCNamedDataProperty( property);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_PROPERTY_NAMEDACCESSOR:
|
||||
{
|
||||
ecma_GCNamedAccessorProperty( property);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_PROPERTY_INTERNAL:
|
||||
{
|
||||
ecma_GCInternalProperty( property);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pNextProperty = ecma_GetPointer( property->m_pNextProperty);
|
||||
ecma_FreeProperty( property);
|
||||
}
|
||||
|
||||
if ( pObject->m_IsLexicalEnvironment )
|
||||
{
|
||||
ecma_Object_t *pOuterLexicalEnvironment = ecma_GetPointer( pObject->u_Attributes.m_LexicalEnvironment.m_pOuterReference);
|
||||
|
||||
if ( pOuterLexicalEnvironment != NULL )
|
||||
{
|
||||
ecma_DerefObject( pOuterLexicalEnvironment);
|
||||
}
|
||||
} else
|
||||
{
|
||||
ecma_Object_t *pPrototypeObject = ecma_GetPointer( pObject->u_Attributes.m_Object.m_pPrototypeObject);
|
||||
|
||||
if ( pPrototypeObject != NULL )
|
||||
{
|
||||
ecma_DerefObject( pPrototypeObject);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_FreeObject( pObject);
|
||||
}
|
||||
} /* ecma_RunGC */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,42 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmagc Garbage collector
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef ECMA_GC_H
|
||||
#define ECMA_GC_H
|
||||
|
||||
/**
|
||||
* Garbage collector interface
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
extern void ecma_GCInit( void);
|
||||
extern void ecma_RefObject(ecma_Object_t *pObject);
|
||||
extern void ecma_DerefObject(ecma_Object_t *pObject);
|
||||
extern void ecma_GCRun( void);
|
||||
|
||||
#endif /* !ECMA_GC_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,317 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmatypes ECMA types
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ECMA_GLOBALS_H
|
||||
#define JERRY_ECMA_GLOBALS_H
|
||||
|
||||
#include "globals.h"
|
||||
#include "mem-allocator.h"
|
||||
|
||||
/** \addtogroup compressedpointer Compressed pointer
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ecma-pointer field is used to calculate ecma-value's address.
|
||||
*
|
||||
* Ecma-pointer contains value's shifted offset from common Ecma-pointers' base.
|
||||
* The offset is shifted right by MEM_ALIGNMENT_LOG.
|
||||
* Least significant MEM_ALIGNMENT_LOG bits of non-shifted offset are zeroes.
|
||||
*/
|
||||
#define ECMA_POINTER_FIELD_WIDTH 14
|
||||
|
||||
/**
|
||||
* The null value for compressed pointers
|
||||
*/
|
||||
#define ECMA_NULL_POINTER 0
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Type of ecma-value
|
||||
*/
|
||||
typedef enum {
|
||||
ECMA_TYPE_SIMPLE, /**< simple value */
|
||||
ECMA_TYPE_NUMBER, /**< 64-bit integer */
|
||||
ECMA_TYPE_STRING, /**< pointer to description of a string */
|
||||
ECMA_TYPE_OBJECT, /**< pointer to description of an object */
|
||||
ECMA_TYPE__COUNT /**< count of types */
|
||||
} ecma_Type_t;
|
||||
|
||||
/**
|
||||
* Simple ecma-values
|
||||
*/
|
||||
typedef enum {
|
||||
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
|
||||
ECMA_SIMPLE_VALUE_NULL, /**< null value */
|
||||
ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */
|
||||
ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */
|
||||
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */
|
||||
} ecma_SimpleValue_t;
|
||||
|
||||
/**
|
||||
* Type of ecma-property
|
||||
*/
|
||||
typedef enum {
|
||||
ECMA_PROPERTY_NAMEDDATA, /**< named data property */
|
||||
ECMA_PROPERTY_NAMEDACCESSOR, /**< named accessor property */
|
||||
ECMA_PROPERTY_INTERNAL /**< internal property */
|
||||
} ecma_PropertyType_t;
|
||||
|
||||
/**
|
||||
* Description of an ecma-value
|
||||
*/
|
||||
typedef struct {
|
||||
/** Value type (ecma_Type_t) */
|
||||
uint32_t m_ValueType : 2;
|
||||
|
||||
/**
|
||||
* Simple value (ecma_SimpleValue_t) or compressed pointer to value (depending on m_ValueType)
|
||||
*/
|
||||
uint32_t m_Value : ECMA_POINTER_FIELD_WIDTH;
|
||||
} __packed ecma_Value_t;
|
||||
|
||||
/**
|
||||
* Internal properties' identifiers.
|
||||
*/
|
||||
typedef enum {
|
||||
ECMA_INTERNAL_PROPERTY_CLASS, /**< [[Class]] */
|
||||
ECMA_INTERNAL_PROPERTY_PROTOTYPE, /**< [[Prototype]] */
|
||||
ECMA_INTERNAL_PROPERTY_EXTENSIBLE, /**< [[Extensible]] */
|
||||
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
|
||||
|
||||
/** provideThis property of lexical environment */
|
||||
ECMA_INTERNAL_PROPERTY_PROVIDE_THIS,
|
||||
|
||||
/** binding object of lexical environment */
|
||||
ECMA_INTERNAL_PROPERTY_BINDING_OBJECT,
|
||||
|
||||
/** Part of an array, that is indexed by numbers */
|
||||
ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES,
|
||||
|
||||
/** Part of an array, that is indexed by strings */
|
||||
ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES
|
||||
} ecma_InternalPropertyId_t;
|
||||
|
||||
/**
|
||||
* Description of ecma-property.
|
||||
*/
|
||||
typedef struct ecma_Property_t {
|
||||
/** Property's type (ecma_PropertyType_t) */
|
||||
uint32_t m_Type : 2;
|
||||
|
||||
/** Compressed pointer to next property */
|
||||
uint32_t m_pNextProperty : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Property's details (depending on m_Type) */
|
||||
union {
|
||||
|
||||
/** Description of named data property */
|
||||
struct __packed ecma_NamedDataProperty_t {
|
||||
/** Compressed pointer to property's name (pointer to String) */
|
||||
uint32_t m_pName : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Attribute 'Writable' */
|
||||
uint32_t m_Writable : 1;
|
||||
|
||||
/** Attribute 'Enumerable' */
|
||||
uint32_t m_Enumerable : 1;
|
||||
|
||||
/** Attribute 'Configurable' */
|
||||
uint32_t m_Configurable : 1;
|
||||
|
||||
/** Value */
|
||||
ecma_Value_t m_Value;
|
||||
} m_NamedDataProperty;
|
||||
|
||||
/** Description of named accessor property */
|
||||
struct __packed ecma_NamedAccessorProperty_t {
|
||||
/** Compressed pointer to property's name (pointer to String) */
|
||||
uint32_t m_pName : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Attribute 'Enumerable' */
|
||||
uint32_t m_Enumerable : 1;
|
||||
|
||||
/** Attribute 'Configurable' */
|
||||
uint32_t m_Configurable : 1;
|
||||
|
||||
/** Compressed pointer to property's getter */
|
||||
uint32_t m_pGet : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Compressed pointer to property's setter */
|
||||
uint32_t m_pSet : ECMA_POINTER_FIELD_WIDTH;
|
||||
} m_NamedAccessorProperty;
|
||||
|
||||
/** Description of internal property */
|
||||
struct __packed ecma_InternalProperty_t {
|
||||
/** Internal property's type */
|
||||
uint32_t m_InternalPropertyType : 4;
|
||||
|
||||
/** Value (may be a compressed pointer) */
|
||||
uint32_t m_Value : ECMA_POINTER_FIELD_WIDTH;
|
||||
} m_InternalProperty;
|
||||
} u;
|
||||
} ecma_Property_t;
|
||||
|
||||
/**
|
||||
* Description of GC's information layout
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* Flag that indicates if the object is valid for normal usage.
|
||||
* If the flag is zero, then the object is not valid and is queued for GC.
|
||||
*/
|
||||
uint32_t m_IsObjectValid : 1;
|
||||
|
||||
/** Details (depending on m_IsObjectValid) */
|
||||
union {
|
||||
/**
|
||||
* Number of refs to the object (if m_IsObjectValid).
|
||||
*
|
||||
* Note: It is not a pointer. Maximum value of reference counter
|
||||
* willn't be bigger than overall count of variables/objects/properties,
|
||||
* which is limited by size of address space allocated for JerryScript
|
||||
* (and, consequently, by ECMA_POINTER_FIELD_WIDTH).
|
||||
*/
|
||||
uint32_t m_Refs : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Compressed pointer to next object in the list of objects, queued for GC (if !m_IsObjectValid) */
|
||||
uint32_t m_NextQueuedForGC : ECMA_POINTER_FIELD_WIDTH;
|
||||
} __packed u;
|
||||
} ecma_GCInfo_t;
|
||||
|
||||
/**
|
||||
* Types of lexical environments
|
||||
*/
|
||||
typedef enum {
|
||||
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< declarative lexical environment */
|
||||
ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND /**< object-bound lexical environment */
|
||||
} ecma_LexicalEnvironmentType_t;
|
||||
|
||||
/**
|
||||
* Description of ECMA-object or lexical environment
|
||||
* (depending on m_IsLexicalEnvironment).
|
||||
*/
|
||||
typedef struct ecma_Object_t {
|
||||
/** Compressed pointer to property list */
|
||||
uint32_t m_pProperties : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** Flag indicating whether it is a general object (false)
|
||||
or a lexical environment (true) */
|
||||
uint32_t m_IsLexicalEnvironment : 1;
|
||||
|
||||
/**
|
||||
* Attributes of either general object or lexical environment
|
||||
* (depending on m_IsLexicalEnvironment)
|
||||
*/
|
||||
union {
|
||||
/**
|
||||
* A general object's attributes (if !m_IsLexicalEnvironment)
|
||||
*/
|
||||
struct {
|
||||
/** Attribute 'Extensible' */
|
||||
uint32_t m_Extensible : 1;
|
||||
|
||||
/** Compressed pointer to prototype object (ecma_Object_t) */
|
||||
uint32_t m_pPrototypeObject : ECMA_POINTER_FIELD_WIDTH;
|
||||
} __packed m_Object;
|
||||
|
||||
/**
|
||||
* A lexical environment's attribute (if m_IsLexicalEnvironment)
|
||||
*/
|
||||
struct {
|
||||
/**
|
||||
* Type of lexical environment (ecma_LexicalEnvironmentType_t).
|
||||
*/
|
||||
uint32_t m_Type : 1;
|
||||
|
||||
/** Compressed pointer to outer lexical environment */
|
||||
uint32_t m_pOuterReference : ECMA_POINTER_FIELD_WIDTH;
|
||||
} __packed m_LexicalEnvironment;
|
||||
|
||||
} __packed u_Attributes;
|
||||
|
||||
/** GC's information */
|
||||
ecma_GCInfo_t m_GCInfo;
|
||||
} ecma_Object_t;
|
||||
|
||||
/**
|
||||
* Description of an ecma-character
|
||||
*/
|
||||
typedef uint16_t ecma_Char_t;
|
||||
|
||||
/**
|
||||
* Description of an ecma-number
|
||||
*/
|
||||
typedef double ecma_Number_t;
|
||||
|
||||
/**
|
||||
* Description of arrays'/strings' length
|
||||
*/
|
||||
typedef uint16_t ecma_Length_t;
|
||||
|
||||
/**
|
||||
* Description of an Array's header
|
||||
*/
|
||||
typedef struct {
|
||||
/** Compressed pointer to next chunk */
|
||||
uint16_t m_pNextChunk;
|
||||
|
||||
/** Number of elements in the Array */
|
||||
uint16_t m_UnitNumber;
|
||||
} ecma_ArrayHeader_t;
|
||||
|
||||
/**
|
||||
* Size of a chunk, containing a String's part, in bytes
|
||||
*/
|
||||
#define ECMA_ARRAY_CHUNK_SIZE_IN_BYTES 32
|
||||
|
||||
/**
|
||||
* Description of first chunk in a chain of chunks that contains an Array.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Array's header */
|
||||
ecma_ArrayHeader_t m_Header;
|
||||
|
||||
/** Elements */
|
||||
uint8_t m_Elements[ ECMA_ARRAY_CHUNK_SIZE_IN_BYTES - sizeof (ecma_ArrayHeader_t) ];
|
||||
} ecma_ArrayFirstChunk_t;
|
||||
|
||||
/**
|
||||
* Description of non-first chunk in a chain of chunks that contains an Array
|
||||
*/
|
||||
typedef struct {
|
||||
/** Compressed pointer to next chunk */
|
||||
uint16_t m_pNextChunk;
|
||||
|
||||
/** Characters */
|
||||
uint8_t m_Elements[ ECMA_ARRAY_CHUNK_SIZE_IN_BYTES - sizeof (uint16_t) ];
|
||||
} ecma_ArrayNonFirstChunk_t;
|
||||
|
||||
#endif /* JERRY_ECMA_GLOBALS_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,376 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of helpers for operations with ECMA data types
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
/**
|
||||
* Compress pointer.
|
||||
*/
|
||||
uintptr_t
|
||||
ecma_CompressPointer(void *pointer) /**< pointer to compress */
|
||||
{
|
||||
if ( pointer == NULL )
|
||||
{
|
||||
return ECMA_NULL_POINTER;
|
||||
}
|
||||
|
||||
uintptr_t intPtr = (uintptr_t) pointer;
|
||||
|
||||
JERRY_ASSERT(intPtr % MEM_ALIGNMENT == 0);
|
||||
|
||||
intPtr -= mem_GetBasePointer();
|
||||
intPtr >>= MEM_ALIGNMENT_LOG;
|
||||
|
||||
JERRY_ASSERT((intPtr & ~((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) == 0);
|
||||
|
||||
return intPtr;
|
||||
} /* ecma_CompressPointer */
|
||||
|
||||
/**
|
||||
* Decompress pointer.
|
||||
*/
|
||||
void*
|
||||
ecma_DecompressPointer(uintptr_t compressedPointer) /**< pointer to decompress */
|
||||
{
|
||||
if ( compressedPointer == ECMA_NULL_POINTER )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uintptr_t intPtr = compressedPointer;
|
||||
|
||||
intPtr <<= MEM_ALIGNMENT_LOG;
|
||||
intPtr += mem_GetBasePointer();
|
||||
|
||||
return (void*) intPtr;
|
||||
} /* ecma_DecompressPointer */
|
||||
|
||||
/**
|
||||
* Create an object with specified prototype object
|
||||
* (or NULL prototype if there is not prototype for the object)
|
||||
* and value of 'Extensible' attribute.
|
||||
*
|
||||
* Reference counter's value will be set to one.
|
||||
*
|
||||
* @return pointer to the object's descriptor
|
||||
*/
|
||||
ecma_Object_t*
|
||||
ecma_CreateObject( ecma_Object_t *pPrototypeObject, /**< pointer to prototybe of the object (or NULL) */
|
||||
bool isExtensible) /**< value of extensible attribute */
|
||||
{
|
||||
ecma_Object_t *pObject = ecma_AllocObject();
|
||||
|
||||
pObject->m_pProperties = ECMA_NULL_POINTER;
|
||||
pObject->m_IsLexicalEnvironment = false;
|
||||
pObject->m_GCInfo.m_IsObjectValid = true;
|
||||
|
||||
/* The global object is always referenced
|
||||
* (at least with the ctx_GlobalObject variable) */
|
||||
pObject->m_GCInfo.u.m_Refs = 1;
|
||||
|
||||
pObject->u_Attributes.m_Object.m_Extensible = isExtensible;
|
||||
ecma_SetPointer( pObject->u_Attributes.m_Object.m_pPrototypeObject, pPrototypeObject);
|
||||
|
||||
return pObject;
|
||||
} /* ecma_CreateObject */
|
||||
|
||||
/**
|
||||
* Create a lexical environment with specified outer lexical environment
|
||||
* (or NULL if the environment is not nested).
|
||||
*
|
||||
* Reference counter's value will be set to one.
|
||||
*
|
||||
* Warning: after object-bound lexical environment is created,
|
||||
* caller must create internal properties, that
|
||||
* specify the bound object and value of 'provideThis'.
|
||||
*
|
||||
* @return pointer to the descriptor of lexical environment
|
||||
*/
|
||||
ecma_Object_t*
|
||||
ecma_CreateLexicalEnvironment(ecma_Object_t *pOuterLexicalEnvironment, /**< outer lexical environment */
|
||||
ecma_LexicalEnvironmentType_t type) /**< type of lexical environment to create */
|
||||
{
|
||||
ecma_Object_t *pNewLexicalEnvironment = ecma_AllocObject();
|
||||
|
||||
pNewLexicalEnvironment->m_IsLexicalEnvironment = true;
|
||||
pNewLexicalEnvironment->u_Attributes.m_LexicalEnvironment.m_Type = type;
|
||||
|
||||
pNewLexicalEnvironment->m_pProperties = ECMA_NULL_POINTER;
|
||||
|
||||
pNewLexicalEnvironment->m_GCInfo.m_IsObjectValid = true;
|
||||
pNewLexicalEnvironment->m_GCInfo.u.m_Refs = 1;
|
||||
|
||||
ecma_SetPointer( pNewLexicalEnvironment->u_Attributes.m_LexicalEnvironment.m_pOuterReference, pOuterLexicalEnvironment);
|
||||
|
||||
return pNewLexicalEnvironment;
|
||||
} /* ecma_CreateLexicalEnvironment */
|
||||
|
||||
/**
|
||||
* Create internal property in an object and link it
|
||||
* into the object's properties' linked-list
|
||||
*
|
||||
* @return pointer to newly created property's des
|
||||
*/
|
||||
ecma_Property_t*
|
||||
ecma_CreateInternalProperty(ecma_Object_t *pObject, /**< the object */
|
||||
ecma_InternalPropertyId_t propertyId) /**< internal property identifier */
|
||||
{
|
||||
ecma_Property_t *pNewProperty = ecma_AllocProperty();
|
||||
|
||||
pNewProperty->m_Type = ECMA_PROPERTY_INTERNAL;
|
||||
|
||||
ecma_SetPointer( pNewProperty->m_pNextProperty, ecma_GetPointer( pObject->m_pProperties));
|
||||
ecma_SetPointer( pObject->m_pProperties, pNewProperty);
|
||||
|
||||
pNewProperty->u.m_InternalProperty.m_InternalPropertyType = propertyId;
|
||||
pNewProperty->u.m_InternalProperty.m_Value = ECMA_NULL_POINTER;
|
||||
|
||||
return pNewProperty;
|
||||
} /* ecma_CreateInternalProperty */
|
||||
|
||||
/**
|
||||
* Find internal property in the object's property set.
|
||||
*
|
||||
* @return pointer to the property's descriptor, if it is found,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_Property_t*
|
||||
ecma_FindInternalProperty(ecma_Object_t *pObject, /**< object descriptor */
|
||||
ecma_InternalPropertyId_t propertyId) /**< internal property identifier */
|
||||
{
|
||||
JERRY_ASSERT( pObject != NULL );
|
||||
|
||||
JERRY_ASSERT( propertyId != ECMA_INTERNAL_PROPERTY_PROTOTYPE
|
||||
&& propertyId != ECMA_INTERNAL_PROPERTY_EXTENSIBLE );
|
||||
|
||||
for ( ecma_Property_t *pProperty = ecma_GetPointer( pObject->m_pProperties);
|
||||
pProperty != NULL;
|
||||
pProperty = ecma_GetPointer( pProperty->m_pNextProperty) )
|
||||
{
|
||||
if ( pProperty->m_Type == ECMA_PROPERTY_INTERNAL )
|
||||
{
|
||||
if ( pProperty->u.m_InternalProperty.m_InternalPropertyType == propertyId )
|
||||
{
|
||||
return pProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} /* ecma_FindInternalProperty */
|
||||
|
||||
/**
|
||||
* Get an internal property.
|
||||
*
|
||||
* Warning:
|
||||
* the property must exist
|
||||
*
|
||||
* @return pointer to the property
|
||||
*/
|
||||
ecma_Property_t*
|
||||
ecma_GetInternalProperty(ecma_Object_t *pObject, /**< object descriptor */
|
||||
ecma_InternalPropertyId_t propertyId) /**< internal property identifier */
|
||||
{
|
||||
ecma_Property_t *pProperty = ecma_FindInternalProperty( pObject, propertyId);
|
||||
|
||||
JERRY_ASSERT( pProperty != NULL );
|
||||
|
||||
return pProperty;
|
||||
} /* ecma_GetInternalProperty */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with characters from specified buffer
|
||||
*
|
||||
* @return Pointer to first chunk of an array, containing allocated string
|
||||
*/
|
||||
ecma_ArrayFirstChunk_t*
|
||||
ecma_NewEcmaString(const ecma_Char_t *pString, /**< buffer of characters */
|
||||
ecma_Length_t length) /**< length of string, in characters */
|
||||
{
|
||||
JERRY_ASSERT( length == 0 || pString != NULL );
|
||||
|
||||
ecma_ArrayFirstChunk_t *pStringFirstChunk = ecma_AllocArrayFirstChunk();
|
||||
|
||||
pStringFirstChunk->m_Header.m_UnitNumber = length;
|
||||
uint8_t *copyPointer = (uint8_t*) pString;
|
||||
size_t charsLeft = length;
|
||||
size_t charsToCopy = JERRY_MIN( length, sizeof (pStringFirstChunk->m_Elements) / sizeof (ecma_Char_t));
|
||||
libc_memcpy(pStringFirstChunk->m_Elements, copyPointer, charsToCopy * sizeof (ecma_Char_t));
|
||||
charsLeft -= charsToCopy;
|
||||
copyPointer += charsToCopy * sizeof (ecma_Char_t);
|
||||
|
||||
ecma_ArrayNonFirstChunk_t *pStringNonFirstChunk;
|
||||
uint16_t *pNextChunkCompressedPointer = &pStringFirstChunk->m_Header.m_pNextChunk;
|
||||
|
||||
while ( charsLeft > 0 )
|
||||
{
|
||||
pStringNonFirstChunk = ecma_AllocArrayNonFirstChunk();
|
||||
|
||||
size_t charsToCopy = JERRY_MIN( charsLeft, sizeof (pStringNonFirstChunk->m_Elements) / sizeof (ecma_Char_t));
|
||||
libc_memcpy(pStringNonFirstChunk->m_Elements, copyPointer, charsToCopy * sizeof (ecma_Char_t));
|
||||
charsLeft -= charsToCopy;
|
||||
copyPointer += charsToCopy * sizeof (ecma_Char_t);
|
||||
|
||||
ecma_SetPointer( *pNextChunkCompressedPointer, pStringNonFirstChunk);
|
||||
pNextChunkCompressedPointer = &pStringNonFirstChunk->m_pNextChunk;
|
||||
}
|
||||
|
||||
*pNextChunkCompressedPointer = ECMA_NULL_POINTER;
|
||||
|
||||
return pStringFirstChunk;
|
||||
} /* ecma_NewEcmaString */
|
||||
|
||||
/**
|
||||
* Copy ecma-string's contents to a buffer.
|
||||
*
|
||||
* Buffer will contain length of string, in characters, followed by string's characters.
|
||||
*
|
||||
* @return number of bytes, actually copied to the buffer, if string's content was copied successfully;
|
||||
* negative number, which is calculated as negation of buffer size, that is required
|
||||
* to hold the string's cpntent (in case size of buffer is insuficcient).
|
||||
*/
|
||||
ssize_t
|
||||
ecma_CopyEcmaStringCharsToBuffer(ecma_ArrayFirstChunk_t *pFirstChunk, /**< first chunk of ecma-string */
|
||||
uint8_t *pBuffer, /**< destination buffer */
|
||||
size_t bufferSize) /**< size of buffer */
|
||||
{
|
||||
ecma_Length_t stringLength = pFirstChunk->m_Header.m_UnitNumber;
|
||||
size_t requiredBufferSize = sizeof (ecma_Length_t) + sizeof (ecma_Char_t) * stringLength;
|
||||
|
||||
if ( requiredBufferSize < bufferSize )
|
||||
{
|
||||
return -(ssize_t) requiredBufferSize;
|
||||
}
|
||||
|
||||
*(ecma_Length_t*) pBuffer = stringLength;
|
||||
|
||||
size_t charsLeft = stringLength;
|
||||
uint8_t *destPointer = pBuffer + sizeof (ecma_Length_t);
|
||||
size_t copyChunkChars = JERRY_MIN(sizeof (pFirstChunk->m_Elements) / sizeof (ecma_Char_t),
|
||||
charsLeft);
|
||||
libc_memcpy( destPointer, pFirstChunk->m_Elements, copyChunkChars * sizeof (ecma_Char_t));
|
||||
destPointer += copyChunkChars * sizeof (ecma_Char_t);
|
||||
charsLeft -= copyChunkChars;
|
||||
|
||||
ecma_ArrayNonFirstChunk_t *pNonFirstChunk = ecma_GetPointer( pFirstChunk->m_Header.m_pNextChunk);
|
||||
|
||||
while ( charsLeft > 0 )
|
||||
{
|
||||
JERRY_ASSERT( charsLeft < stringLength );
|
||||
|
||||
copyChunkChars = JERRY_MIN(sizeof (pNonFirstChunk->m_Elements) / sizeof (ecma_Char_t),
|
||||
charsLeft);
|
||||
libc_memcpy( destPointer, pNonFirstChunk->m_Elements, copyChunkChars * sizeof (ecma_Char_t));
|
||||
destPointer += copyChunkChars * sizeof (ecma_Char_t);
|
||||
charsLeft -= copyChunkChars;
|
||||
|
||||
pNonFirstChunk = ecma_GetPointer( pNonFirstChunk->m_pNextChunk);
|
||||
}
|
||||
|
||||
return (ssize_t) requiredBufferSize;
|
||||
} /* ecma_CopyEcmaStringCharsToBuffer */
|
||||
|
||||
/**
|
||||
* Duplicate an ecma-string.
|
||||
*
|
||||
* @return pointer to new ecma-string's first chunk
|
||||
*/
|
||||
ecma_ArrayFirstChunk_t*
|
||||
ecma_DuplicateEcmaString( ecma_ArrayFirstChunk_t *pFirstChunk) /**< first chunk of string to duplicate */
|
||||
{
|
||||
JERRY_ASSERT( pFirstChunk != NULL );
|
||||
|
||||
ecma_ArrayFirstChunk_t *pFirstChunkCopy = ecma_AllocArrayFirstChunk();
|
||||
libc_memcpy( pFirstChunkCopy, pFirstChunk, sizeof (ecma_ArrayFirstChunk_t));
|
||||
|
||||
ecma_ArrayNonFirstChunk_t *pNonFirstChunk, *pNonFirstChunkCopy;
|
||||
pNonFirstChunk = ecma_GetPointer( pFirstChunk->m_Header.m_pNextChunk);
|
||||
uint16_t *pNextPointer = &pFirstChunk->m_Header.m_pNextChunk;
|
||||
|
||||
while ( pNonFirstChunk != NULL )
|
||||
{
|
||||
pNonFirstChunkCopy = ecma_AllocArrayNonFirstChunk();
|
||||
ecma_SetPointer( *pNextPointer, pNonFirstChunkCopy);
|
||||
pNextPointer = &pNonFirstChunkCopy->m_pNextChunk;
|
||||
|
||||
libc_memcpy( pNonFirstChunkCopy, pNonFirstChunk, sizeof (ecma_ArrayNonFirstChunk_t));
|
||||
|
||||
pNonFirstChunk = ecma_GetPointer( pNonFirstChunk->m_pNextChunk);
|
||||
}
|
||||
|
||||
*pNextPointer = ECMA_NULL_POINTER;
|
||||
|
||||
return pFirstChunkCopy;
|
||||
} /* ecma_DuplicateEcmaString */
|
||||
|
||||
/**
|
||||
* Compare null-terminated string to ecma-string
|
||||
*
|
||||
* @return true - if strings are equal;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_CompareCharBufferToEcmaString(ecma_Char_t *pString, /**< null-terminated string */
|
||||
ecma_ArrayFirstChunk_t *pEcmaString) /* ecma-string */
|
||||
{
|
||||
JERRY_ASSERT( pString != NULL );
|
||||
JERRY_ASSERT( pEcmaString != NULL );
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
*/
|
||||
JERRY_UNIMPLEMENTED();
|
||||
} /* ecma_CompareCharBufferToEcmaString */
|
||||
|
||||
/**
|
||||
* Free all chunks of an array
|
||||
*/
|
||||
void
|
||||
ecma_FreeArray( ecma_ArrayFirstChunk_t *pFirstChunk) /**< first chunk of the array */
|
||||
{
|
||||
JERRY_ASSERT( pFirstChunk != NULL );
|
||||
|
||||
ecma_ArrayNonFirstChunk_t *pNonFirstChunk = ecma_GetPointer( pFirstChunk->m_Header.m_pNextChunk);
|
||||
|
||||
ecma_FreeArrayFirstChunk( pFirstChunk);
|
||||
|
||||
while ( pNonFirstChunk != NULL )
|
||||
{
|
||||
ecma_ArrayNonFirstChunk_t *pNextChunk = ecma_GetPointer( pNonFirstChunk->m_pNextChunk);
|
||||
|
||||
ecma_FreeArrayNonFirstChunk( pNonFirstChunk);
|
||||
|
||||
pNonFirstChunk = pNextChunk;
|
||||
}
|
||||
} /* ecma_FreeArray */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,64 @@
|
||||
/* 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 ecma ---TODO---
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef JERRY_ECMA_HELPERS_H
|
||||
#define JERRY_ECMA_HELPERS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
extern uintptr_t ecma_CompressPointer(void *pointer);
|
||||
extern void* ecma_DecompressPointer(uintptr_t compressedPointer);
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified compressed pointer field.
|
||||
*/
|
||||
#define ecma_GetPointer( field) \
|
||||
ecma_DecompressPointer( field)
|
||||
|
||||
/**
|
||||
* Set value of compressed pointer field so that it will correspond
|
||||
* to specified nonCompressedPointer.
|
||||
*/
|
||||
#define ecma_SetPointer( field, nonCompressedPointer) \
|
||||
(field) = ecma_CompressPointer( nonCompressedPointer) & ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1)
|
||||
|
||||
extern ecma_Object_t* ecma_CreateObject( ecma_Object_t *pPrototypeObject, bool isExtensible);
|
||||
extern ecma_Object_t* ecma_CreateLexicalEnvironment( ecma_Object_t *pOuterLexicalEnvironment, ecma_LexicalEnvironmentType_t type);
|
||||
|
||||
extern ecma_Property_t* ecma_CreateInternalProperty(ecma_Object_t *pObject, ecma_InternalPropertyId_t propertyId);
|
||||
extern ecma_Property_t* ecma_FindInternalProperty(ecma_Object_t *pObject, ecma_InternalPropertyId_t propertyId);
|
||||
extern ecma_Property_t* ecma_GetInternalProperty(ecma_Object_t *pObject, ecma_InternalPropertyId_t propertyId);
|
||||
extern ecma_Property_t* ecma_SetInternalProperty(ecma_Object_t *pObject, ecma_InternalPropertyId_t propertyId);
|
||||
|
||||
extern ecma_ArrayFirstChunk_t* ecma_NewEcmaString( const ecma_Char_t *pString, ecma_Length_t length);
|
||||
extern ssize_t ecma_CopyEcmaStringCharsToBuffer( ecma_ArrayFirstChunk_t *pFirstChunk, uint8_t *pBuffer, size_t bufferSize);
|
||||
extern ecma_ArrayFirstChunk_t* ecma_DuplicateEcmaString( ecma_ArrayFirstChunk_t *pFirstChunk);
|
||||
extern bool ecma_CompareCharBufferToEcmaString( ecma_Char_t *pString, ecma_ArrayFirstChunk_t *pEcmaString);
|
||||
|
||||
extern void ecma_FreeArray( ecma_ArrayFirstChunk_t *pFirstChunk);
|
||||
|
||||
#endif /* !JERRY_ECMA_HELPERS_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
Reference in New Issue
Block a user