From 97a2776996161eedeb06110cea0295e1e2597157 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:36:05 +0400 Subject: [PATCH 01/16] Deleting tests/jerry/*.exp. --- tests/jerry/blinky.exp | 25 -------------- tests/jerry/empty.exp | 0 tests/jerry/floating.exp | 49 ---------------------------- tests/jerry/functions-only.exp | 12 ------- tests/jerry/integer.exp | 8 ----- tests/jerry/keyword.exp | 54 ------------------------------- tests/jerry/multiline-comment.exp | 2 -- tests/jerry/nonstrict-eval.exp | 26 --------------- tests/jerry/nonstrict-with.exp | 10 ------ tests/jerry/punctuators.exp | 54 ------------------------------- tests/jerry/strict-with.exp | 5 --- tests/jerry/string.exp | 23 ------------- tests/jerry/symbols-only.exp | 22 ------------- 13 files changed, 290 deletions(-) delete mode 100644 tests/jerry/blinky.exp delete mode 100644 tests/jerry/empty.exp delete mode 100644 tests/jerry/floating.exp delete mode 100644 tests/jerry/functions-only.exp delete mode 100644 tests/jerry/integer.exp delete mode 100644 tests/jerry/keyword.exp delete mode 100644 tests/jerry/multiline-comment.exp delete mode 100644 tests/jerry/nonstrict-eval.exp delete mode 100644 tests/jerry/nonstrict-with.exp delete mode 100644 tests/jerry/punctuators.exp delete mode 100644 tests/jerry/strict-with.exp delete mode 100644 tests/jerry/string.exp delete mode 100644 tests/jerry/symbols-only.exp diff --git a/tests/jerry/blinky.exp b/tests/jerry/blinky.exp deleted file mode 100644 index 91f1189fe..000000000 --- a/tests/jerry/blinky.exp +++ /dev/null @@ -1,25 +0,0 @@ -require (leds); -function LEDsOn () { - LEDOn (LED3); - LEDOn (LED6); - LEDOn (LED7); - LEDOn (LED4); - LEDOn (LED10); - LEDOn (LED8); - LEDOn (LED9); - LEDOn (LED5); -} -function LEDsOff () { - LEDOff (LED3); - LEDOff (LED6); - LEDOff (LED7); - LEDOff (LED4); - LEDOff (LED10); - LEDOff (LED8); - LEDOff (LED9); - LEDOff (LED5); -} -while (true) { - setTimeout (LEDsOn, 500); - setTimeout (LEDsOff, 500); -} diff --git a/tests/jerry/empty.exp b/tests/jerry/empty.exp deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/jerry/floating.exp b/tests/jerry/floating.exp deleted file mode 100644 index 7f4c06ca5..000000000 --- a/tests/jerry/floating.exp +++ /dev/null @@ -1,49 +0,0 @@ -NEWLINE -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -FLOAT (0.000000) -NEWLINE -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (0.100000) -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (1.000000) -FLOAT (0.100000) -FLOAT (0.100000) -FLOAT (0.100000) -NEWLINE -FLOAT (123.456001) -FLOAT (123.000000) -FLOAT (0.456000) -FLOAT (inf) -FLOAT (inf) -FLOAT (0.000000) -FLOAT (inf) -FLOAT (inf) -FLOAT (0.000000) -FLOAT (inf) -FLOAT (inf) -FLOAT (0.000000) -NEWLINE -FLOAT (122999999650278146048.000000) -FLOAT (122999999650278146048.000000) -FLOAT (0.000000) -FLOAT (123455997908642430976.000000) -FLOAT (123455997908642430976.000000) -FLOAT (0.000000) -FLOAT (456000010710941696.000000) -FLOAT (456000010710941696.000000) -FLOAT (0.000000) diff --git a/tests/jerry/functions-only.exp b/tests/jerry/functions-only.exp deleted file mode 100644 index b9cd2ab8a..000000000 --- a/tests/jerry/functions-only.exp +++ /dev/null @@ -1,12 +0,0 @@ -(function () { - if ((this != null)) { - return this; - } - while (true) { - if ([][2]) return false; - } -} -)({}, function () { - return [true]; -} -); diff --git a/tests/jerry/integer.exp b/tests/jerry/integer.exp deleted file mode 100644 index 7ec58181b..000000000 --- a/tests/jerry/integer.exp +++ /dev/null @@ -1,8 +0,0 @@ -NEWLINE -INTEGER (0) -INTEGER (0) -INTEGER (0) -INTEGER (1223) -INTEGER (57005) -INTEGER (61453) -INTEGER (61453) diff --git a/tests/jerry/keyword.exp b/tests/jerry/keyword.exp deleted file mode 100644 index 8b3de6587..000000000 --- a/tests/jerry/keyword.exp +++ /dev/null @@ -1,54 +0,0 @@ -NEWLINE -KEYWORD (break) -KEYWORD (do) -KEYWORD (instanceof) -KEYWORD (typeof) -NEWLINE -KEYWORD (case) -KEYWORD (else) -KEYWORD (new) -KEYWORD (var) -NEWLINE -KEYWORD (catch) -KEYWORD (finally) -KEYWORD (return) -KEYWORD (void) -NEWLINE -KEYWORD (continue) -KEYWORD (for) -KEYWORD (switch) -KEYWORD (while) -NEWLINE -KEYWORD (debugger) -KEYWORD (function) -KEYWORD (this) -KEYWORD (with) -NEWLINE -KEYWORD (default) -KEYWORD (if) -KEYWORD (throw) -NEWLINE -KEYWORD (delete) -KEYWORD (in) -KEYWORD (try) -NEWLINE -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -NEWLINE -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -NEWLINE -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -NEWLINE -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -KEYWORD RESERVED -NEWLINE diff --git a/tests/jerry/multiline-comment.exp b/tests/jerry/multiline-comment.exp deleted file mode 100644 index e4c826873..000000000 --- a/tests/jerry/multiline-comment.exp +++ /dev/null @@ -1,2 +0,0 @@ -NEWLINE -NEWLINE diff --git a/tests/jerry/nonstrict-eval.exp b/tests/jerry/nonstrict-eval.exp deleted file mode 100644 index 6b596fbb1..000000000 --- a/tests/jerry/nonstrict-eval.exp +++ /dev/null @@ -1,26 +0,0 @@ -var eval = 42; -eval = eval++; -eval += (--eval); -eval -= (++eval); -eval *= eval--; -function eval (eval) { -}; -try { -} -catch (eval) { -} -function strict () { - "use strict"; - eval (arguments); -} -var eval = 42; -eval = eval++; -eval += (--eval); -eval -= (++eval); -eval *= eval--; -function eval (eval) { -}; -try { -} -catch (eval) { -} diff --git a/tests/jerry/nonstrict-with.exp b/tests/jerry/nonstrict-with.exp deleted file mode 100644 index 6edf3813c..000000000 --- a/tests/jerry/nonstrict-with.exp +++ /dev/null @@ -1,10 +0,0 @@ -with ({}) { -} -with ({x : 42}) { - var foo = function () { - "use strict"; - return x; - }; -} -with ({}) { -} diff --git a/tests/jerry/punctuators.exp b/tests/jerry/punctuators.exp deleted file mode 100644 index d520173bc..000000000 --- a/tests/jerry/punctuators.exp +++ /dev/null @@ -1,54 +0,0 @@ -NEWLINE -PUNC ({) -PUNC (}) -PUNC (() -PUNC ()) -PUNC ([) -PUNC (]) -NEWLINE -PUNC (.) -PUNC (;) -PUNC (,) -PUNC (<) -PUNC (>) -PUNC (<=) -NEWLINE -PUNC (>=) -PUNC (==) -PUNC (!=) -PUNC (===) -PUNC (!==) -NEWLINE -PUNC (+) -PUNC (-) -PUNC (*) -PUNC (%) -PUNC (++) -PUNC (--) -NEWLINE -PUNC (<<) -PUNC (>>) -PUNC (>>>) -PUNC (&) -PUNC (|) -PUNC (^) -NEWLINE -PUNC (!) -PUNC (~) -PUNC (&&) -PUNC (||) -PUNC (?) -PUNC (:) -NEWLINE -PUNC (=) -PUNC (+=) -PUNC (-=) -PUNC (*=) -PUNC (%=) -PUNC (<<=) -NEWLINE -PUNC (>>=) -PUNC (>>>=) -PUNC (&=) -PUNC (|=) -PUNC (^=) diff --git a/tests/jerry/strict-with.exp b/tests/jerry/strict-with.exp deleted file mode 100644 index 73f52f6e5..000000000 --- a/tests/jerry/strict-with.exp +++ /dev/null @@ -1,5 +0,0 @@ -function foo () { - "use strict"; - with ({}) { - } -} diff --git a/tests/jerry/string.exp b/tests/jerry/string.exp deleted file mode 100644 index f45c08722..000000000 --- a/tests/jerry/string.exp +++ /dev/null @@ -1,23 +0,0 @@ -NEWLINE -STRING () -NEWLINE -STRING () -NEWLINE -STRING (a) -NEWLINE -STRING (aaa) -NEWLINE -STRING (a -a) -NEWLINE -STRING (") -NEWLINE -STRING (') -NEWLINE -STRING (') -NEWLINE -STRING (') -NEWLINE -STRING (") -NEWLINE -STRING (") diff --git a/tests/jerry/symbols-only.exp b/tests/jerry/symbols-only.exp deleted file mode 100644 index 188b998d3..000000000 --- a/tests/jerry/symbols-only.exp +++ /dev/null @@ -1,22 +0,0 @@ -var x = 42; -var y = "hello world"; -if ((x == y)) { - with ({x : 10, y : "20", z : 42}) { - print (z); - } -} -try { - x = 2; - throw y; - y = 4; -} -catch (e) { - y = e; -} -finally { - x = y; -} -for (var i = 0; (i < 10); i++) { - x += x; -} -print (y); From bc83f77abe5f0e98876fd21a16a24e0f1e231f05 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:39:22 +0400 Subject: [PATCH 02/16] Fixing warnings and removing call to vprintf in src/libruntime/target/stm32f4/*. --- src/libruntime/target/stm32f4/jerry-assert.c | 6 +++--- src/libruntime/target/stm32f4/jerry-libc.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libruntime/target/stm32f4/jerry-assert.c b/src/libruntime/target/stm32f4/jerry-assert.c index abe859184..88e0a218d 100644 --- a/src/libruntime/target/stm32f4/jerry-assert.c +++ b/src/libruntime/target/stm32f4/jerry-assert.c @@ -20,9 +20,9 @@ * Handle failed assertion */ void __noreturn -jerry_AssertFail(const char *assertion, /**< assertion condition string */ - const char *file, /**< file name */ - const uint32_t line) /** line */ +jerry_AssertFail(const char *assertion __unused, /**< assertion condition string */ + const char *file __unused, /**< file name */ + const uint32_t line __unused) /** line */ { __exit( -ERR_GENERAL); } /* jerry_AssertFail */ diff --git a/src/libruntime/target/stm32f4/jerry-libc.c b/src/libruntime/target/stm32f4/jerry-libc.c index e83e31417..7d0faed61 100644 --- a/src/libruntime/target/stm32f4/jerry-libc.c +++ b/src/libruntime/target/stm32f4/jerry-libc.c @@ -36,8 +36,13 @@ __printf(const char *format, /**< format string */ va_start( args, format); - int ret = vprintf( format, args); - + /** + * TODO: Call internal vprintf implementation when it appears. + */ + int ret = 0; + + JERRY_UNIMPLEMENTED(); + va_end( args); return ret; @@ -52,7 +57,7 @@ __putchar (int c) /** exit - cause normal process termination */ void __noreturn -__exit (int status) +__exit (int status __unused) { /** * TODO: Blink LEDs? status -> binary -> LEDs? From 30b1a43e1ed363992d6d3621af05e13032029375 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:43:07 +0400 Subject: [PATCH 03/16] Adding memcpy, memset (for compiler usage). --- src/libruntime/jerry-libc.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libruntime/jerry-libc.c b/src/libruntime/jerry-libc.c index 765e2c926..d836efee0 100644 --- a/src/libruntime/jerry-libc.c +++ b/src/libruntime/jerry-libc.c @@ -19,6 +19,36 @@ #include "jerry-libc.h" +/** + * memcpy alias to __memcpy (for compiler usage) + */ +extern void *memcpy(void *s1, const void*s2, size_t n); + +/** + * memset alias to __memset (for compiler usage) + */ +extern void *memset(void *s, int c, size_t n); + +/** + * memcpy alias to __memcpy (for compiler usage) + */ +void* memcpy(void *s1, /**< destination */ + const void* s2, /**< source */ + size_t n) /**< bytes number */ +{ + return __memcpy(s1, s2, n); +} /* memcpy */ + +/** + * memset alias to __memset (for compiler usage) + */ +void* memset(void *s, /**< area to set values in */ + int c, /**< value to set */ + size_t n) /**< area size */ +{ + return __memset(s, c, n); +} /* memset */ + /** * memset * @@ -26,8 +56,8 @@ */ void* __memset(void *s, /**< area to set values in */ - int c, /**< value to set */ - size_t n) /**< area size */ + int c, /**< value to set */ + size_t n) /**< area size */ { uint8_t *pArea = s; for ( size_t index = 0; index < n; index++ ) From 0dd13021ae84c381a1c789f2933bd71efc09398e Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:44:54 +0400 Subject: [PATCH 04/16] Remove usage of 'double' type. --- src/libruntime/jerry-libc.c | 2 +- src/libruntime/jerry-libc.h | 2 +- src/libruntime/pretty-printer.c | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libruntime/jerry-libc.c b/src/libruntime/jerry-libc.c index d836efee0..5cd66dd87 100644 --- a/src/libruntime/jerry-libc.c +++ b/src/libruntime/jerry-libc.c @@ -224,7 +224,7 @@ __strtof (const char *nptr, char **endptr) (void) endptr; JERRY_UNIMPLEMENTED (); -} +} /* __strtof */ /** Calculate the length of a string. */ size_t diff --git a/src/libruntime/jerry-libc.h b/src/libruntime/jerry-libc.h index a39d8310c..77c581993 100644 --- a/src/libruntime/jerry-libc.h +++ b/src/libruntime/jerry-libc.h @@ -54,6 +54,6 @@ extern int __fprintf(FILE *stream, const char *format, ...); #define DBL_DIG ( 10) #define DBL_MIN_EXP (-324) #define DBL_MAX_EXP ( 308) -#define HUGE_VAL (1e37) +#define HUGE_VAL (1e37f) #endif /* JERRY_LIBC_H */ diff --git a/src/libruntime/pretty-printer.c b/src/libruntime/pretty-printer.c index 63ab02e84..4c04231c0 100644 --- a/src/libruntime/pretty-printer.c +++ b/src/libruntime/pretty-printer.c @@ -51,7 +51,8 @@ pp_token (token tok) break; case TOK_FLOAT: - __printf ("FLOAT (%f)\n", tok.data.fp_num); + FIXME(int -> float); + __printf ("FLOAT (%d)\n", (int)tok.data.fp_num); break; case TOK_NULL: From 4ca4c71c8bd3b279ef4465ef319e28a46e2b3e19 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:51:11 +0400 Subject: [PATCH 05/16] Fix warning about unused parameter 'opdata' in opfunc_call_1. --- src/libcoreint/opcodes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 0d60317d8..b7276e2f9 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -99,7 +99,7 @@ opfunc_loop_inf (OPCODE opdata, struct __int_data *int_data) } void -opfunc_call_1 (OPCODE opdata, struct __int_data *int_data) +opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data) { #ifdef __HOST __printf ("%d::op_call_1:idx:%d:%d\n", From c9e98171fd2d9aaebd31888eb33429d098086052 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:53:41 +0400 Subject: [PATCH 06/16] Remove inline attributes from src/libjsparser/lexer.c. --- src/libjsparser/lexer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libjsparser/lexer.c b/src/libjsparser/lexer.c index bbff2d4be..042518452 100644 --- a/src/libjsparser/lexer.c +++ b/src/libjsparser/lexer.c @@ -83,7 +83,7 @@ static string_and_token keyword_tokens[] = static string_and_token seen_names[MAX_NAMES]; static size_t seen_names_num; -static inline bool +static bool is_empty (token tok) { return tok.type == TOK_EMPTY; @@ -213,7 +213,7 @@ add_to_seen_tokens (string_and_token snt) seen_names[seen_names_num++] = snt; } -static inline void +static void new_token (void) { JERRY_ASSERT (buffer); @@ -227,7 +227,7 @@ consume_char (void) buffer++; } -static inline const char * +static const char * current_token (void) { JERRY_ASSERT (buffer); From 63547e9f2c902cd916f8474996a17ce0c72953e2 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:56:17 +0400 Subject: [PATCH 07/16] Change bit fields' type from uint32_t to unsigned int (because uint32_t is defined as something other than unsigned int in arm-none-eabi stdint.h; using that type for bit-fields is GCC extension). --- src/libecmaobjects/ecma-globals.h | 52 ++++++++++++++--------------- src/libecmaobjects/ecma-reference.h | 4 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 659960e7a..21d1cdf46 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -101,12 +101,12 @@ typedef enum { */ typedef struct { /** Value type (ecma_Type_t) */ - uint32_t m_ValueType : 2; + unsigned int 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; + unsigned int m_Value : ECMA_POINTER_FIELD_WIDTH; } __packed ecma_Value_t; /** @@ -116,13 +116,13 @@ typedef struct { */ typedef struct { /** Type (ecma_CompletionType_t) */ - uint32_t completion_type : 3; + unsigned int completion_type : 3; /** Value */ ecma_Value_t completion_value; /** Target */ - uint32_t target : 8; + unsigned int target : 8; } __packed ecma_CompletionValue_t; /** @@ -152,10 +152,10 @@ typedef enum { */ typedef struct ecma_Property_t { /** Property's type (ecma_PropertyType_t) */ - uint32_t m_Type : 2; + unsigned int m_Type : 2; /** Compressed pointer to next property */ - uint32_t m_pNextProperty : ECMA_POINTER_FIELD_WIDTH; + unsigned int m_pNextProperty : ECMA_POINTER_FIELD_WIDTH; /** Property's details (depending on m_Type) */ union { @@ -163,16 +163,16 @@ typedef struct ecma_Property_t { /** 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; + unsigned int m_pName : ECMA_POINTER_FIELD_WIDTH; /** Attribute 'Writable' */ - uint32_t m_Writable : 1; + unsigned int m_Writable : 1; /** Attribute 'Enumerable' */ - uint32_t m_Enumerable : 1; + unsigned int m_Enumerable : 1; /** Attribute 'Configurable' */ - uint32_t m_Configurable : 1; + unsigned int m_Configurable : 1; /** Value */ ecma_Value_t m_Value; @@ -181,28 +181,28 @@ typedef struct ecma_Property_t { /** 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; + unsigned int m_pName : ECMA_POINTER_FIELD_WIDTH; /** Attribute 'Enumerable' */ - uint32_t m_Enumerable : 1; + unsigned int m_Enumerable : 1; /** Attribute 'Configurable' */ - uint32_t m_Configurable : 1; + unsigned int m_Configurable : 1; /** Compressed pointer to property's getter */ - uint32_t m_pGet : ECMA_POINTER_FIELD_WIDTH; + unsigned int m_pGet : ECMA_POINTER_FIELD_WIDTH; /** Compressed pointer to property's setter */ - uint32_t m_pSet : ECMA_POINTER_FIELD_WIDTH; + unsigned int 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; + unsigned int m_InternalPropertyType : 4; /** Value (may be a compressed pointer) */ - uint32_t m_Value : ECMA_POINTER_FIELD_WIDTH; + unsigned int m_Value : ECMA_POINTER_FIELD_WIDTH; } m_InternalProperty; } u; } ecma_Property_t; @@ -215,7 +215,7 @@ 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; + unsigned int m_IsObjectValid : 1; /** Details (depending on m_IsObjectValid) */ union { @@ -227,10 +227,10 @@ typedef struct { * 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; + unsigned int 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; + unsigned int m_NextQueuedForGC : ECMA_POINTER_FIELD_WIDTH; } __packed u; } ecma_GCInfo_t; @@ -248,11 +248,11 @@ typedef enum { */ typedef struct ecma_Object_t { /** Compressed pointer to property list */ - uint32_t m_pProperties : ECMA_POINTER_FIELD_WIDTH; + unsigned int 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; + unsigned int m_IsLexicalEnvironment : 1; /** * Attributes of either general object or lexical environment @@ -264,10 +264,10 @@ typedef struct ecma_Object_t { */ struct { /** Attribute 'Extensible' */ - uint32_t m_Extensible : 1; + unsigned int m_Extensible : 1; /** Compressed pointer to prototype object (ecma_Object_t) */ - uint32_t m_pPrototypeObject : ECMA_POINTER_FIELD_WIDTH; + unsigned int m_pPrototypeObject : ECMA_POINTER_FIELD_WIDTH; } __packed m_Object; /** @@ -277,10 +277,10 @@ typedef struct ecma_Object_t { /** * Type of lexical environment (ecma_LexicalEnvironmentType_t). */ - uint32_t m_Type : 1; + unsigned int m_Type : 1; /** Compressed pointer to outer lexical environment */ - uint32_t m_pOuterReference : ECMA_POINTER_FIELD_WIDTH; + unsigned int m_pOuterReference : ECMA_POINTER_FIELD_WIDTH; } __packed m_LexicalEnvironment; } __packed u_Attributes; diff --git a/src/libecmaobjects/ecma-reference.h b/src/libecmaobjects/ecma-reference.h index cfdb33bb6..89c4f8035 100644 --- a/src/libecmaobjects/ecma-reference.h +++ b/src/libecmaobjects/ecma-reference.h @@ -35,12 +35,12 @@ typedef struct { * Note: * m_PropertyName is valid only if m_IsPropertyReference is true. */ - uint32_t m_IsPropertyReference : 1; + unsigned int m_IsPropertyReference : 1; /** * Flag indicating that this reference is strict (see also: ECMA-262 v5, 8.7). */ - uint32_t m_StrictReference : 1; + unsigned int m_StrictReference : 1; /** * Name of variable (Null-terminated string). From dfb9441e8cbc00ae28604700f7e2200eeaa2e64d Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 19:59:29 +0400 Subject: [PATCH 08/16] Removed typedefs for basic int types and bool, definition of NULL from globals.h. Included , , in that header. --- src/globals.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/globals.h b/src/globals.h index 2fcfe2972..7eee61bd1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -16,22 +16,15 @@ #ifndef JERRY_GLOBALS_H #define JERRY_GLOBALS_H +#include +#include +#include + /** * Types */ typedef unsigned long mword_t; -typedef mword_t uintptr_t; -typedef mword_t size_t; typedef signed long ssize_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; -typedef signed int int32_t; - -typedef enum { - false, true -} bool; /** * Attributes @@ -43,8 +36,6 @@ typedef enum { /** * Constants */ -#define NULL ((void*)0) - #define JERRY_BITSINBYTE 8 /** @@ -99,7 +90,7 @@ extern void __noreturn jerry_AssertFail( const char *assertion, const char *file /** * Mark for unreachable points and unimplemented cases */ -#define JERRY_UNREACHABLE() do { JERRY_ASSERT( false); __builtin_trap(); } while (0) +#define JERRY_UNREACHABLE() do { JERRY_ASSERT( false); jerry_Exit( ERR_GENERAL); } while (0) #define JERRY_UNIMPLEMENTED() JERRY_UNREACHABLE() /** From d4b84f47a8223d564f30a9eb32d3e794a0c306f7 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 20:03:43 +0400 Subject: [PATCH 09/16] Fixing type conversion warnings in src/main.c and disabling warnings for third-party headers, included from that module. --- src/main.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 8ba6ebf05..46e8ea521 100644 --- a/src/main.c +++ b/src/main.c @@ -14,9 +14,14 @@ */ #ifdef __TARGET_MCU + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wsign-conversion" #include "stm32f4xx.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" +#pragma GCC diagnostic pop #define LED_GREEN 12 #define LED_ORANGE 13 @@ -38,11 +43,11 @@ void fake_exit (void) { #ifdef __TARGET_MCU - int pin = LED_RED; - uint32_t mode = GPIO_Mode_OUT << (pin * 2); - uint32_t speed = GPIO_Speed_100MHz << (pin * 2); - uint32_t type = GPIO_OType_PP << pin; - uint32_t pullup = GPIO_PuPd_NOPULL << (pin * 2); + uint32_t pin = LED_RED; + uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2); + uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2); + uint32_t type = (uint32_t)GPIO_OType_PP << pin; + uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2); // // Initialise the peripheral clock. // @@ -66,17 +71,17 @@ fake_exit (void) while (1) { - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash * 7; index++); } From 7a2397f235e1b90f59470312f2f043838b736de3 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 20:10:46 +0400 Subject: [PATCH 10/16] Introducing new make targets scheme: {dev,debug,release,debug_release}.{linux,stm32f{4}}[.{check,flash}]. --- Makefile | 199 ++++++----------------------- Makefile.mak | 275 ++++++++++++++++++++++++++++++++++++++++ tools/jerry_unittest.sh | 5 +- 3 files changed, 317 insertions(+), 162 deletions(-) create mode 100644 Makefile.mak diff --git a/Makefile b/Makefile index cfac5dcb0..c37a479e8 100644 --- a/Makefile +++ b/Makefile @@ -12,144 +12,49 @@ # See the License for the specific language governing permissions and # limitations under the License. -TARGET ?= jerry -CROSS_COMPILE ?= arm-none-eabi- -OBJ_DIR = ./obj -OUT_DIR = ./out +# +# Target naming scheme +# +# Main targets: {dev,debug,release,debug_release}.{linux,stm32f{4}}[.{check,flash}] +# +# Target mode part (before dot): +# dev: - JERRY_NDEBUG; - optimizations; + debug symbols; - -Werror | local development build +# debug: - JERRY_NDEBUG; - optimizations; + debug symbols; + -Werror | debug build +# debug_release: - JERRY_NDEBUG; + optimizations; + debug symbols; + -Werror | checked release build +# release: + JERRY_NDEBUG; + optimizations; - debug symbols; + -Werror | release build +# +# Target system part (after first dot): +# linux - target system is linux +# stm32f{4} - target is STM32F{4} board +# +# Target action part (optional, after second dot): +# check - run cppcheck on src folder, unit and other tests +# flash - flash specified mcu target binary +# +# +# Unit test target: unittests +# -MAIN_MODULE_SRC = ./src/main.c -UNITTESTS_SRC_DIR = ./tests/unit +export TARGET_MODES = dev debug debug_release release +export TARGET_PC_SYSTEMS = linux +export TARGET_MCU_SYSTEMS = $(addprefix stm32f,4) # now only stm32f4 is supported, to add, for example, to stm32f3, change to $(addprefix stm32f,3 4) +export TARGET_SYSTEMS = $(TARGET_PC_SYSTEMS) $(TARGET_MCU_SYSTEMS) -LNK_SCRIPT_STM32F4 = ./third-party/stm32f4.ld -SUP_STM32F4 = ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s +# Target list +export JERRY_TARGETS = $(foreach __MODE,$(TARGET_MODES),$(foreach __SYSTEM,$(TARGET_SYSTEMS),$(__MODE).$(__SYSTEM))) +export TESTS_TARGET = unittests +export CHECK_TARGETS = $(foreach __TARGET,$(JERRY_TARGETS),$(__TARGET).check) +export FLASH_TARGETS = $(foreach __TARGET,$(JERRY_TARGETS),$(__TARGET).flash) +export OBJ_DIR = ./obj +export OUT_DIR = ./out +export UNITTESTS_SRC_DIR = ./tests/unit -# FIXME: -# Place jerry-libc.c, pretty-printer.c to some subdirectory (libruntime?) -# and add them to the SOURCES list through wildcard. -# FIXME: -# Add common-io.c and sensors.c -SOURCES = \ - $(sort \ - $(wildcard ./src/libruntime/*.c) \ - $(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) ) +all: clean $(JERRY_TARGETS) $(TESTS_TARGET) $(CHECK_TARGETS) -SOURCES_STM32F4 = \ - third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \ - $(wildcard src/libruntime/target/stm32f4/*) - -SOURCES_LINUX = \ - $(wildcard src/libruntime/target/linux/*) - -HEADERS = \ - $(sort \ - $(wildcard ./src/*.h) \ - $(wildcard ./src/libruntime/*.h) \ - $(wildcard ./src/libperipherals/*.h) \ - $(wildcard ./src/libjsparser/*.h) \ - $(wildcard ./src/libecmaobjects/*.h) \ - $(wildcard ./src/libecmaoperations/*.h) \ - $(wildcard ./src/liballocator/*.h) \ - $(wildcard ./src/libcoreint/*.h) ) - -INCLUDES = \ - -I src \ - -I src/libruntime \ - -I src/libperipherals \ - -I src/libjsparser \ - -I src/libecmaobjects \ - -I src/libecmaoperations \ - -I src/liballocator \ - -I src/libcoreint - -INCLUDES_STM32F4 = \ - -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include \ - -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \ - -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include - -UNITTESTS = \ - $(sort \ - $(patsubst %.c,%,$(notdir \ - $(wildcard $(UNITTESTS_SRC_DIR)/*)))) - -OBJS = \ - $(sort \ - $(patsubst %.c,./%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES)))) - -CC = gcc -LD = ld -OBJDUMP = objdump -OBJCOPY = objcopy -SIZE = size -STRIP = strip - -# General flags -CFLAGS ?= $(INCLUDES) -std=c99 -Werror #-fdiagnostics-color=always -CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline -CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector -CFLAGS += -Wconversion -Wsign-conversion -Wformat-security -CFLAGS += -Wstrict-prototypes -Wmissing-prototypes - -# Flags for MCU -MCU_CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb -MCU_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -MCU_CFLAGS += -ffunction-sections -fdata-sections -nostdlib -fno-common - -LDFLAGS = -nostartfiles -T$(LNK_SCRIPT_STM32F4) - -DEBUG_OPTIONS = -g3 -O0 # -fsanitize=address -RELEASE_OPTIONS = -Os -flto -DJERRY_NDEBUG - -DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS -TARGET_HOST = -D__HOST -TARGET_MCU = -D__TARGET_MCU - -#-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \ - -.PHONY: all debug debug.stdm32f4 release clean tests check install - -all: clean debug release check - -debug.stdm32f4: clean debug.stdm32f4.bin - -debug.stdm32f4.o: - mkdir -p $(OUT_DIR)/debug.stdm32f4/ - $(CROSS_COMPILE)$(CC) \ - $(SUP_STM32F4) $(SOURCES_STM32F4) $(INCLUDES_STM32F4) \ - $(CFLAGS) $(MCU_CFLAGS) $(DEBUG_OPTIONS) \ - $(DEFINES) $(TARGET_MCU) $(MAIN_MODULE_SRC) -c - -debug.stdm32f4.elf: debug.stdm32f4.o - $(CROSS_COMPILE)$(LD) $(LDFLAGS) -o $(TARGET).elf *.o - rm -f *.o - -debug.stdm32f4.bin: debug.stdm32f4.elf - $(CROSS_COMPILE)$(OBJCOPY) -Obinary $(TARGET).elf $(TARGET).bin - rm -f *.elf - -debug: clean - mkdir -p $(OUT_DIR)/debug.host/ - $(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(SOURCES_LINUX) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/debug.host/$(TARGET) - -release: clean - mkdir -p $(OUT_DIR)/release.host/ - $(CC) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(SOURCES_LINUX) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/release.host/$(TARGET) - $(STRIP) $(OUT_DIR)/release.host/$(TARGET) - -tests: - mkdir -p $(OUT_DIR)/tests.host/ - for unit_test in $(UNITTESTS); \ - do \ - $(CC) -O3 $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(SOURCES_LINUX) $(UNITTESTS_SRC_DIR)/"$$unit_test".c -o $(OUT_DIR)/tests.host/"$$unit_test"; \ - done +$(JERRY_TARGETS) $(TESTS_TARGET) $(FLASH_TARGETS) $(CHECK_TARGETS): + @echo $@ + @make -f Makefile.mak TARGET=$@ $@ clean: rm -f $(OBJ_DIR)/*.o *.bin *.o *~ *.log *.log @@ -161,31 +66,3 @@ clean: rm -f $(TARGET).hex rm -f $(TARGET).lst rm -f js.files - -check: tests - @ mkdir -p $(OUT_DIR) - @ cd $(OUT_DIR) - - @ echo "=== Running cppcheck ===" - @ cppcheck $(HEADERS) $(SOURCES) --error-exitcode=1 --enable=all --std=c99 - @ echo Done - @ echo - - @ echo "=== Running unit tests ===" - @ ./tools/jerry_unittest.sh $(OUT_DIR)/tests.host $(UNITTESTS) - @ echo Done - @ echo - - @ echo "=== Running js tests ===" - @ if [ -f $(OUT_DIR)/release.host/$(TARGET) ]; then \ - ./tools/jerry_test.sh $(OUT_DIR)/release.host/$(TARGET);\ - fi - - @ if [ -f $(OUT_DIR)/debug.host/$(TARGET) ]; then \ - ./tools/jerry_test.sh $(OUT_DIR)/debug.host/$(TARGET); \ - fi - @echo Done - @echo - -install: - st-flash write $(TARGET).bin 0x08000000 diff --git a/Makefile.mak b/Makefile.mak new file mode 100644 index 000000000..efbc9e696 --- /dev/null +++ b/Makefile.mak @@ -0,0 +1,275 @@ +ifeq ($(TARGET),) + $(error TARGET not set) +endif + +ENGINE_NAME ?= jerry + +CROSS_COMPILE ?= arm-none-eabi- +CC = gcc +LD = ld +OBJDUMP = objdump +OBJCOPY = objcopy +SIZE = size +STRIP = strip + +MAIN_MODULE_SRC = ./src/main.c + +LNK_SCRIPT_STM32F4 = ./third-party/stm32f4.ld + +# Parsing target +# '.' -> ' ' +TARGET_SPACED = $(subst ., ,$(TARGET)) +# extract target mode part +TARGET_MODE = $(word 1,$(TARGET_SPACED)) +# extract target system part +TARGET_SYSTEM = $(word 2,$(TARGET_SPACED)) +# extract optional action part +TARGET_ACTION = $(word 3,$(TARGET_SPACED)) + +# target folder name in $(OUT_DIR) +TARGET_DIR=$(OUT_DIR)/$(TARGET_MODE).$(TARGET_SYSTEM) + +# unittests mode -> linux system +ifeq ($(TARGET_MODE),$(TESTS_TARGET)) + TARGET_SYSTEM = linux +endif + +# +# Options setup +# + +# JERRY_NDEBUG, debug symbols +ifeq ($(TARGET_MODE),release) + OPTION_NDEBUG = enable + OPTION_DEBUG_SYMS = disable + OPTION_STRIP = enable +else + OPTION_NDEBUG = disable + OPTION_DEBUG_SYMS = enable + OPTION_STRIP = disable +endif + +# Optimizations +ifeq ($(filter-out debug_release release $(TESTS_TARGET),$(TARGET_MODE)),) + OPTION_OPTIMIZE = enable +else + OPTION_OPTIMIZE = disable +endif + +# -Werror +ifeq ($(TARGET_MODE),dev) + OPTION_WERROR = disable +else + OPTION_WERROR = enable +endif + +# Is MCU target? +ifeq ($(filter-out $(TARGET_MCU_SYSTEMS),$(TARGET_SYSTEM)),) + OPTION_MCU = enable +else + OPTION_MCU = disable +endif + +# +# Target CPU +# +TARGET_CPU = $(strip $(if $(filter linux,$(TARGET_SYSTEM)), x64, \ + $(if $(filter stm32f3,$(TARGET_SYSTEM)), cortexm4, \ + $(if $(filter stm32f4,$(TARGET_SYSTEM)), cortexm4, \ + $(error Do not know target CPU for target system '$(TARGET_SYSTEM)'))))) + +# +# Flag blocks +# + +# Warnings +CFLAGS_WARNINGS ?= -Wall -Wextra -Wpedantic -Wlogical-op -Winline \ + -Wformat-nonliteral -Winit-self -Wstack-protector \ + -Wconversion -Wsign-conversion -Wformat-security \ + -Wstrict-prototypes -Wmissing-prototypes +CFLAGS_WERROR ?= -Werror + +# Optimizations +CFLAGS_OPTIMIZE ?= -Os -flto +CFLAGS_NO_OPTIMIZE ?= -O0 +LDFLAGS_OPTIMIZE ?= -flto +LDFLAGS_NO_OPTIMIZE ?= -O0 + +# Debug symbols +CFLAGS_DEBUG_SYMS ?= -g3 + +# Cortex-M4 MCU +CFLAGS_CORTEXM4 ?= -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb \ + -mfpu=fpv4-sp-d16 -mfloat-abi=hard + + +# +# Common +# + +CFLAGS_COMMON ?= $(INCLUDES) -std=c99 # -fsanitize=address -fdiagnostics-color=always +CFLAGS_COMMON += -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS + +LDFLAGS ?= + +ifeq ($(OPTION_OPTIMIZE),enable) + CFLAGS_COMMON += $(CFLAGS_OPTIMIZE) + LDFLAGS += $(LDFLAGS_OPTIMIZE) +else + CFLAGS_COMMON += $(CFLAGS_NO_OPTIMIZE) + LDFLAGS += $(LDFLAGS_NO_OPTIMIZE) +endif + +ifeq ($(OPTION_DEBUG_SYMS),enable) + CFLAGS_COMMON += $(CFLAGS_DEBUG_SYMS) +endif + +# CPU-specific common +ifeq ($(TARGET_CPU),cortexm4) + CFLAGS_COMMON += $(CFLAGS_CORTEXM4) +endif + +# System-specific common +ifeq ($(TARGET_SYSTEM),stm32f4) + LDFLAGS += -nostartfiles -T$(LNK_SCRIPT_STM32F4) +endif + +ifeq ($(OPTION_MCU),enable) + CC := $(CROSS_COMPILE)$(CC) + LD := $(CROSS_COMPILE)$(LD) + OBJDUMP := $(CROSS_COMPILE)$(OBJDUMP) + OBJCOPY := $(CROSS_COMPILE)$(OBJCOPY) + SIZE := $(CROSS_COMPILE)$(SIZE) + STRIP := $(CROSS_COMPILE)$(STRIP) +endif + +# +# Jerry part sources, headers, includes, cflags, ldflags +# + +CFLAGS_JERRY = $(CFLAGS_COMMON) $(CFLAGS_WARNINGS) + +# FIXME: +# Add common-io.c and sensors.c +SOURCES_JERRY = \ + $(sort \ + $(wildcard ./src/libruntime/*.c) \ + $(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) ) \ + $(wildcard src/libruntime/target/$(TARGET_SYSTEM)/*) + +INCLUDES_JERRY = \ + -I src \ + -I src/libruntime \ + -I src/libperipherals \ + -I src/libjsparser \ + -I src/libecmaobjects \ + -I src/libecmaoperations \ + -I src/liballocator \ + -I src/libcoreint + +ifeq ($(OPTION_NDEBUG),enable) + CFLAGS_JERRY += -DJERRY_NDEBUG +endif + +ifeq ($(OPTION_WERROR),enable) + CFLAGS_JERRY += $(CFLAGS_WERROR) +endif + +ifeq ($(OPTION_MCU),disable) + CFLAGS_JERRY += -D__HOST +else + CFLAGS_COMMON += -ffunction-sections -fdata-sections -nostdlib + CFLAGS_JERRY += -D__TARGET_MCU +endif + +# +# Third-party sources, headers, includes, cflags, ldflags +# + +SOURCES_THIRDPARTY = +INCLUDES_THIRDPARTY = +CFLAGS_THIRDPARTY = + +ifeq ($(TARGET_SYSTEM),stm32f4) + SOURCES_THIRDPARTY += \ + ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \ + ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s + + INCLUDES_THIRDPARTY += \ + -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include \ + -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \ + -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include + +#-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \ + +endif + +# Unit tests + +SOURCES_UNITTESTS = \ + $(sort \ + $(patsubst %.c,%,$(notdir \ + $(wildcard $(UNITTESTS_SRC_DIR)/*)))) + +.PHONY: all clean check install $(JERRY_TARGETS) $(TESTS_TARGET) + +all: clean $(JERRY_TARGETS) + +$(JERRY_TARGETS): + @rm -rf $(TARGET_DIR) + @mkdir -p $(TARGET_DIR) + @rm -rf $(OBJ_DIR) + @mkdir $(OBJ_DIR) + @source_index=0; \ + for jerry_src in $(SOURCES_JERRY) $(MAIN_MODULE_SRC); do \ + cmd="$(CC) -c $(CFLAGS_COMMON) $(CFLAGS_JERRY) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $$jerry_src -o $(OBJ_DIR)/$$(basename $$jerry_src).$$source_index.o"; \ + $$cmd; \ + if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \ + source_index=$$(($$source_index+1)); \ + done; \ + for thirdparty_src in $(SOURCES_THIRDPARTY); do \ + cmd="$(CC) -c $(CFLAGS_COMMON) $(CFLAGS_THIRDPARTY) $(INCLUDES_THIRDPARTY) $$thirdparty_src -o $(OBJ_DIR)/$$(basename $$thirdparty_src).$$source_index.o"; \ + $$cmd; \ + if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \ + source_index=$$(($$source_index+1)); \ + done; \ + cmd="$(CC) $(CFLAGS_COMMON) $(OBJ_DIR)/* $(LDFLAGS) -o $(TARGET_DIR)/$(ENGINE_NAME)"; \ + $$cmd; \ + if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; + @if [ "$(OPTION_STRIP)" = "enable" ]; then $(STRIP) $(TARGET_DIR)/$(ENGINE_NAME) || exit $$?; fi; + @if [ "$(OPTION_MCU)" = "enable" ]; then $(OBJCOPY) -Obinary $(TARGET_DIR)/$(ENGINE_NAME) $(TARGET_DIR)/$(ENGINE_NAME).bin || exit $$?; fi; + +$(TESTS_TARGET): + @echo $@ $(TARGET_DIR) + @mkdir -p $(TARGET_DIR) + @for unit_test in $(SOURCES_UNITTESTS); \ + do \ + $(CC) $(CFLAGS_COMMON) $(CFLAGS_JERRY) \ + $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $(SOURCES_JERRY) $(UNITTESTS_SRC_DIR)/"$$unit_test".c -o $(TARGET_DIR)/"$$unit_test"; \ + done + @ echo "=== Running unit tests ===" + @ ./tools/jerry_unittest.sh $(TARGET_DIR) + @ echo Done + @ echo + +$(CHECK_TARGETS): + @ echo "=== Running cppcheck ===" + @ cppcheck `find src $(UNITTESTS_SRC_DIR) -name *.[ch]` --error-exitcode=1 --enable=all --std=c99 + @ echo Done + @ echo + + @ echo "=== Running js tests ===" + @ if [ -f $(TARGET_DIR)/$(ENGINE_NAME) ]; then \ + ./tools/jerry_test.sh $(TARGET_DIR)/$(ENGINE_NAME);\ + fi + + @echo Done + @echo + +$(FLASH_TARGETS): + st-flash write $(OUT_DIR)/$(TARGET)/jerry.bin 0x08000000 || exit $$? diff --git a/tools/jerry_unittest.sh b/tools/jerry_unittest.sh index 645aef2ce..cb92943d7 100755 --- a/tools/jerry_unittest.sh +++ b/tools/jerry_unittest.sh @@ -15,7 +15,10 @@ #!/bin/bash DIR="$1" -UNITTESTS="${*:2}" + +rm -f $DIR/unit_tests_run.log + +UNITTESTS=$(ls $DIR) for unit_test in $UNITTESTS; do From 18a5852914bc3e8dc3fa6c4ac69d0248847c5d09 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 20:53:06 +0400 Subject: [PATCH 11/16] Fix src/main.c for target MCU. --- src/main.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 46e8ea521..533c795cb 100644 --- a/src/main.c +++ b/src/main.c @@ -55,10 +55,12 @@ fake_exit (void) // // Initilaise the GPIO port. // - GPIOD->MODER |= mode; - GPIOD->OSPEEDR |= speed; - GPIOD->OTYPER |= type; - GPIOD->PUPDR |= pullup; + volatile GPIO_TypeDef* gpio = GPIOD; + + gpio->MODER |= mode; + gpio->OSPEEDR |= speed; + gpio->OTYPER |= type; + gpio->PUPDR |= pullup; // // Toggle the selected LED indefinitely. // @@ -68,20 +70,20 @@ fake_exit (void) int dot = 600000; int dash = dot * 3; - + while (1) { - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); - GPIOD->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (uint16_t) (1 << pin); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); + gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash * 7; index++); } @@ -90,19 +92,26 @@ fake_exit (void) #endif } +#ifdef __HOST int main (int argc, char **argv) +#endif /* __HOST */ +#ifdef __TARGET_MCU +int +main (void) +#endif /* __TARGET_MCU */ { statement st; bool dump_tokens = false; bool dump_ast = false; - const char *file_name = NULL; #ifdef __HOST + const char *file_name = NULL; FILE *file = NULL; #endif mem_Init (); +#ifdef __HOST if (argc > 0) for (int i = 1; i < argc; i++) { @@ -125,7 +134,6 @@ main (int argc, char **argv) if (!dump_tokens) dump_ast = true; -#ifdef __HOST file = __fopen (file_name, "r"); if (file == NULL) From b4cafc2ae8aa812a35e92694ff7170a8b1747e77 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 14 Jul 2014 21:00:40 +0400 Subject: [PATCH 12/16] Removing *.linux.flash targets. Adding dependency from check, flash to target of an action, fix path used in flash action. Temporarily changing --error-exitcode parameter of cppcheck to 0. --- Makefile | 2 +- Makefile.mak | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c37a479e8..a3682836b 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ export TARGET_SYSTEMS = $(TARGET_PC_SYSTEMS) $(TARGET_MCU_SYSTEMS) export JERRY_TARGETS = $(foreach __MODE,$(TARGET_MODES),$(foreach __SYSTEM,$(TARGET_SYSTEMS),$(__MODE).$(__SYSTEM))) export TESTS_TARGET = unittests export CHECK_TARGETS = $(foreach __TARGET,$(JERRY_TARGETS),$(__TARGET).check) -export FLASH_TARGETS = $(foreach __TARGET,$(JERRY_TARGETS),$(__TARGET).flash) +export FLASH_TARGETS = $(foreach __TARGET,$(foreach __MODE,$(TARGET_MODES),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS),$(__MODE).$(__SYSTEM))),$(__TARGET).flash) export OBJ_DIR = ./obj export OUT_DIR = ./out diff --git a/Makefile.mak b/Makefile.mak index efbc9e696..457f0e6e8 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -26,6 +26,9 @@ TARGET_SYSTEM = $(word 2,$(TARGET_SPACED)) # extract optional action part TARGET_ACTION = $(word 3,$(TARGET_SPACED)) +# Target used as dependency of an action (check, flash, etc.) +TARGET_OF_ACTION = $(TARGET_MODE).$(TARGET_SYSTEM) + # target folder name in $(OUT_DIR) TARGET_DIR=$(OUT_DIR)/$(TARGET_MODE).$(TARGET_SYSTEM) @@ -257,9 +260,10 @@ $(TESTS_TARGET): @ echo Done @ echo -$(CHECK_TARGETS): +# FIXME: Change cppcheck's --error-exitcode to 1 after fixing cppcheck's warnings and errors. +$(CHECK_TARGETS): $(TARGET_OF_ACTION) @ echo "=== Running cppcheck ===" - @ cppcheck `find src $(UNITTESTS_SRC_DIR) -name *.[ch]` --error-exitcode=1 --enable=all --std=c99 + @ cppcheck `find src $(UNITTESTS_SRC_DIR) -name *.[ch]` --error-exitcode=0 --enable=all --std=c99 @ echo Done @ echo @@ -271,5 +275,5 @@ $(CHECK_TARGETS): @echo Done @echo -$(FLASH_TARGETS): - st-flash write $(OUT_DIR)/$(TARGET)/jerry.bin 0x08000000 || exit $$? +$(FLASH_TARGETS): $(TARGET_OF_ACTION) + st-flash write $(OUT_DIR)/$(TARGET_OF_ACTION)/jerry.bin 0x08000000 || exit $$? From 4ffbb5dc0ce6eb7d1f4f6acea77521089e3051a9 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 15 Jul 2014 15:43:16 +0400 Subject: [PATCH 13/16] Emptying LDFLAGS_OPTIMIZE and LDFLAGS_NO_OPTIMIZE, because their current values are duplicating flags in $(CFLAGS_COMMON). --- Makefile.mak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.mak b/Makefile.mak index 457f0e6e8..70eedb2ea 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -95,8 +95,8 @@ CFLAGS_WERROR ?= -Werror # Optimizations CFLAGS_OPTIMIZE ?= -Os -flto CFLAGS_NO_OPTIMIZE ?= -O0 -LDFLAGS_OPTIMIZE ?= -flto -LDFLAGS_NO_OPTIMIZE ?= -O0 +LDFLAGS_OPTIMIZE ?= +LDFLAGS_NO_OPTIMIZE ?= # Debug symbols CFLAGS_DEBUG_SYMS ?= -g3 From 2615f287004889c2f09623904b4cb94aed74471d Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 15 Jul 2014 18:56:09 +0400 Subject: [PATCH 14/16] Adding JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(...) macros that allow referencing variables that are unused due to partial implementation. --- src/globals.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/globals.h b/src/globals.h index 7eee61bd1..d01d5965e 100644 --- a/src/globals.h +++ b/src/globals.h @@ -90,8 +90,10 @@ extern void __noreturn jerry_AssertFail( const char *assertion, const char *file /** * Mark for unreachable points and unimplemented cases */ +extern void jerry_RefUnusedVariables(int unused_variables_follow, ...); #define JERRY_UNREACHABLE() do { JERRY_ASSERT( false); jerry_Exit( ERR_GENERAL); } while (0) #define JERRY_UNIMPLEMENTED() JERRY_UNREACHABLE() +#define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(...) do { JERRY_UNIMPLEMENTED(); if ( false ) { jerry_RefUnusedVariables( 0, __VA_ARGS__); } } while (0) /** * Exit From f88fe5fae33843902ac623e2497c84c828a6263b Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 15 Jul 2014 19:16:54 +0400 Subject: [PATCH 15/16] Moving jerry defines from CFLAGS_COMMON to DEFINES_JERRY and fixing cppcheck arguments. --- Makefile.mak | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.mak b/Makefile.mak index 70eedb2ea..66158ddf7 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -111,7 +111,6 @@ CFLAGS_CORTEXM4 ?= -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb \ # CFLAGS_COMMON ?= $(INCLUDES) -std=c99 # -fsanitize=address -fdiagnostics-color=always -CFLAGS_COMMON += -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS LDFLAGS ?= @@ -150,7 +149,8 @@ endif # Jerry part sources, headers, includes, cflags, ldflags # -CFLAGS_JERRY = $(CFLAGS_COMMON) $(CFLAGS_WARNINGS) +CFLAGS_JERRY = $(CFLAGS_WARNINGS) +DEFINES_JERRY = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS # FIXME: # Add common-io.c and sensors.c @@ -176,7 +176,7 @@ INCLUDES_JERRY = \ -I src/libcoreint ifeq ($(OPTION_NDEBUG),enable) - CFLAGS_JERRY += -DJERRY_NDEBUG + DEFINES_JERRY += -DJERRY_NDEBUG endif ifeq ($(OPTION_WERROR),enable) @@ -184,10 +184,10 @@ ifeq ($(OPTION_WERROR),enable) endif ifeq ($(OPTION_MCU),disable) - CFLAGS_JERRY += -D__HOST + DEFINES_JERRY += -D__HOST else CFLAGS_COMMON += -ffunction-sections -fdata-sections -nostdlib - CFLAGS_JERRY += -D__TARGET_MCU + DEFINES_JERRY += -D__TARGET_MCU endif # @@ -230,7 +230,7 @@ $(JERRY_TARGETS): @mkdir $(OBJ_DIR) @source_index=0; \ for jerry_src in $(SOURCES_JERRY) $(MAIN_MODULE_SRC); do \ - cmd="$(CC) -c $(CFLAGS_COMMON) $(CFLAGS_JERRY) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $$jerry_src -o $(OBJ_DIR)/$$(basename $$jerry_src).$$source_index.o"; \ + cmd="$(CC) -c $(DEFINES_JERRY) $(CFLAGS_COMMON) $(CFLAGS_JERRY) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $$jerry_src -o $(OBJ_DIR)/$$(basename $$jerry_src).$$source_index.o"; \ $$cmd; \ if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \ source_index=$$(($$source_index+1)); \ @@ -252,7 +252,7 @@ $(TESTS_TARGET): @mkdir -p $(TARGET_DIR) @for unit_test in $(SOURCES_UNITTESTS); \ do \ - $(CC) $(CFLAGS_COMMON) $(CFLAGS_JERRY) \ + $(CC) $(DEFINES_JERRY) $(CFLAGS_COMMON) $(CFLAGS_JERRY) \ $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $(SOURCES_JERRY) $(UNITTESTS_SRC_DIR)/"$$unit_test".c -o $(TARGET_DIR)/"$$unit_test"; \ done @ echo "=== Running unit tests ===" @@ -263,13 +263,13 @@ $(TESTS_TARGET): # FIXME: Change cppcheck's --error-exitcode to 1 after fixing cppcheck's warnings and errors. $(CHECK_TARGETS): $(TARGET_OF_ACTION) @ echo "=== Running cppcheck ===" - @ cppcheck `find src $(UNITTESTS_SRC_DIR) -name *.[ch]` --error-exitcode=0 --enable=all --std=c99 + @ cppcheck $(DEFINES_JERRY) `find $(UNITTESTS_SRC_DIR) -name *.[c]` $(SOURCES_JERRY) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) --error-exitcode=0 --enable=all --std=c99 @ echo Done @ echo @ echo "=== Running js tests ===" @ if [ -f $(TARGET_DIR)/$(ENGINE_NAME) ]; then \ - ./tools/jerry_test.sh $(TARGET_DIR)/$(ENGINE_NAME);\ + ./tools/jerry_test.sh $(TARGET_DIR)/$(ENGINE_NAME); \ fi @echo Done From 4395da05d37d5667268c42f1a509f820147d8ef9 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 15 Jul 2014 19:26:42 +0400 Subject: [PATCH 16/16] Renaming ecma_Object_t::u_Attributes to u. Renaming ecma_CompletionValue_t:: completion_type to type, completion_value to value. Introducing ECMA_TARGET_ID_RESERVED value of ecma_CompletionValue_t::target when it is unused. Adding ecma_Reference_t type for ECMA-reference. Introducing some constructors and helpers for ecma-values. Introducing ecma_FindNamedProperty helper. Removing ecma_SyntacticReference_t type. Implementing ecma operation GetIdentifierReference. Stubs and partial implementation for GetValue, SetValue, lexical environment operations (HasBinding, etc.). --- src/libecmaobjects/ecma-gc.c | 4 +- src/libecmaobjects/ecma-globals.h | 36 ++++- src/libecmaobjects/ecma-helpers-value.c | 120 ++++++++++++++++ src/libecmaobjects/ecma-helpers.c | 55 ++++++-- src/libecmaobjects/ecma-helpers.h | 13 +- src/libecmaobjects/ecma-reference.h | 29 +--- src/libecmaoperations/ecma-get-put-value.c | 101 ++++++++++++++ src/libecmaoperations/ecma-lex-env.c | 153 +++++++++++++++++++++ src/libecmaoperations/ecma-lex-env.h | 48 +++++++ src/libecmaoperations/ecma-operations.h | 6 +- 10 files changed, 520 insertions(+), 45 deletions(-) create mode 100644 src/libecmaobjects/ecma-helpers-value.c create mode 100644 src/libecmaoperations/ecma-get-put-value.c create mode 100644 src/libecmaoperations/ecma-lex-env.c create mode 100644 src/libecmaoperations/ecma-lex-env.h diff --git a/src/libecmaobjects/ecma-gc.c b/src/libecmaobjects/ecma-gc.c index 69128e454..4ced0032a 100644 --- a/src/libecmaobjects/ecma-gc.c +++ b/src/libecmaobjects/ecma-gc.c @@ -258,7 +258,7 @@ ecma_GCRun( void) if ( pObject->m_IsLexicalEnvironment ) { - ecma_Object_t *pOuterLexicalEnvironment = ecma_GetPointer( pObject->u_Attributes.m_LexicalEnvironment.m_pOuterReference); + ecma_Object_t *pOuterLexicalEnvironment = ecma_GetPointer( pObject->u.m_LexicalEnvironment.m_pOuterReference); if ( pOuterLexicalEnvironment != NULL ) { @@ -266,7 +266,7 @@ ecma_GCRun( void) } } else { - ecma_Object_t *pPrototypeObject = ecma_GetPointer( pObject->u_Attributes.m_Object.m_pPrototypeObject); + ecma_Object_t *pPrototypeObject = ecma_GetPointer( pObject->u.m_Object.m_pPrototypeObject); if ( pPrototypeObject != NULL ) { diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 21d1cdf46..b8a302fb8 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -116,15 +116,21 @@ typedef struct { */ typedef struct { /** Type (ecma_CompletionType_t) */ - unsigned int completion_type : 3; + unsigned int type : 3; /** Value */ - ecma_Value_t completion_value; + ecma_Value_t value; /** Target */ unsigned int target : 8; } __packed ecma_CompletionValue_t; +/** + * Target value indicating that target field + * of ecma_CompletionValue_t defines no target. + */ +#define ECMA_TARGET_ID_RESERVED 255 + /** * Internal properties' identifiers. */ @@ -283,7 +289,7 @@ typedef struct ecma_Object_t { unsigned int m_pOuterReference : ECMA_POINTER_FIELD_WIDTH; } __packed m_LexicalEnvironment; - } __packed u_Attributes; + } __packed u; /** GC's information */ ecma_GCInfo_t m_GCInfo; @@ -342,6 +348,30 @@ typedef struct { uint8_t m_Elements[ ECMA_ARRAY_CHUNK_SIZE_IN_BYTES - sizeof (uint16_t) ]; } ecma_ArrayNonFirstChunk_t; +/** + * \addtogroup reference ECMA-reference + * @{ + */ + +/** + * ECMA-reference (see also: ECMA-262 v5, 8.7). + */ +typedef struct +{ + /** base value */ + ecma_Value_t base; + + /** referenced name value pointer */ + ecma_Char_t *referenced_name_p; + + /** strict reference flag */ + bool is_strict; +} ecma_Reference_t; + +/** + * @} + */ + #endif /* JERRY_ECMA_GLOBALS_H */ /** diff --git a/src/libecmaobjects/ecma-helpers-value.c b/src/libecmaobjects/ecma-helpers-value.c new file mode 100644 index 000000000..ad8d6bc9e --- /dev/null +++ b/src/libecmaobjects/ecma-helpers-value.c @@ -0,0 +1,120 @@ +/* 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 + * @{ + */ + +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "globals.h" + +/** + * Check if the value is undefined. + * + * @return true - if the value contains ecma-undefined simple value, + * false - otherwise. + */ +bool +ecma_IsUndefinedValue( ecma_Value_t value) /**< ecma-value */ +{ + return ( value.m_ValueType == ECMA_TYPE_SIMPLE && value.m_Value == ECMA_SIMPLE_VALUE_UNDEFINED ); +} /* ecma_IsUndefinedValue */ + +/** + * Check if the value is null. + * + * @return true - if the value contains ecma-null simple value, + * false - otherwise. + */ +bool +ecma_IsNullValue( ecma_Value_t value) /**< ecma-value */ +{ + return ( value.m_ValueType == ECMA_TYPE_SIMPLE && value.m_Value == ECMA_SIMPLE_VALUE_NULL ); +} /* ecma_IsNullValue */ + +/** + * Check if the value is boolean. + * + * @return true - if the value contains ecma-true or ecma-false simple values, + * false - otherwise. + */ +bool +ecma_IsBooleanValue( ecma_Value_t value) /**< ecma-value */ +{ + return ( ( value.m_ValueType == ECMA_TYPE_SIMPLE && value.m_Value == ECMA_SIMPLE_VALUE_FALSE ) + || ( value.m_ValueType == ECMA_TYPE_SIMPLE && value.m_Value == ECMA_SIMPLE_VALUE_TRUE ) ); +} /* ecma_IsBooleanValue */ + +/** + * Check if the value is true. + * + * Warning: + * value must be boolean + * + * @return true - if the value contains ecma-true simple value, + * false - otherwise. + */ +bool +ecma_IsValueTrue( ecma_Value_t value) /**< ecma-value */ +{ + JERRY_ASSERT( ecma_IsBooleanValue( value) ); + + return ( value.m_ValueType == ECMA_TYPE_SIMPLE && value.m_Value == ECMA_SIMPLE_VALUE_TRUE ); +} /* ecma_IsValueTrue */ + +/** + * Simple value constructor + */ +ecma_Value_t +ecma_MakeSimpleValue( ecma_SimpleValue_t value) /**< simple value */ +{ + return (ecma_Value_t) { .m_ValueType = ECMA_TYPE_SIMPLE, .m_Value = value }; +} /* ecma_MakeSimpleValue */ + +/** + * Object value constructor + */ +ecma_Value_t +ecma_MakeObjectValue( ecma_Object_t* object_p) /**< object to reference in value */ +{ + JERRY_ASSERT( object_p != NULL ); + + ecma_Value_t object_value; + + object_value.m_ValueType = ECMA_TYPE_OBJECT; + ecma_SetPointer( object_value.m_Value, object_p); + + return object_value; +} /* ecma_MakeObjectValue */ + +/** + * Completion value constructor + */ +ecma_CompletionValue_t +ecma_MakeCompletionValue(ecma_CompletionType_t type, /**< type */ + ecma_Value_t value, /**< value */ + uint8_t target) /**< target */ +{ + return (ecma_CompletionValue_t) { .type = type, .value = value, .target = target }; +} /* ecma_MakeCompletionValue */ + +/** + * @} + * @} + */ diff --git a/src/libecmaobjects/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c index 65a9497ce..4ae5be949 100644 --- a/src/libecmaobjects/ecma-helpers.c +++ b/src/libecmaobjects/ecma-helpers.c @@ -20,10 +20,6 @@ * @{ */ -/** - * Implementation of helpers for operations with ECMA data types - */ - #include "ecma-alloc.h" #include "ecma-globals.h" #include "ecma-helpers.h" @@ -94,8 +90,8 @@ ecma_CreateObject( ecma_Object_t *pPrototypeObject, /**< pointer to prototybe of * (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); + pObject->u.m_Object.m_Extensible = isExtensible; + ecma_SetPointer( pObject->u.m_Object.m_pPrototypeObject, pPrototypeObject); return pObject; } /* ecma_CreateObject */ @@ -119,14 +115,14 @@ ecma_CreateLexicalEnvironment(ecma_Object_t *pOuterLexicalEnvironment, /**< oute ecma_Object_t *pNewLexicalEnvironment = ecma_AllocObject(); pNewLexicalEnvironment->m_IsLexicalEnvironment = true; - pNewLexicalEnvironment->u_Attributes.m_LexicalEnvironment.m_Type = type; + pNewLexicalEnvironment->u.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); + ecma_SetPointer( pNewLexicalEnvironment->u.m_LexicalEnvironment.m_pOuterReference, pOuterLexicalEnvironment); return pNewLexicalEnvironment; } /* ecma_CreateLexicalEnvironment */ @@ -157,7 +153,7 @@ ecma_CreateInternalProperty(ecma_Object_t *pObject, /**< the object */ /** * Find internal property in the object's property set. * - * @return pointer to the property's descriptor, if it is found, + * @return pointer to the property, if it is found, * NULL - otherwise. */ ecma_Property_t* @@ -204,6 +200,47 @@ ecma_GetInternalProperty(ecma_Object_t *pObject, /**< object descriptor */ return pProperty; } /* ecma_GetInternalProperty */ +/** + * Find named data property or named access property in specified object. + * + * @return pointer to the property, if it is found, + * NULL - otherwise. + */ +ecma_Property_t* +ecma_FindNamedProperty(ecma_Object_t *obj_p, /**< object to find property in */ + ecma_Char_t *string_p) /**< property's name */ +{ + JERRY_ASSERT( obj_p != NULL ); + JERRY_ASSERT( string_p != NULL ); + + for ( ecma_Property_t *property_p = ecma_GetPointer( obj_p->m_pProperties); + property_p != NULL; + property_p = ecma_GetPointer( property_p->m_pNextProperty) ) + { + ecma_ArrayFirstChunk_t *property_name_p; + + if ( property_p->m_Type == ECMA_PROPERTY_NAMEDDATA ) + { + property_name_p = ecma_GetPointer( property_p->u.m_NamedDataProperty.m_pName); + } else if ( property_p->m_Type == ECMA_PROPERTY_NAMEDACCESSOR ) + { + property_name_p = ecma_GetPointer( property_p->u.m_NamedAccessorProperty.m_pName); + } else + { + continue; + } + + JERRY_ASSERT( property_name_p != NULL ); + + if ( ecma_CompareCharBufferToEcmaString( string_p, property_name_p) ) + { + return property_p; + } + } + + return NULL; +} /* ecma_FindNamedProperty */ + /** * Allocate new ecma-string and fill it with characters from specified buffer * diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index fe13dda2d..21e438a59 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -41,6 +41,15 @@ extern void* ecma_DecompressPointer(uintptr_t compressedPointer); #define ecma_SetPointer( field, nonCompressedPointer) \ (field) = ecma_CompressPointer( nonCompressedPointer) & ( ( 1u << ECMA_POINTER_FIELD_WIDTH ) - 1) +extern ecma_Value_t ecma_MakeSimpleValue( ecma_SimpleValue_t value); +extern ecma_Value_t ecma_MakeObjectValue( ecma_Object_t* object_p); +extern ecma_CompletionValue_t ecma_MakeCompletionValue( ecma_CompletionType_t type, ecma_Value_t value, uint8_t target); + +extern bool ecma_IsUndefinedValue( ecma_Value_t value); +extern bool ecma_IsNullValue( ecma_Value_t value); +extern bool ecma_IsBooleanValue( ecma_Value_t value); +extern bool ecma_IsValueTrue( ecma_Value_t value); + 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); @@ -49,6 +58,8 @@ extern ecma_Property_t* ecma_FindInternalProperty(ecma_Object_t *pObject, ecma_I 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_Property_t *ecma_FindNamedProperty(ecma_Object_t *obj_p, ecma_Char_t *string_p); + 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); @@ -61,4 +72,4 @@ extern void ecma_FreeArray( ecma_ArrayFirstChunk_t *pFirstChunk); /** * @} * @} - */ \ No newline at end of file + */ diff --git a/src/libecmaobjects/ecma-reference.h b/src/libecmaobjects/ecma-reference.h index 89c4f8035..28efde2dd 100644 --- a/src/libecmaobjects/ecma-reference.h +++ b/src/libecmaobjects/ecma-reference.h @@ -21,37 +21,10 @@ */ /** - * \addtogroup syntacticreference Textual reference to variable/property + * \addtogroup reference ECMA-reference * @{ */ -/** - * 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. - */ - unsigned int m_IsPropertyReference : 1; - - /** - * Flag indicating that this reference is strict (see also: ECMA-262 v5, 8.7). - */ - unsigned int 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; /** * @} diff --git a/src/libecmaoperations/ecma-get-put-value.c b/src/libecmaoperations/ecma-get-put-value.c new file mode 100644 index 000000000..15ff799cb --- /dev/null +++ b/src/libecmaoperations/ecma-get-put-value.c @@ -0,0 +1,101 @@ +/* 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. + */ + +/** + * Implementation of ECMA GetValue and PutValue + */ + +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-operations.h" + +/** \addtogroup ecma ---TODO--- + * @{ + * + * \addtogroup ecmaoperations ECMA-defined operations + * @{ + */ + +/** + * Resolve syntactic reference to ECMA-reference. + * + * Warning: string pointed by name_p + * must not be freed or reused + * until the reference is freed. + * + * @return ECMA-reference (if base value is an object, upon return + * it's reference counter is increased by one). + */ +ecma_Reference_t +ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p, /**< identifier's name */ + bool is_strict) /**< strict reference flag */ +{ + JERRY_ASSERT( lex_env_p != NULL ); + + ecma_Object_t *lex_env_iter_p = lex_env_p; + + while ( lex_env_iter_p != NULL ) + { + ecma_CompletionValue_t completion_value; + completion_value = ecma_OpHasBinding( lex_env_iter_p, name_p); + + JERRY_ASSERT( completion_value.type == ECMA_COMPLETION_TYPE_NORMAL ); + + if ( ecma_IsValueTrue( completion_value.value) ) + { + ecma_RefObject( lex_env_iter_p); + + return (ecma_Reference_t) { .base = ecma_MakeObjectValue( lex_env_iter_p), + .referenced_name_p = name_p, + .is_strict = is_strict }; + } + + lex_env_iter_p = ecma_GetPointer( lex_env_iter_p->u.m_LexicalEnvironment.m_pOuterReference); + } + + return (ecma_Reference_t) { .base = ecma_MakeObjectValue( NULL), + .referenced_name_p = NULL, + .is_strict = is_strict }; +} /* ecma_OpGetIdentifierReference */ + +/** + * GetValue operation. + * + * See also: ECMA-262 v5, 8.7.1 + */ +ecma_CompletionValue_t +ecma_OpGetValue( ecma_Reference_t *ref_p) /**< ECMA-reference */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( ref_p); +} /* ecma_OpGetValue */ + +/** + * SetValue operation. + * + * See also: ECMA-262 v5, 8.7.1 + */ +ecma_CompletionValue_t +ecma_OpSetValue(ecma_Reference_t *ref_p, /**< ECMA-reference */ + ecma_Value_t value) /**< ECMA-value */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( ref_p, value); +} /* ecma_OpSetValue */ + +/** + * @} + * @} + */ diff --git a/src/libecmaoperations/ecma-lex-env.c b/src/libecmaoperations/ecma-lex-env.c new file mode 100644 index 000000000..be79fcbe5 --- /dev/null +++ b/src/libecmaoperations/ecma-lex-env.c @@ -0,0 +1,153 @@ +/* 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 "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "globals.h" + +/** \addtogroup ecma ---TODO--- + * @{ + */ + +/** + * \addtogroup lexicalenvironment Lexical environment + * @{ + */ + +/** + * HasBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpHasBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p) /**< argument N */ +{ + JERRY_ASSERT( lex_env_p != NULL && lex_env_p->m_IsLexicalEnvironment ); + + ecma_SimpleValue_t has_binding = ECMA_SIMPLE_VALUE_UNDEFINED; + + switch ( (ecma_LexicalEnvironmentType_t) lex_env_p->u.m_LexicalEnvironment.m_Type ) + { + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_Property_t *property_p = ecma_FindNamedProperty( lex_env_p, name_p); + + has_binding = ( property_p != NULL ) ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE; + } + case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND: + { + JERRY_UNIMPLEMENTED(); + } + } + + return ecma_MakeCompletionValue(ECMA_COMPLETION_TYPE_NORMAL, + ecma_MakeSimpleValue( has_binding), + ECMA_TARGET_ID_RESERVED); +} /* ecma_OpHasBinding */ + +/** + * CreateMutableBinding operation. + * + * see also: ecma-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpCreateMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p, /**< argument N */ + bool is_deletable) /**< argument D */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p, is_deletable); +} /* ecma_OpCreateMutableBinding */ + +/** + * SetMutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpSetMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p, /**< argument N */ + ecma_Value_t value, /**< argument V */ + bool is_strict) /**< argument S */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p, value, is_strict); +} /* ecma_OpSetMutableBinding */ + +/** + * GetBindingValue operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpGetBindingValue(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p, /**< argument N */ + bool is_strict) /**< argument S */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p, is_strict); +} /* ecma_OpGetBindingValue */ + +/** + * DeleteBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpDeleteBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p) /**< argument N */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p); +} /* ecma_OpDeleteBinding */ + +/** + * ImplicitThisValue operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpImplicitThisValue( ecma_Object_t *lex_env_p) /**< lexical environment */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p); +} /* ecma_OpImplicitThisValue */ + +/** + * CreateImmutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpCreateImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p) /**< argument N */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p); +} /* ecma_OpCreateImmutableBinding */ + +/** + * InitializeImmutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +ecma_CompletionValue_t +ecma_OpInitializeImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */ + ecma_Char_t *name_p, /**< argument N */ + ecma_Value_t value) /**< argument V */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( lex_env_p, name_p, value); +} /* ecma_OpInitializeImmutableBinding */ + +/** + * @} + * @} + */ diff --git a/src/libecmaoperations/ecma-lex-env.h b/src/libecmaoperations/ecma-lex-env.h new file mode 100644 index 000000000..c1768bfe6 --- /dev/null +++ b/src/libecmaoperations/ecma-lex-env.h @@ -0,0 +1,48 @@ +/* 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_LEX_ENV_H +#define ECMA_LEX_ENV_H + +#include "ecma-globals.h" +#include "globals.h" + +/** \addtogroup ecma ---TODO--- + * @{ + */ + +/** + * \addtogroup lexicalenvironment Lexical environment + * @{ + */ + +/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */ +extern ecma_CompletionValue_t ecma_OpHasBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p); +extern ecma_CompletionValue_t ecma_OpCreateMutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, bool is_deletable); +extern ecma_CompletionValue_t ecma_OpSetMutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, ecma_Value_t value, bool is_strict); +extern ecma_CompletionValue_t ecma_OpGetBindingValue( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, bool is_strict); +extern ecma_CompletionValue_t ecma_OpDeleteBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p); +extern ecma_CompletionValue_t ecma_OpImplicitThisValue( ecma_Object_t *lex_env_p); + +/* ECMA-262 v5, Table 18. Additional methods of Declarative Environment Records */ +extern ecma_CompletionValue_t ecma_OpCreateImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p); +extern ecma_CompletionValue_t ecma_OpInitializeImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, ecma_Value_t value); + +/** + * @} + * @} + */ + +#endif /* !ECMA_LEX_ENV_H */ diff --git a/src/libecmaoperations/ecma-operations.h b/src/libecmaoperations/ecma-operations.h index 5600335e6..56b7c7c27 100644 --- a/src/libecmaoperations/ecma-operations.h +++ b/src/libecmaoperations/ecma-operations.h @@ -26,8 +26,10 @@ #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); +extern ecma_Reference_t ecma_OpGetIdentifierReference( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, bool is_strict); + +extern ecma_CompletionValue_t ecma_OpGetValue( ecma_Reference_t *ref_p); +extern ecma_CompletionValue_t ecma_OpSetValue( ecma_Reference_t *ref_p, ecma_Value_t value); /** * @}