diff --git a/src/error.h b/src/error.h deleted file mode 100644 index f5461aab7..000000000 --- a/src/error.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ERROR_H -#define ERROR_H - -#include "mappings.h" - -void fatal (int); - -#define ERR_IO (-1) -#define ERR_BUFFER_SIZE (-2) -#define ERR_SEVERAL_FILES (-3) -#define ERR_NO_FILES (-4) -#define ERR_NON_CHAR (-5) -#define ERR_UNCLOSED (-6) -#define ERR_INT_LITERAL (-7) -#define ERR_STRING (-8) -#define ERR_PARSER (-9) - -#endif /* ERROR_H */ \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index c70b1beb5..8fb6b4090 100644 --- a/src/globals.h +++ b/src/globals.h @@ -16,15 +16,12 @@ #ifndef JERRY_GLOBALS_H #define JERRY_GLOBALS_H -#include -#include - /** * Types */ typedef unsigned long mword_t; typedef mword_t uintptr_t; -//typedef mword_t size_t; +typedef mword_t size_t; typedef signed long ssize_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; @@ -32,6 +29,10 @@ typedef unsigned int uint32_t; typedef unsigned long long uint64_t; typedef signed int int32_t; +typedef enum { + false, true +} bool; + /** * Attributes */ @@ -42,9 +43,24 @@ typedef signed int int32_t; /** * Constants */ +#define NULL ((void*)0) #define JERRY_BITSINBYTE 8 +/** + * Errors + */ +#define ERR_IO (-1) +#define ERR_BUFFER_SIZE (-2) +#define ERR_SEVERAL_FILES (-3) +#define ERR_NO_FILES (-4) +#define ERR_NON_CHAR (-5) +#define ERR_UNCLOSED (-6) +#define ERR_INT_LITERAL (-7) +#define ERR_STRING (-8) +#define ERR_PARSER (-9) +#define ERR_GENERAL (-255) + /** * Asserts * diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 1278f4ae3..e942d8bc6 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -16,12 +16,6 @@ #ifndef INTERPRETER_H #define INTERPRETER_H -#ifdef JERRY_NDEBUG -#include -#include -#include -#endif - #include "opcodes.h" #include "ecma-globals.h" diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index cbfe6212e..0d60317d8 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -14,8 +14,8 @@ */ #include "ecma-operations.h" -#include "error.h" #include "interpreter.h" +#include "jerry-libc.h" #include "opcodes.h" void @@ -90,7 +90,7 @@ void opfunc_loop_inf (OPCODE opdata, struct __int_data *int_data) { #ifdef __HOST - printf ("%d::loop_inf:idx:%d\n", + __printf ("%d::loop_inf:idx:%d\n", int_data->pos, opdata.data.loop_inf.loop_root); #endif @@ -102,7 +102,7 @@ void opfunc_call_1 (OPCODE opdata, struct __int_data *int_data) { #ifdef __HOST - printf ("%d::op_call_1:idx:%d:%d\n", + __printf ("%d::op_call_1:idx:%d:%d\n", int_data->pos, opdata.data.call_1.name_lit_idx, opdata.data.call_1.arg1_lit_idx); @@ -115,7 +115,7 @@ void opfunc_jmp (OPCODE opdata, struct __int_data *int_data) { #ifdef __HOST - printf ("%d::op_jmp:idx:%d\n", + __printf ("%d::op_jmp:idx:%d\n", int_data->pos, opdata.data.jmp.opcode_idx); #endif diff --git a/src/libcoreint/opcodes.h b/src/libcoreint/opcodes.h index cf0c3216e..4af8a7e41 100644 --- a/src/libcoreint/opcodes.h +++ b/src/libcoreint/opcodes.h @@ -16,10 +16,6 @@ #ifndef OPCODES_H #define OPCODES_H -#ifdef JERRY_NDEBUG -#include -#endif - #include "globals.h" #define OPCODE struct __opcode diff --git a/src/libjsparser/lexer.c b/src/libjsparser/lexer.c index 69d1e8e32..47578c945 100644 --- a/src/libjsparser/lexer.c +++ b/src/libjsparser/lexer.c @@ -13,13 +13,15 @@ * limitations under the License. */ -#include "error.h" +#include "jerry-libc.h" #include "lexer.h" -#include "mappings.h" static token saved_token; static token empty_token = { .type = TOK_EMPTY, .data.none = NULL }; +/* FIXME: Make general fatal function call it from libjsparser's fatal */ +extern void fatal(int); + typedef struct { const char *str; @@ -117,7 +119,7 @@ get_char (size_t i) if (error == 0) return '\0'; if (error < BUFFER_SIZE) - memset (buffer + error, '\0', BUFFER_SIZE - error); + __memset (buffer + error, '\0', BUFFER_SIZE - error); buffer_start = buffer; } @@ -141,7 +143,7 @@ get_char (size_t i) if (error == 0) return '\0'; if (error < BUFFER_SIZE - tail_size - token_size) - memset (buffer + tail_size + error, '\0', + __memset (buffer + tail_size + error, '\0', BUFFER_SIZE - tail_size - token_size - error); } else @@ -152,7 +154,7 @@ get_char (size_t i) if (error == 0) return '\0'; if (error < BUFFER_SIZE - tail_size) - memset (buffer + tail_size + error, '\0', BUFFER_SIZE - tail_size - error); + __memset (buffer + tail_size + error, '\0', BUFFER_SIZE - tail_size - error); } } @@ -182,7 +184,7 @@ decode_keyword (void) for (i = 0; i < size; i++) { - if (!strncmp (keyword_tokens[i].str, token_start, strlen (keyword_tokens[i].str))) + if (!__strncmp (keyword_tokens[i].str, token_start, __strlen (keyword_tokens[i].str))) return keyword_tokens[i].tok; } @@ -196,7 +198,7 @@ convert_seen_name_to_token (void) for (i = 0; i < seen_names_num; i++) { - if (!strncmp (seen_names[i].str, token_start, strlen (seen_names[i].str))) + if (!__strncmp (seen_names[i].str, token_start, __strlen (seen_names[i].str))) return seen_names[i].tok; } @@ -233,7 +235,7 @@ current_token (void) JERRY_ASSERT (token_start <= buffer); size_t length = (size_t) (buffer - token_start); char *res = (char *) malloc (length + 1); - strncpy (res, token_start, length); + __strncpy (res, token_start, length); res[length] = '\0'; token_start = NULL; return res; @@ -278,11 +280,11 @@ static token parse_name (void) { char c = LA (0); - bool every_char_islower = islower (c); + bool every_char_islower = __islower (c); const char *string = NULL; token known_token = empty_token; - JERRY_ASSERT (isalpha (c) || c == '$' || c == '_'); + JERRY_ASSERT (__isalpha (c) || c == '$' || c == '_'); new_token (); consume_char (); @@ -291,9 +293,9 @@ parse_name (void) c = LA (0); if (c == '\0') c = c; - if (!isalpha (c) && !isdigit (c) && c != '$' && c != '_') + if (!__isalpha (c) && !__isdigit (c) && c != '$' && c != '_') break; - if (every_char_islower && (!islower (c))) + if (every_char_islower && (!__islower (c))) every_char_islower = false; consume_char (); } @@ -366,7 +368,7 @@ parse_number (void) size_t tok_length = 0, i; int res = 0; - JERRY_ASSERT (isdigit (c) || c == '.'); + JERRY_ASSERT (__isdigit (c) || c == '.'); if (c == '0') if (LA (1) == 'x' || LA (1) == 'X') @@ -374,7 +376,7 @@ parse_number (void) if (c == '.') { - JERRY_ASSERT (!isalpha (LA (1))); + JERRY_ASSERT (!__isalpha (LA (1))); is_fp = true; } @@ -387,12 +389,12 @@ parse_number (void) while (true) { c = LA (0); - if (!isxdigit (c)) + if (!__isxdigit (c)) break; consume_char (); } - if (isalpha (c) || c == '_' || c == '$') + if (__isalpha (c) || c == '_' || c == '$') fatal (ERR_INT_LITERAL); tok_length = (size_t) (buffer - token_start); @@ -422,7 +424,7 @@ parse_number (void) if (c == '.') { - if (isalpha (LA (1)) || LA (1) == '_' || LA (1) == '$') + if (__isalpha (LA (1)) || LA (1) == '_' || LA (1) == '$') fatal (ERR_INT_LITERAL); is_fp = true; consume_char (); @@ -433,17 +435,17 @@ parse_number (void) { if (LA (1) == '-' || LA (1) == '+') consume_char (); - if (!isdigit (LA (1))) + if (!__isdigit (LA (1))) fatal (ERR_INT_LITERAL); is_exp = true; consume_char (); continue; } - if (isalpha (c) || c == '_' || c == '$') + if (__isalpha (c) || c == '_' || c == '$') fatal (ERR_INT_LITERAL); - if (!isdigit (c)) + if (!__isdigit (c)) break; consume_char (); @@ -451,7 +453,7 @@ parse_number (void) if (is_fp || is_exp) { - float res = strtof (token_start, NULL); + float res = __strtof (token_start, NULL); token_start = NULL; return (token) { .type = TOK_FLOAT, .data.fp_num = res }; } @@ -512,7 +514,7 @@ parse_string (void) if (c == '\\') { /* Only single escape character is allowed. */ - if (LA (1) == 'x' || LA (1) == 'u' || isdigit (LA (1))) + if (LA (1) == 'x' || LA (1) == 'u' || __isdigit (LA (1))) fatal (ERR_STRING); if ((LA (1) == '\'' && !is_double_quoted) || (LA (1) == '"' && is_double_quoted) @@ -553,7 +555,7 @@ parse_string (void) index++; } - memset (index, '\0', length - (size_t) (index - tok)); + __memset (index, '\0', length - (index - tok)); token_start = NULL; // Eat up '"' @@ -571,7 +573,7 @@ grobble_whitespaces (void) { char c = LA (0); - while ((isspace (c) && c != '\n') || c == '\0') + while ((__isspace (c) && c != '\n') || c == '\0') { consume_char (); c = LA (0); @@ -653,10 +655,10 @@ lexer_next_token (void) JERRY_ASSERT (token_start == NULL); - if (isalpha (c) || c == '$' || c == '_') + if (__isalpha (c) || c == '$' || c == '_') return parse_name (); - if (isdigit (c) || (c == '.' && isdigit (LA (1)))) + if (__isdigit (c) || (c == '.' && __isdigit (LA (1)))) return parse_number (); if (c == '\n') @@ -671,7 +673,7 @@ lexer_next_token (void) if (c == '\'' || c == '"') return parse_string (); - if (isspace (c)) + if (__isspace (c)) { grobble_whitespaces (); return @@ -803,5 +805,5 @@ lexer_save_token (token tok) void lexer_dump_buffer_state (void) { - printf ("%s\n", buffer); + __printf ("%s\n", buffer); } \ No newline at end of file diff --git a/src/libjsparser/lexer.h b/src/libjsparser/lexer.h index 2c30ad288..ee3893e0d 100644 --- a/src/libjsparser/lexer.h +++ b/src/libjsparser/lexer.h @@ -16,7 +16,7 @@ #ifndef LEXER_H #define LEXER_H -#include "mappings.h" +#include "globals.h" /* Keywords. */ typedef enum diff --git a/src/libjsparser/mappings.h b/src/libjsparser/mappings.h deleted file mode 100644 index ffcbc76f1..000000000 --- a/src/libjsparser/mappings.h +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MAPPINGS_H -#define MAPPINGS_H - -#ifndef __HOST -#include "jerry-libc.h" -#include "allocator.h" -#include - -static inline void * -memset (void *s, int n1, size_t n2) -{ - return __memset (s, n1, n2); -} - -static inline int -memcmp (const void *s1, const void *s2, size_t n) -{ - return __memcmp (s1, s2, n); -} - -static inline void * -memcpy (void *s1, const void *s2, size_t n) -{ - return __memcpy (s1, s2, n); -} - -static inline int -printf (const char *s, ...) -{ - va_list args; - va_start (args, s); - int ret = __printf (s, args); - va_end (args); - return ret; -} - -static inline int -putchar (int c) -{ - return __putchar (c); -} - -static inline void -exit (int status) -{ - __exit (status); -} - -static inline int -strcmp (const char *s1, const char *s2) -{ - return __strcmp (s1, s2); -} - -static inline int -strncmp (const char *s1, const char *s2, size_t n) -{ - return __strncmp (s1, s2, n); -} - -static inline char * -strncpy (char *s1, const char *s2, size_t n) -{ - return __strncpy (s1, s2, n); -} - -static inline float -strtof (const char *s1, char **s2) -{ - return __strtof (s1, s2); -} - -static inline size_t -strlen (const char *s) -{ - return __strlen (s); -} - -static inline int -isspace (int s) -{ - return __isspace (s); -} - -static inline int -isupper (int s) -{ - return __isupper (s); -} - -static inline int -islower (int s) -{ - return __islower (s); -} - -static inline int -isalpha (int s) -{ - return __isalpha (s); -} - -static inline int -isdigit (int s) -{ - return __isdigit (s); -} - -static inline int -isxdigit (int s) -{ - return __isxdigit (s); -} - -#else -#undef NULL -#include "../globals.h" -#include -#include -#include -#include -#endif - -#endif // MAPPINGS_H diff --git a/src/libjsparser/parser.c b/src/libjsparser/parser.c index 62f6a6693..10a359726 100644 --- a/src/libjsparser/parser.c +++ b/src/libjsparser/parser.c @@ -13,20 +13,20 @@ * limitations under the License. */ -#include "parser.h" -#include "error.h" +#include "jerry-libc.h" #include "lexer.h" -#include "error.h" - -extern void lexer_dump_buffer_state (void); +#include "parser.h" +/* FIXME: */ +extern void lexer_dump_buffer_state(); +/* FIXME: Make general fatal function call it from libjsparser's fatal */ void fatal (int code) { - printf ("FATAL: %d\n", code); + __printf ("FATAL: %d\n", code); lexer_dump_buffer_state (); JERRY_UNREACHABLE (); - exit (code); + __exit( -code); } bool diff --git a/src/libjsparser/parser.h b/src/libjsparser/parser.h index d08d7c0c7..df45c22e2 100644 --- a/src/libjsparser/parser.h +++ b/src/libjsparser/parser.h @@ -16,7 +16,7 @@ #ifndef PARSER_H #define PARSER_H -#include "mappings.h" +#include "globals.h" struct source_element_list; struct statement_list; diff --git a/src/libperipherals/actuators.c b/src/libperipherals/actuators.c index 1c3472b9b..1fa50043a 100644 --- a/src/libperipherals/actuators.c +++ b/src/libperipherals/actuators.c @@ -13,21 +13,20 @@ * limitations under the License. */ -#include - #include "actuators.h" +#include "jerry-libc.h" void led_toggle(int led_id) { - printf("led_toogle: %d", led_id); + __printf("led_toogle: %d", led_id); } void led_on(int led_id) { - printf("led_on: %d", led_id); + __printf("led_on: %d", led_id); } void led_off(int led_id) { - printf("led_off: %d", led_id); + __printf("led_off: %d", led_id); } diff --git a/src/libruntime/jerry-libc.c b/src/libruntime/jerry-libc.c index 94922f0b8..99f9bab1e 100644 --- a/src/libruntime/jerry-libc.c +++ b/src/libruntime/jerry-libc.c @@ -14,16 +14,11 @@ */ /** - * Jerry libc implementation + * Jerry libc's common functions implementation */ #include "jerry-libc.h" -#include - -extern int vprintf (__const char *__restrict __format, __builtin_va_list __arg); -extern void __noreturn exit(int status); - /** * memset * @@ -89,40 +84,6 @@ __memcpy(void *s1, /**< destination */ return s1; } /* __memcpy */ -/** - * printf - * - * @return number of characters printed - */ -int -__printf(const char *format, /**< format string */ - ...) /**< parameters' values */ -{ - va_list args; - - va_start( args, format); - - int ret = vprintf( format, args); - - va_end( args); - - return ret; -} /* __printf */ - -/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */ -int -__putchar (int c) -{ - return __printf ("%c", c); -} - -/** exit - cause normal process termination */ -void __noreturn -__exit (int status) -{ - exit( status); -} - /** Compare two strings. return an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. */ int diff --git a/src/libruntime/jerry-libc.h b/src/libruntime/jerry-libc.h index 9834e24ef..3d85a1cc3 100644 --- a/src/libruntime/jerry-libc.h +++ b/src/libruntime/jerry-libc.h @@ -21,6 +21,8 @@ #include "globals.h" +typedef void FILE; + extern void *__memset (void *s, int c, size_t n); extern int __memcmp (const void *s1, const void *s2, size_t n); extern void *__memcpy (void *s1, const void *s2, size_t n); @@ -41,6 +43,11 @@ extern int __isalpha (int); extern int __isdigit (int); extern int __isxdigit (int); +extern FILE* __fopen(const char *path, const char *mode); +extern int __fclose(FILE *fp); +extern size_t __fread(void *ptr, size_t size, size_t nmemb, FILE *stream); +extern size_t __fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); + #define DBL_MANT_DIG ( 52) #define DBL_DIG ( 10) #define DBL_MIN_EXP (-324) diff --git a/src/libruntime/linux/jerry-assert.c b/src/libruntime/linux/jerry-assert.c index c947f3b21..6d0d84458 100644 --- a/src/libruntime/linux/jerry-assert.c +++ b/src/libruntime/linux/jerry-assert.c @@ -27,5 +27,5 @@ jerry_AssertFail( const char *assertion, /**< assertion condition string */ __printf("Assertion '%s' failed at %s:%u\n", assertion, file, line); - __exit( 1); + __exit( -ERR_GENERAL); } /* jerry_AssertFail */ diff --git a/src/libruntime/pretty-printer.c b/src/libruntime/pretty-printer.c index 6ad6d151a..5a8ab75b2 100644 --- a/src/libruntime/pretty-printer.c +++ b/src/libruntime/pretty-printer.c @@ -13,8 +13,8 @@ * limitations under the License. */ +#include "jerry-libc.h" #include "pretty-printer.h" -#include "error.h" static int intendation; static bool was_function_expression; @@ -35,11 +35,11 @@ pp_token (token tok) switch (tok.type) { case TOK_NAME: - printf ("IDENTIFIER (%s)\n", tok.data.name); + __printf ("IDENTIFIER (%s)\n", tok.data.name); break; case TOK_STRING: - printf ("STRING (%s)\n", tok.data.str); + __printf ("STRING (%s)\n", tok.data.str); break; case TOK_KEYWORD: @@ -47,227 +47,227 @@ pp_token (token tok) break; case TOK_INT: - printf ("INTEGER (%d)\n", tok.data.num); + __printf ("INTEGER (%d)\n", tok.data.num); break; case TOK_FLOAT: - printf ("FLOAT (%f)\n", tok.data.fp_num); + __printf ("FLOAT (%f)\n", tok.data.fp_num); break; case TOK_NULL: - printf ("NULL (null)\n"); + __printf ("NULL (null)\n"); break; case TOK_BOOL: if (tok.data.is_true) - printf ("BOOL (true)\n"); + __printf ("BOOL (true)\n"); else - printf ("BOOL (false)\n"); + __printf ("BOOL (false)\n"); break; case TOK_OPEN_BRACE: - printf ("PUNC ({)\n"); + __printf ("PUNC ({)\n"); break; case TOK_CLOSE_BRACE: - printf ("PUNC (})\n"); + __printf ("PUNC (})\n"); break; case TOK_OPEN_PAREN: - printf ("PUNC (()\n"); + __printf ("PUNC (()\n"); break; case TOK_CLOSE_PAREN: - printf ("PUNC ())\n"); + __printf ("PUNC ())\n"); break; case TOK_OPEN_SQUARE: - printf ("PUNC ([)\n"); + __printf ("PUNC ([)\n"); break; case TOK_CLOSE_SQUARE: - printf ("PUNC (])\n"); + __printf ("PUNC (])\n"); break; case TOK_DOT: - printf ("PUNC (.)\n"); + __printf ("PUNC (.)\n"); break; case TOK_SEMICOLON: - printf ("PUNC (;)\n"); + __printf ("PUNC (;)\n"); break; case TOK_COMMA: - printf ("PUNC (,)\n"); + __printf ("PUNC (,)\n"); break; case TOK_LESS: - printf ("PUNC (<)\n"); + __printf ("PUNC (<)\n"); break; case TOK_GREATER: - printf ("PUNC (>)\n"); + __printf ("PUNC (>)\n"); break; case TOK_LESS_EQ: - printf ("PUNC (<=)\n"); + __printf ("PUNC (<=)\n"); break; case TOK_GREATER_EQ: - printf ("PUNC (>=)\n"); + __printf ("PUNC (>=)\n"); break; case TOK_DOUBLE_EQ: - printf ("PUNC (==)\n"); + __printf ("PUNC (==)\n"); break; case TOK_NOT_EQ: - printf ("PUNC (!=)\n"); + __printf ("PUNC (!=)\n"); break; case TOK_TRIPLE_EQ: - printf ("PUNC (===)\n"); + __printf ("PUNC (===)\n"); break; case TOK_NOT_DOUBLE_EQ: - printf ("PUNC (!==)\n"); + __printf ("PUNC (!==)\n"); break; case TOK_PLUS: - printf ("PUNC (+)\n"); + __printf ("PUNC (+)\n"); break; case TOK_MINUS: - printf ("PUNC (-)\n"); + __printf ("PUNC (-)\n"); break; case TOK_MULT: - printf ("PUNC (*)\n"); + __printf ("PUNC (*)\n"); break; case TOK_MOD: - printf ("PUNC (%%)\n"); + __printf ("PUNC (%%)\n"); break; case TOK_DOUBLE_PLUS: - printf ("PUNC (++)\n"); + __printf ("PUNC (++)\n"); break; case TOK_DOUBLE_MINUS: - printf ("PUNC (--)\n"); + __printf ("PUNC (--)\n"); break; case TOK_LSHIFT: - printf ("PUNC (<<)\n"); + __printf ("PUNC (<<)\n"); break; case TOK_RSHIFT: - printf ("PUNC (>>)\n"); + __printf ("PUNC (>>)\n"); break; case TOK_RSHIFT_EX: - printf ("PUNC (>>>)\n"); + __printf ("PUNC (>>>)\n"); break; case TOK_AND: - printf ("PUNC (&)\n"); + __printf ("PUNC (&)\n"); break; case TOK_OR: - printf ("PUNC (|)\n"); + __printf ("PUNC (|)\n"); break; case TOK_XOR: - printf ("PUNC (^)\n"); + __printf ("PUNC (^)\n"); break; case TOK_NOT: - printf ("PUNC (!)\n"); + __printf ("PUNC (!)\n"); break; case TOK_COMPL: - printf ("PUNC (~)\n"); + __printf ("PUNC (~)\n"); break; case TOK_DOUBLE_AND: - printf ("PUNC (&&)\n"); + __printf ("PUNC (&&)\n"); break; case TOK_DOUBLE_OR: - printf ("PUNC (||)\n"); + __printf ("PUNC (||)\n"); break; case TOK_QUERY: - printf ("PUNC (?)\n"); + __printf ("PUNC (?)\n"); break; case TOK_COLON: - printf ("PUNC (:)\n"); + __printf ("PUNC (:)\n"); break; case TOK_EQ: - printf ("PUNC (=)\n"); + __printf ("PUNC (=)\n"); break; case TOK_PLUS_EQ: - printf ("PUNC (+=)\n"); + __printf ("PUNC (+=)\n"); break; case TOK_MINUS_EQ: - printf ("PUNC (-=)\n"); + __printf ("PUNC (-=)\n"); break; case TOK_MULT_EQ: - printf ("PUNC (*=)\n"); + __printf ("PUNC (*=)\n"); break; case TOK_MOD_EQ: - printf ("PUNC (%%=)\n"); + __printf ("PUNC (%%=)\n"); break; case TOK_LSHIFT_EQ: - printf ("PUNC (<<=)\n"); + __printf ("PUNC (<<=)\n"); break; case TOK_RSHIFT_EQ: - printf ("PUNC (>>=)\n"); + __printf ("PUNC (>>=)\n"); break; case TOK_RSHIFT_EX_EQ: - printf ("PUNC (>>>=)\n"); + __printf ("PUNC (>>>=)\n"); break; case TOK_AND_EQ: - printf ("PUNC (&=)\n"); + __printf ("PUNC (&=)\n"); break; case TOK_OR_EQ: - printf ("PUNC (|=)\n"); + __printf ("PUNC (|=)\n"); break; case TOK_XOR_EQ: - printf ("PUNC (^=)\n"); + __printf ("PUNC (^=)\n"); break; case TOK_DIV: - printf ("PUNC (/)\n"); + __printf ("PUNC (/)\n"); break; case TOK_DIV_EQ: - printf ("PUNC (/=)\n"); + __printf ("PUNC (/=)\n"); break; case TOK_NEWLINE: - printf ("NEWLINE\n"); + __printf ("NEWLINE\n"); break; default: @@ -286,115 +286,115 @@ pp_keyword (keyword kw) break; case KW_RESERVED: - printf ("KEYWORD RESERVED\n"); + __printf ("KEYWORD RESERVED\n"); break; case KW_BREAK: - printf ("KEYWORD (break)\n"); + __printf ("KEYWORD (break)\n"); break; case KW_CASE: - printf ("KEYWORD (case)\n"); + __printf ("KEYWORD (case)\n"); break; case KW_CATCH: - printf ("KEYWORD (catch)\n"); + __printf ("KEYWORD (catch)\n"); break; case KW_CONTINUE: - printf ("KEYWORD (continue)\n"); + __printf ("KEYWORD (continue)\n"); break; case KW_DEBUGGER: - printf ("KEYWORD (debugger)\n"); + __printf ("KEYWORD (debugger)\n"); break; case KW_DEFAULT: - printf ("KEYWORD (default)\n"); + __printf ("KEYWORD (default)\n"); break; case KW_DELETE: - printf ("KEYWORD (delete)\n"); + __printf ("KEYWORD (delete)\n"); break; case KW_DO: - printf ("KEYWORD (do)\n"); + __printf ("KEYWORD (do)\n"); break; case KW_ELSE: - printf ("KEYWORD (else)\n"); + __printf ("KEYWORD (else)\n"); break; case KW_FINALLY: - printf ("KEYWORD (finally)\n"); + __printf ("KEYWORD (finally)\n"); break; case KW_FOR: - printf ("KEYWORD (for)\n"); + __printf ("KEYWORD (for)\n"); break; case KW_FUNCTION: - printf ("KEYWORD (function)\n"); + __printf ("KEYWORD (function)\n"); break; case KW_IF: - printf ("KEYWORD (if)\n"); + __printf ("KEYWORD (if)\n"); break; case KW_IN: - printf ("KEYWORD (in)\n"); + __printf ("KEYWORD (in)\n"); break; case KW_INSTANCEOF: - printf ("KEYWORD (instanceof)\n"); + __printf ("KEYWORD (instanceof)\n"); break; case KW_NEW: - printf ("KEYWORD (new)\n"); + __printf ("KEYWORD (new)\n"); break; case KW_RETURN: - printf ("KEYWORD (return)\n"); + __printf ("KEYWORD (return)\n"); break; case KW_SWITCH: - printf ("KEYWORD (switch)\n"); + __printf ("KEYWORD (switch)\n"); break; case KW_THIS: - printf ("KEYWORD (this)\n"); + __printf ("KEYWORD (this)\n"); break; case KW_THROW: - printf ("KEYWORD (throw)\n"); + __printf ("KEYWORD (throw)\n"); break; case KW_TRY: - printf ("KEYWORD (try)\n"); + __printf ("KEYWORD (try)\n"); break; case KW_TYPEOF: - printf ("KEYWORD (typeof)\n"); + __printf ("KEYWORD (typeof)\n"); break; case KW_VAR: - printf ("KEYWORD (var)\n"); + __printf ("KEYWORD (var)\n"); break; case KW_VOID: - printf ("KEYWORD (void)\n"); + __printf ("KEYWORD (void)\n"); break; case KW_WHILE: - printf ("KEYWORD (while)\n"); + __printf ("KEYWORD (while)\n"); break; case KW_WITH: - printf ("KEYWORD (with)\n"); + __printf ("KEYWORD (with)\n"); break; default: @@ -404,10 +404,10 @@ pp_keyword (keyword kw) } static void -intend (void) +intend () { for (int i = 0; i < intendation; i++) - putchar (' '); + __putchar (' '); } static void @@ -420,20 +420,20 @@ pp_formal_parameter_list (formal_parameter_list param_list) if (param_list.names[i] == NULL) break; if (i != 0) - printf (", "); - printf ("%s", param_list.names[i]); + __printf (", "); + __printf ("%s", param_list.names[i]); } } static void pp_function_declaration (function_declaration func_decl) { - printf ("function "); + __printf ("function "); if (func_decl.name) - printf ("%s ", func_decl.name); - putchar ('('); + __printf ("%s ", func_decl.name); + __putchar ('('); pp_formal_parameter_list (func_decl.params); - printf (") "); + __printf (") "); was_function_expression = true; } @@ -443,19 +443,19 @@ pp_literal (literal lit) switch (lit.type) { case LIT_NULL: - printf ("null"); + __printf ("null"); break; case LIT_BOOL: - printf ("%s", lit.data.is_true ? "true" : "false"); + __printf ("%s", lit.data.is_true ? "true" : "false"); break; case LIT_INT: - printf ("%d", lit.data.num); + __printf ("%d", lit.data.num); break; case LIT_STR: - printf ("\"%s\"", lit.data.str); + __printf ("\"%s\"", lit.data.str); break; default: @@ -470,7 +470,7 @@ pp_operand (operand op) if (op.is_literal) pp_literal (op.data.lit); else - printf ("%s", op.data.name); + __printf ("%s", op.data.name); } static void @@ -483,7 +483,7 @@ pp_operand_list (operand_list list) if (is_operand_empty (list.ops[i])) break; if (i != 0) - printf (", "); + __printf (", "); pp_operand (list.ops[i]); } } @@ -493,7 +493,7 @@ pp_property (property prop) { JERRY_ASSERT (!is_property_empty (prop)); pp_operand (prop.name); - printf (" : "); + __printf (" : "); pp_operand (prop.value); } @@ -507,7 +507,7 @@ pp_property_list (property_list prop_list) if (is_property_empty (prop_list.props[i])) break; if (i != 0) - printf (", "); + __printf (", "); pp_property (prop_list.props[i]); } } @@ -516,40 +516,40 @@ static void pp_call_expression (call_expression expr) { JERRY_ASSERT (expr.name); - printf ("%s (", expr.name); + __printf ("%s (", expr.name); pp_operand_list (expr.args); - printf (")\n"); + __printf (")\n"); } static void dump_two_operands (operand_pair pair, const char *operation) { pp_operand (pair.op1); - printf ("%s", operation); + __printf ("%s", operation); pp_operand (pair.op2); - putchar ('\n'); + __putchar ('\n'); } static void dump_unary (operand op, const char *operation) { - printf ("%s", operation); + __printf ("%s", operation); pp_operand (op); - putchar ('\n'); + __putchar ('\n'); } static void dump_postfix (operand op, const char *operation) { pp_operand (op); - printf ("%s\n", operation); + __printf ("%s\n", operation); } static void pp_assignment_expression (assignment_expression expr) { - if (expr.oper != AO_NONE && expr.var) - printf ("%s", expr.var); + if (expr.var) + __printf ("%s", expr.var); switch (expr.oper) { @@ -557,51 +557,51 @@ pp_assignment_expression (assignment_expression expr) break; case AO_EQ: - printf (" = "); + __printf (" = "); break; case AO_MULT_EQ: - printf (" *= "); + __printf (" *= "); break; case AO_DIV_EQ: - printf (" ?= "); + __printf (" ?= "); break; case AO_MOD_EQ: - printf (" %%= "); + __printf (" %%= "); break; case AO_PLUS_EQ: - printf (" += "); + __printf (" += "); break; case AO_MINUS_EQ: - printf (" -= "); + __printf (" -= "); break; case AO_LSHIFT_EQ: - printf (" <<= "); + __printf (" <<= "); break; case AO_RSHIFT_EQ: - printf (" >>= "); + __printf (" >>= "); break; case AO_RSHIFT_EX_EQ: - printf (" >>>= "); + __printf (" >>>= "); break; case AO_AND_EQ: - printf (" &= "); + __printf (" &= "); break; case AO_XOR_EQ: - printf (" ^= "); + __printf (" ^= "); break; case AO_OR_EQ: - printf (" |= "); + __printf (" |= "); break; default: @@ -767,30 +767,30 @@ pp_assignment_expression (assignment_expression expr) return; case ET_NEW: - printf ("new "); + __printf ("new "); pp_operand (expr.data.ops.op1); JERRY_ASSERT (is_operand_empty (expr.data.ops.op2)); - putchar ('\n'); + __putchar ('\n'); return; case ET_INDEX: pp_operand (expr.data.ops.op1); - putchar ('.'); + __putchar ('.'); pp_operand (expr.data.ops.op2); - putchar ('\n'); + __putchar ('\n'); return; case ET_PROP_REF: pp_operand (expr.data.ops.op1); - putchar ('['); + __putchar ('['); pp_operand (expr.data.ops.op2); - printf ("]\n"); + __printf ("]\n"); return; case ET_OBJECT: - putchar ('{'); + __putchar ('{'); pp_property_list (expr.data.obj_lit); - printf ("}\n"); + __printf ("}\n"); return; case ET_FUNCTION: @@ -798,20 +798,20 @@ pp_assignment_expression (assignment_expression expr) return; case ET_ARRAY: - putchar ('['); + __putchar ('['); pp_operand_list (expr.data.arr_lit); - printf ("]\n"); + __printf ("]\n"); return; case ET_SUBEXPRESSION: - putchar ('('); + __putchar ('('); return; case ET_LITERAL: case ET_IDENTIFIER: pp_operand (expr.data.ops.op1); JERRY_ASSERT (is_operand_empty (expr.data.ops.op2)); - putchar ('\n'); + __putchar ('\n'); return; default: @@ -829,13 +829,13 @@ pp_expression (expression_list expr_list) if (is_expression_empty (expr_list.exprs[i])) break; if (i != 0) - printf (", "); + __printf (", "); pp_assignment_expression (expr_list.exprs[i]); } if (was_subexpression && !was_function_expression) { - putchar (')'); + __putchar (')'); was_subexpression = false; } } @@ -843,10 +843,10 @@ pp_expression (expression_list expr_list) static void pp_variable_declaration (variable_declaration var_decl) { - printf ("%s", var_decl.name); + __printf ("%s", var_decl.name); if (!is_expression_empty (var_decl.assign_expr)) { - printf (" = "); + __printf (" = "); pp_assignment_expression (var_decl.assign_expr); } } @@ -856,14 +856,14 @@ pp_variable_declaration_list (variable_declaration_list decl_list) { int i; - printf ("var "); + __printf ("var "); for (i = 0; i < MAX_DECLS; i++) { if (is_variable_declaration_empty (decl_list.decls[i])) break; if (i != 0) - printf (", "); + __printf (", "); pp_variable_declaration (decl_list.decls[i]); } } @@ -873,7 +873,7 @@ pp_for_in_statement_initializer_part (for_in_statement_initializer_part init) { if (init.is_decl) { - printf ("var "); + __printf ("var "); pp_variable_declaration (init.data.decl); } else if (!is_expression_empty (init.data.left_hand_expr)) @@ -883,11 +883,11 @@ pp_for_in_statement_initializer_part (for_in_statement_initializer_part init) static void pp_for_in_statement (for_in_statement for_in_stmt) { - printf ("for ("); + __printf ("for ("); pp_for_in_statement_initializer_part (for_in_stmt.init); - printf (" in "); + __printf (" in "); pp_expression (for_in_stmt.list_expr); - printf (") "); + __printf (") "); } static void @@ -902,15 +902,15 @@ pp_for_statement_initialiser_part (for_statement_initialiser_part init) static void pp_for_statement (for_statement for_stmt) { - printf ("for ("); + __printf ("for ("); pp_for_statement_initialiser_part (for_stmt.init); - printf ("; "); + __printf ("; "); if (is_expression_empty (for_stmt.limit)) pp_assignment_expression (for_stmt.limit); - printf ("; "); + __printf ("; "); if (is_expression_empty (for_stmt.incr)) pp_assignment_expression (for_stmt.incr); - printf (") "); + __printf (") "); } static void @@ -932,25 +932,25 @@ pp_statement (statement stmt) { if (stmt.type == STMT_EMPTY) { - printf (";\n"); + __printf (";\n"); prev_stmt = stmt.type; return; } else - putchar ('\n'); + __putchar ('\n'); } switch (stmt.type) { case STMT_BLOCK_START: - printf ("{\n"); + __printf ("{\n"); intendation += 2; break; case STMT_BLOCK_END: intendation -= 2; intend (); - printf ("}"); + __printf ("}"); break; case STMT_VARIABLE: @@ -959,38 +959,38 @@ pp_statement (statement stmt) break; case STMT_EMPTY: - printf (";\n"); + __printf (";\n"); break; case STMT_IF: intend (); - printf ("if ("); + __printf ("if ("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_ELSE: intend (); - printf ("else "); + __printf ("else "); break; case STMT_ELSE_IF: intend (); - printf ("else if("); + __printf ("else if("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_DO: intend (); - printf ("do "); + __printf ("do "); break; case STMT_WHILE: intend (); - printf ("while ("); + __printf ("while ("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_FOR_OR_FOR_IN: @@ -1000,70 +1000,70 @@ pp_statement (statement stmt) case STMT_CONTINUE: intend (); - printf ("continue\n"); + __printf ("continue\n"); break; case STMT_BREAK: intend (); - printf ("break\n"); + __printf ("break\n"); break; case STMT_RETURN: intend (); - printf ("return "); + __printf ("return "); pp_expression (stmt.data.expr); if (!was_function_expression) - printf (";\n"); + __printf (";\n"); break; case STMT_WITH: intend (); - printf ("with ("); + __printf ("with ("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_LABELLED: intend (); - printf ("%s:\n", stmt.data.name); + __printf ("%s:\n", stmt.data.name); break; case STMT_SWITCH: intend (); - printf ("switch ("); + __printf ("switch ("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_CASE: intend (); - printf ("case "); + __printf ("case "); pp_expression (stmt.data.expr); - printf (":\n"); + __printf (":\n"); break; case STMT_THROW: intend (); - printf ("throw "); + __printf ("throw "); pp_expression (stmt.data.expr); - printf (";\n"); + __printf (";\n"); break; case STMT_TRY: intend (); - printf ("try "); + __printf ("try "); break; case STMT_CATCH: intend (); - printf ("catch ("); + __printf ("catch ("); pp_expression (stmt.data.expr); - printf (") "); + __printf (") "); break; case STMT_FINALLY: intend (); - printf ("finally "); + __printf ("finally "); break; case STMT_EXPRESSION: @@ -1072,7 +1072,7 @@ pp_statement (statement stmt) break; case STMT_SUBEXPRESSION_END: - putchar (')'); + __putchar (')'); break; case STMT_FUNCTION: @@ -1087,8 +1087,8 @@ pp_statement (statement stmt) prev_stmt = stmt.type; } -void pp_finish (void) +void pp_finish () { if (prev_stmt == STMT_BLOCK_END) - putchar ('\n'); + __putchar ('\n'); } diff --git a/src/libruntime/stm32f4/jerry-assert.c b/src/libruntime/stm32f4/jerry-assert.c index 949d80110..b6b3b5952 100644 --- a/src/libruntime/stm32f4/jerry-assert.c +++ b/src/libruntime/stm32f4/jerry-assert.c @@ -24,9 +24,5 @@ jerry_AssertFail( const char *assertion, /**< assertion condition string */ const char *file, /**< file name */ const uint32_t line) /** line */ { - /** - * TODO: Blink with LEDs. - * Save call stack? - */ - while( true ); + __exit( -ERR_GENERAL); } /* jerry_AssertFail */ diff --git a/src/main.c b/src/main.c index 0aa43228c..a2a89f7d0 100644 --- a/src/main.c +++ b/src/main.c @@ -13,12 +13,6 @@ * limitations under the License. */ -#ifdef __HOST -#include -#include -#include -#endif - #ifdef __TARGET_MCU #include "stm32f4xx.h" #include "stm32f4xx_gpio.h" @@ -30,17 +24,11 @@ #define LED_BLUE 15 #endif -#include "error.h" - -#include "mem-allocator.h" - -#include "interpreter.h" - #include "generated.h" - -#include "lexer.h" -#include "parser.h" -#include "pretty-printer.h" +#include "globals.h" +#include "interpreter.h" +#include "jerry-libc.h" +#include "mem-allocator.h" void fake_exit (void); @@ -111,9 +99,9 @@ main (int argc, char **argv) if (argc > 0) for (int i = 1; i < argc; i++) { - if (!strcmp ("-t", argv[i])) + if (!__strcmp ("-t", argv[i])) dump_tokens = true; - else if (!strcmp ("-a", argv[i])) + else if (!__strcmp ("-a", argv[i])) dump_ast = true; else if (file_name == NULL) file_name = argv[i];