mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
* Build numeral literal number in token only if needs * Build string literal for ast only if needs * Move NumeralData from ASTContext to ASTNode * Fix compile error on gcc 7+ Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
87 lines
3.5 KiB
C++
87 lines
3.5 KiB
C++
/*
|
|
* Copyright (c) 2017-present Samsung Electronics Co., Ltd
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
* USA
|
|
*/
|
|
|
|
#include "Escargot.h"
|
|
#include "Node.h"
|
|
#include "interpreter/ByteCode.h"
|
|
#include "interpreter/ByteCodeGenerator.h"
|
|
#include "runtime/ErrorObject.h"
|
|
|
|
namespace Escargot {
|
|
|
|
ByteCodeRegisterIndex Node::getRegister(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context)
|
|
{
|
|
return context->getRegister();
|
|
}
|
|
|
|
void Node::generateResultNotRequiredExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context)
|
|
{
|
|
#ifndef NDEBUG
|
|
size_t before = context->m_registerStack->size();
|
|
#endif
|
|
generateExpressionByteCode(codeBlock, context, getRegister(codeBlock, context));
|
|
context->giveUpRegister();
|
|
ASSERT(context->m_registerStack->size() == before);
|
|
}
|
|
|
|
void Node::generateStoreByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context, ByteCodeRegisterIndex srcRegister, bool needToReferenceSelf)
|
|
{
|
|
generateExpressionByteCode(codeBlock, context, context->getRegister());
|
|
context->giveUpRegister();
|
|
codeBlock->pushCode(ThrowStaticErrorOperation(ByteCodeLOC(m_loc.index), ErrorObject::ReferenceError, "Invalid assignment left-hand side"), context, this);
|
|
}
|
|
|
|
void Node::generateReferenceResolvedAddressByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context)
|
|
{
|
|
context->getRegister();
|
|
codeBlock->pushCode(ThrowStaticErrorOperation(ByteCodeLOC(m_loc.index), ErrorObject::ReferenceError, "Invalid assignment left-hand side"), context, this);
|
|
return;
|
|
}
|
|
|
|
void* ASTBlockScopeContext::operator new(size_t size)
|
|
{
|
|
static bool typeInited = false;
|
|
static GC_descr descr;
|
|
if (!typeInited) {
|
|
GC_word obj_bitmap[GC_BITMAP_SIZE(ASTBlockScopeContext)] = { 0 };
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTBlockScopeContext, m_names));
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTBlockScopeContext, m_usingNames));
|
|
descr = GC_make_descriptor(obj_bitmap, GC_WORD_LEN(ASTBlockScopeContext));
|
|
typeInited = true;
|
|
}
|
|
return GC_MALLOC_EXPLICITLY_TYPED(size, descr);
|
|
}
|
|
|
|
void* ASTFunctionScopeContext::operator new(size_t size)
|
|
{
|
|
static bool typeInited = false;
|
|
static GC_descr descr;
|
|
if (!typeInited) {
|
|
GC_word obj_bitmap[GC_BITMAP_SIZE(ASTFunctionScopeContext)] = { 0 };
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTFunctionScopeContext, m_varNames));
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTFunctionScopeContext, m_parameters));
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTFunctionScopeContext, m_firstChild));
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTFunctionScopeContext, m_nextSibling));
|
|
GC_set_bit(obj_bitmap, GC_WORD_OFFSET(ASTFunctionScopeContext, m_childBlockScopes));
|
|
descr = GC_make_descriptor(obj_bitmap, GC_WORD_LEN(ASTFunctionScopeContext));
|
|
typeInited = true;
|
|
}
|
|
return GC_MALLOC_EXPLICITLY_TYPED(size, descr);
|
|
}
|
|
}
|