diff --git a/Makefile.mk b/Makefile.mk index d6f2ce7ce..f2a73ce08 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -257,10 +257,7 @@ GIT_HASH=$(shell git rev-parse HEAD) BUILD_DATE=$(shell date +'%d/%m/%Y') CFLAGS_JERRY = $(CFLAGS_WARNINGS) $(CFLAGS_WERROR) $(CFLAGS_WFATAL_ERRORS) -DEFINES_JERRY = -DMEM_HEAP_CHUNK_SIZE=$$((64)) -DMEM_HEAP_AREA_SIZE=$$((2 * 1024 + 512)) -DMEM_STATS \ - -DCONFIG_ECMA_REFERENCE_COUNTER_WIDTH=$$((10)) \ - -DCONFIG_MEM_STACK_LIMIT=$$((4 * 1024)) -DCONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE=$$((1024)) \ - -DCONFIG_ECMA_NUMBER_FLOAT32 +DEFINES_JERRY = -DMEM_STATS DEFINES_JERRY += -DJERRY_BUILD_DATE="\"$(BUILD_DATE)\"" \ -DJERRY_COMMIT_HASH="\"$(GIT_HASH)\"" \ diff --git a/src/config.h b/src/config.h new file mode 100644 index 000000000..fbfd0aeb0 --- /dev/null +++ b/src/config.h @@ -0,0 +1,88 @@ +/* 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 CONFIG_H +#define CONFIG_H + +/** + * Limit of data (system heap, engine's data except engine's own heap) + */ +#define CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE 1024 + +/** + * Limit of stack size + */ +#define CONFIG_MEM_STACK_LIMIT 4096 + +/** + * Log2 of maximum number of chunks in a pool + */ +#define CONFIG_MEM_POOL_MAX_CHUNKS_NUMBER_LOG 16 + +/** + * Size of pool chunk + * + * Should not be less than size of any of ECMA Object Model's data types. + */ +#define CONFIG_MEM_POOL_CHUNK_SIZE 16 + +/** + * Size of heap chunk + */ +#define CONFIG_MEM_HEAP_CHUNK_SIZE 64 + +/** + * Size of heap + */ +#define CONFIG_MEM_HEAP_AREA_SIZE (2 * 1024 + 512) + +/** + * Log2 of maximum possible offset in the heap + * + * The option affects size of compressed pointer that in turn + * affects size of ECMA Object Model's data types. + * + * In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE. + * + * On the other hand, value 2 ^ CONFIG_MEM_HEAP_OFFSET_LOG should not be less than CONFIG_MEM_HEAP_AREA_SIZE. + */ +#define CONFIG_MEM_HEAP_OFFSET_LOG 16 + +/** + * Width of fields used for holding counter of references to ecma-strings and ecma-objects + * + * The option affects maximum number of simultaneously existing: + * - references to one string; + * - stack references to one object + * The number is ((2 ^ CONFIG_ECMA_REFERENCE_COUNTER_WIDTH) - 1). + * + * Also the option affects size of ECMA Object Model's data types. + * In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE. + */ +#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH 10 + +/** + * Use 32-bit/64-bit float for ecma-numbers + */ +#define CONFIG_ECMA_NUMBER_FLOAT32 +// #define CONFIG_ECMA_NUMBER_FLOAT64 + +/** + * Use ASCII/UTF-16 representation for ecma-characters + */ +#define CONFIG_ECMA_CHAR_ASCII +// #define CONFIG_ECMA_CHAR_UTF16 + +#endif /* !CONFIG_H */ diff --git a/src/liballocator/mem-config.h b/src/liballocator/mem-config.h index cf93d7c60..b27c4253e 100644 --- a/src/liballocator/mem-config.h +++ b/src/liballocator/mem-config.h @@ -16,20 +16,32 @@ #ifndef MEM_CONFIG_H #define MEM_CONFIG_H +#include "config.h" + /** * Log2 of maximum possible offset in the heap */ -#define MEM_HEAP_OFFSET_LOG 16 +#define MEM_HEAP_OFFSET_LOG (CONFIG_MEM_HEAP_OFFSET_LOG) /** - * Size of one pool chunk + * Size of heap */ -#define MEM_POOL_CHUNK_SIZE 16 +#define MEM_HEAP_AREA_SIZE (CONFIG_MEM_HEAP_AREA_SIZE) + +/** + * Size of heap chunk + */ +#define MEM_HEAP_CHUNK_SIZE (CONFIG_MEM_HEAP_CHUNK_SIZE) + +/** + * Size of pool chunk + */ +#define MEM_POOL_CHUNK_SIZE (CONFIG_MEM_POOL_CHUNK_SIZE) /** * Log2 of maximum number of chunks in a pool */ -#define MEM_POOL_MAX_CHUNKS_NUMBER_LOG 16 +#define MEM_POOL_MAX_CHUNKS_NUMBER_LOG (CONFIG_MEM_POOL_MAX_CHUNKS_NUMBER_LOG) /** * Logarithm of required alignment for allocated units/blocks diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index ee9b29664..7a218d511 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -21,8 +21,9 @@ */ #ifndef JERRY_ECMA_GLOBALS_H -#define JERRY_ECMA_GLOBALS_H +#define JERRY_ECMA_GLOBALS_H +#include "config.h" #include "globals.h" #include "mem-allocator.h" @@ -442,15 +443,33 @@ typedef struct ecma_property_configurable_value_t configurable; } ecma_property_descriptor_t; +#ifdef CONFIG_ECMA_CHAR_ASCII /** * Description of an ecma-character */ typedef uint8_t ecma_char_t; +#elif defined (CONFIG_ECMA_CHAR_UTF16) +/** + * Description of an ecma-character + */ +typedef uint16_t ecma_char_t; +#else /* !CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16 */ +# error "!CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16" +#endif /* !CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16 */ +#ifdef CONFIG_ECMA_NUMBER_FLOAT32 /** * Description of an ecma-number */ typedef float ecma_number_t; +#elif defined (CONFIG_ECMA_NUMBER_FLOAT64) +/** + * Description of an ecma-number + */ +typedef double ecma_number_t; +#else /* !CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64 */ +#error "!CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64" +#endif /* !CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64 */ /** * Value '0' of ecma_number_t diff --git a/src/libecmaobjects/ecma-helpers-number.c b/src/libecmaobjects/ecma-helpers-number.c index c08dabdd1..0fe9f2855 100644 --- a/src/libecmaobjects/ecma-helpers-number.c +++ b/src/libecmaobjects/ecma-helpers-number.c @@ -284,7 +284,7 @@ ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */ /* IEEE-754 2008, 3.4, d */ exponent = 1 - ecma_number_exponent_bias; - while (!(fraction & (1u << ECMA_NUMBER_FRACTION_WIDTH))) + while (!(fraction & (1ul << ECMA_NUMBER_FRACTION_WIDTH))) { JERRY_ASSERT (fraction != 0); @@ -298,8 +298,8 @@ ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */ exponent = (int32_t) biased_exp - ecma_number_exponent_bias; JERRY_ASSERT (biased_exp > 0 && biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1); - JERRY_ASSERT ((fraction & (1u << ECMA_NUMBER_FRACTION_WIDTH)) == 0); - fraction |= 1u << ECMA_NUMBER_FRACTION_WIDTH; + JERRY_ASSERT ((fraction & (1ul << ECMA_NUMBER_FRACTION_WIDTH)) == 0); + fraction |= 1ul << ECMA_NUMBER_FRACTION_WIDTH; } *out_fraction_p = fraction;