mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Fixes in triple-address code parser, 1% tests passed
This commit is contained in:
parent
7da95ecefa
commit
1d6aac7839
10
Makefile
10
Makefile
@ -31,7 +31,7 @@ SUP_STM32F4 = ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32
|
||||
# Add common-io.c and sensors.c
|
||||
SOURCES = \
|
||||
$(sort \
|
||||
$(wildcard ./src/jerry-libc.c ./src/pretty-printer.c ./src/error.c) \
|
||||
$(wildcard ./src/jerry-libc.c ./src/pretty-printer.c) \
|
||||
$(wildcard ./src/libperipherals/actuators.c) \
|
||||
$(wildcard ./src/libjsparser/*.c) \
|
||||
$(wildcard ./src/libecmaobjects/*.c) \
|
||||
@ -81,10 +81,10 @@ STRIP = strip
|
||||
|
||||
# General flags
|
||||
CFLAGS ?= $(INCLUDES) -std=c99 #-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
|
||||
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
|
||||
|
||||
27
src/error.c
27
src/error.c
@ -1,27 +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.
|
||||
*/
|
||||
|
||||
#include "error.h"
|
||||
|
||||
extern void lexer_dump_buffer_state (void);
|
||||
|
||||
void
|
||||
fatal (int code)
|
||||
{
|
||||
printf ("FATAL: %d\n", code);
|
||||
lexer_dump_buffer_state ();
|
||||
JERRY_UNREACHABLE ();
|
||||
exit (code);
|
||||
}
|
||||
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
static const char* generated_source = ""
|
||||
static const char* generated_source __unused = ""
|
||||
"while (true) {\n"
|
||||
"LEDToggle (LED3);\n"
|
||||
"LEDToggle (LED6);\n"
|
||||
|
||||
@ -87,11 +87,11 @@ is_empty (token tok)
|
||||
return tok.type == TOK_EMPTY;
|
||||
}
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
FILE *lexer_debug_log;
|
||||
#endif
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
static FILE *file;
|
||||
static char *buffer_start;
|
||||
|
||||
@ -169,7 +169,7 @@ static const char *token_start;
|
||||
|
||||
#define LA(I) (*(buffer + I))
|
||||
|
||||
#endif // JERRY_NDEBUG
|
||||
#endif // __HOST
|
||||
|
||||
/* If TOKEN represents a keyword, return decoded keyword,
|
||||
if TOKEN represents a Future Reserved Word, return KW_RESERVED,
|
||||
@ -230,7 +230,7 @@ current_token (void)
|
||||
{
|
||||
JERRY_ASSERT (buffer);
|
||||
JERRY_ASSERT (token_start);
|
||||
JERRY_ASSERT (token_start > buffer);
|
||||
JERRY_ASSERT (token_start <= buffer);
|
||||
size_t length = (size_t) (buffer - token_start);
|
||||
char *res = (char *) malloc (length + 1);
|
||||
strncpy (res, token_start, length);
|
||||
@ -578,7 +578,7 @@ grobble_whitespaces (void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
void
|
||||
lexer_set_file (FILE *ex_file)
|
||||
{
|
||||
@ -634,7 +634,7 @@ replace_comment_by_newline (void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
static token
|
||||
lexer_next_token_private (void)
|
||||
#else
|
||||
@ -675,7 +675,7 @@ lexer_next_token (void)
|
||||
{
|
||||
grobble_whitespaces ();
|
||||
return
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
lexer_next_token_private ();
|
||||
#else
|
||||
lexer_next_token ();
|
||||
@ -688,7 +688,7 @@ lexer_next_token (void)
|
||||
return (token) { .type = TOK_NEWLINE, .data.none = NULL };
|
||||
else
|
||||
return
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
lexer_next_token_private ();
|
||||
#else
|
||||
lexer_next_token ();
|
||||
@ -699,7 +699,7 @@ lexer_next_token (void)
|
||||
{
|
||||
replace_comment_by_newline ();;
|
||||
return
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
lexer_next_token_private ();
|
||||
#else
|
||||
lexer_next_token ();
|
||||
@ -771,7 +771,7 @@ lexer_next_token (void)
|
||||
fatal (ERR_NON_CHAR);
|
||||
}
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
static int i = 0;
|
||||
|
||||
token
|
||||
@ -793,7 +793,7 @@ lexer_next_token (void)
|
||||
void
|
||||
lexer_save_token (token tok)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
// if (tok.type == TOK_CLOSE_BRACE)
|
||||
fprintf (lexer_debug_log, "lexer_save_token(%d): type=0x%x, data=%p\n", i, tok.type, tok.data.none);
|
||||
#endif
|
||||
|
||||
@ -151,7 +151,7 @@ typedef struct
|
||||
}
|
||||
token;
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
void lexer_set_file (FILE *);
|
||||
#else
|
||||
void lexer_set_source (const char *);
|
||||
@ -159,4 +159,6 @@ void lexer_set_source (const char *);
|
||||
token lexer_next_token (void);
|
||||
void lexer_save_token (token);
|
||||
|
||||
void lexer_dump_buffer_state (void);
|
||||
|
||||
#endif
|
||||
@ -16,7 +16,7 @@
|
||||
#ifndef MAPPINGS_H
|
||||
#define MAPPINGS_H
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
#ifndef __HOST
|
||||
#include "../jerry-libc.h"
|
||||
#include "allocator.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
@ -16,6 +16,18 @@
|
||||
#include "parser.h"
|
||||
#include "error.h"
|
||||
#include "lexer.h"
|
||||
#include "error.h"
|
||||
|
||||
extern void lexer_dump_buffer_state (void);
|
||||
|
||||
void
|
||||
fatal (int code)
|
||||
{
|
||||
printf ("FATAL: %d\n", code);
|
||||
lexer_dump_buffer_state ();
|
||||
JERRY_UNREACHABLE ();
|
||||
exit (code);
|
||||
}
|
||||
|
||||
bool
|
||||
is_formal_parameter_list_empty (formal_parameter_list list)
|
||||
@ -68,7 +80,7 @@ is_statement_null (statement stmt)
|
||||
|
||||
static token tok;
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
FILE *debug_file;
|
||||
#endif
|
||||
|
||||
@ -133,14 +145,14 @@ current_scope_must_be (unsigned int scopes)
|
||||
static inline void
|
||||
current_scope_must_be_global (void)
|
||||
{
|
||||
if (scope_index != 0)
|
||||
if (scope_index != 1)
|
||||
fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static void
|
||||
push_scope (int type)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
fprintf (debug_file, "push_scope: 0x%x\n", type);
|
||||
#endif
|
||||
current_scopes[scope_index++] = (scope) { .type = type, .was_stmt = false };
|
||||
@ -149,7 +161,7 @@ push_scope (int type)
|
||||
static void
|
||||
pop_scope (void)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
fprintf (debug_file, "pop_scope: 0x%x\n", current_scopes[scope_index - 1].type);
|
||||
#endif
|
||||
scope_index--;
|
||||
@ -160,7 +172,7 @@ assert_keyword (keyword kw)
|
||||
{
|
||||
if (tok.type != TOK_KEYWORD || tok.data.kw != kw)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
printf ("assert_keyword: 0x%x\n", kw);
|
||||
#endif
|
||||
JERRY_UNREACHABLE ();
|
||||
@ -178,7 +190,7 @@ current_token_must_be(token_type tt)
|
||||
{
|
||||
if (tok.type != tt)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
printf ("current_token_must_be: 0x%x\n", tt);
|
||||
#endif
|
||||
fatal (ERR_PARSER);
|
||||
@ -199,7 +211,7 @@ next_token_must_be (token_type tt)
|
||||
tok = lexer_next_token ();
|
||||
if (tok.type != tt)
|
||||
{
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
printf ("next_token_must_be: 0x%x\n", tt);
|
||||
#endif
|
||||
fatal (ERR_PARSER);
|
||||
@ -786,7 +798,7 @@ parse_operator:
|
||||
res.type = ET_PROP_REF;
|
||||
skip_newlines ();
|
||||
res.data.ops.op2 = parse_operand ();
|
||||
assert (!res.data.ops.op2.is_literal);
|
||||
JERRY_ASSERT (!res.data.ops.op2.is_literal);
|
||||
return res;
|
||||
|
||||
case TOK_OPEN_SQUARE:
|
||||
@ -962,7 +974,7 @@ parse_for_or_for_in_statement (void)
|
||||
fatal (ERR_PARSER);
|
||||
}
|
||||
}
|
||||
assert (is_variable_declaration_empty(list.decls[0]));
|
||||
JERRY_ASSERT (is_variable_declaration_empty(list.decls[0]));
|
||||
|
||||
/* expression contains left_hand_side_expression. */
|
||||
expr = parse_expression ();
|
||||
@ -981,13 +993,13 @@ plain_for:
|
||||
res.is_for_in = false;
|
||||
if (!is_variable_declaration_empty(list.decls[0]))
|
||||
{
|
||||
assert (is_expression_empty(expr.exprs[0]));
|
||||
JERRY_ASSERT (is_expression_empty(expr.exprs[0]));
|
||||
res.data.for_stmt.init.is_decl = true;
|
||||
res.data.for_stmt.init.data.decl_list = list;
|
||||
}
|
||||
if (!is_expression_empty(expr.exprs[0]))
|
||||
{
|
||||
assert (is_variable_declaration_empty(list.decls[0]));
|
||||
JERRY_ASSERT (is_variable_declaration_empty(list.decls[0]));
|
||||
res.data.for_stmt.init.is_decl = false;
|
||||
res.data.for_stmt.init.data.expr = expr;
|
||||
}
|
||||
@ -1015,14 +1027,14 @@ for_in:
|
||||
res.is_for_in = true;
|
||||
if (!is_variable_declaration_empty(list.decls[0]))
|
||||
{
|
||||
assert (is_expression_empty (expr.exprs[0]));
|
||||
assert (is_variable_declaration_empty (list.decls[1]));
|
||||
JERRY_ASSERT (is_expression_empty (expr.exprs[0]));
|
||||
JERRY_ASSERT (is_variable_declaration_empty (list.decls[1]));
|
||||
res.data.for_in_stmt.init.is_decl = true;
|
||||
res.data.for_in_stmt.init.data.decl = list.decls[0];
|
||||
}
|
||||
if (!is_expression_empty(expr.exprs[0]))
|
||||
{
|
||||
assert (is_expression_empty(expr.exprs[0]));
|
||||
JERRY_ASSERT (is_expression_empty(expr.exprs[0]));
|
||||
res.data.for_in_stmt.init.is_decl = false;
|
||||
res.data.for_in_stmt.init.data.left_hand_expr = expr.exprs[0];
|
||||
}
|
||||
@ -1112,6 +1124,8 @@ parser_parse_statement (void)
|
||||
statement res;
|
||||
res.data.none = NULL;
|
||||
|
||||
JERRY_ASSERT (scope_index);
|
||||
|
||||
skip_newlines ();
|
||||
|
||||
if (is_keyword (KW_FINALLY))
|
||||
@ -1374,8 +1388,8 @@ parser_parse_statement (void)
|
||||
void
|
||||
parser_init (void)
|
||||
{
|
||||
scope_index = 0;
|
||||
#ifdef JERRY_NDEBUG
|
||||
scope_index = 1;
|
||||
#ifdef __HOST
|
||||
debug_file = fopen ("parser.log", "w");
|
||||
#endif
|
||||
}
|
||||
|
||||
43
src/main.c
43
src/main.c
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -39,6 +39,10 @@
|
||||
|
||||
#include "generated.h"
|
||||
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "pretty-printer.h"
|
||||
|
||||
void fake_exit (void);
|
||||
|
||||
void
|
||||
@ -95,10 +99,11 @@ fake_exit (void)
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
statement st;
|
||||
bool dump_tokens = false;
|
||||
bool dump_ast = true;
|
||||
bool dump_ast = false;
|
||||
const char *file_name = NULL;
|
||||
#ifdef JERRY_NDEBUG
|
||||
#ifdef __HOST
|
||||
FILE *file = NULL;
|
||||
#endif
|
||||
|
||||
@ -124,16 +129,44 @@ main (int argc, char **argv)
|
||||
if (dump_tokens && dump_ast)
|
||||
fatal (ERR_SEVERAL_FILES);
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
if (!dump_tokens)
|
||||
dump_ast = true;
|
||||
|
||||
#ifdef __HOST
|
||||
file = fopen (file_name, "r");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
fatal (ERR_IO);
|
||||
}
|
||||
|
||||
lexer_set_file (file);
|
||||
#else
|
||||
lexer_set_source (generated_source);
|
||||
#endif
|
||||
|
||||
TODO(Call parser);
|
||||
if (dump_ast)
|
||||
{
|
||||
parser_init ();
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
while (st.type != STMT_EOF)
|
||||
{
|
||||
pp_statement (st);
|
||||
st = parser_parse_statement ();
|
||||
JERRY_ASSERT (!is_statement_null (st));
|
||||
}
|
||||
}
|
||||
|
||||
if (dump_tokens)
|
||||
{
|
||||
token tok = lexer_next_token ();
|
||||
while (tok.type != TOK_EOF)
|
||||
{
|
||||
pp_token (tok);
|
||||
tok = lexer_next_token ();
|
||||
}
|
||||
}
|
||||
|
||||
//gen_bytecode (generated_source);
|
||||
//gen_bytecode ();
|
||||
|
||||
@ -548,7 +548,7 @@ dump_postfix (operand op, const char *operation)
|
||||
static void
|
||||
pp_assignment_expression (assignment_expression expr)
|
||||
{
|
||||
if (expr.var)
|
||||
if (expr.oper != AO_NONE && expr.var)
|
||||
printf ("%s", expr.var);
|
||||
|
||||
switch (expr.oper)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user