Fix parsing of for-loops.
This commit is contained in:
+17
-5
@@ -119,12 +119,24 @@ dump_current_line (void)
|
||||
{
|
||||
const char *i;
|
||||
|
||||
__printf ("// ");
|
||||
|
||||
for (i = buffer; *i != '\n' && *i != 0; i++)
|
||||
__putchar (*i);
|
||||
__putchar ('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
current_token_equals_to (const char *str)
|
||||
{
|
||||
if (__strlen (str) != (size_t) (buffer - token_start))
|
||||
return false;
|
||||
if (!__strncmp (str, token_start, (size_t) (buffer - token_start)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If TOKEN represents a keyword, return decoded keyword,
|
||||
if TOKEN represents a Future Reserved Word, return KW_RESERVED,
|
||||
otherwise return KW_NONE. */
|
||||
@@ -136,7 +148,7 @@ decode_keyword (void)
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!__strncmp (keyword_tokens[i].str, token_start, (size_t) (buffer - token_start)))
|
||||
if (current_token_equals_to (keyword_tokens[i].str))
|
||||
return keyword_tokens[i].tok;
|
||||
}
|
||||
|
||||
@@ -150,7 +162,7 @@ convert_seen_name_to_token (void)
|
||||
|
||||
for (i = 0; i < seen_names_count; i++)
|
||||
{
|
||||
if (!__strncmp (seen_names[i].str, token_start, (size_t) (buffer - token_start)))
|
||||
if (current_token_equals_to (seen_names[i].str))
|
||||
return seen_names[i].tok;
|
||||
}
|
||||
|
||||
@@ -238,8 +250,8 @@ lexer_adjust_num_ids (void)
|
||||
|
||||
for (i = 0; i < sizeof (keyword_tokens) / sizeof (string_and_token); i++)
|
||||
{
|
||||
if (!__strncmp ("true", keyword_tokens[i].str, 4)
|
||||
|| !__strncmp ("false", keyword_tokens[i].str, 5))
|
||||
if (!__strcmp ("true", keyword_tokens[i].str)
|
||||
|| !__strcmp ("false", keyword_tokens[i].str))
|
||||
keyword_tokens[i].tok.data.uid = (uint8_t) (keyword_tokens[i].tok.data.uid + seen_names_count);
|
||||
}
|
||||
}
|
||||
@@ -609,7 +621,7 @@ parse_string (void)
|
||||
|
||||
for (num = 0; num < seen_names_count; num++)
|
||||
{
|
||||
if (!__strncmp (seen_names[num].str, tok, __strlen (tok)))
|
||||
if (!__strcmp (seen_names[num].str, tok))
|
||||
{
|
||||
mem_heap_free_block ((uint8_t*) tok);
|
||||
return seen_names[num].tok;
|
||||
|
||||
+14
-15
@@ -20,9 +20,10 @@
|
||||
#include "serializer.h"
|
||||
|
||||
#define MAX_OPCODES 10
|
||||
#define INVALID_VALUE 255
|
||||
|
||||
static token tok;
|
||||
static OPCODE opcode, opcodes_buffer[10];
|
||||
static OPCODE opcode, opcodes_buffer[MAX_OPCODES];
|
||||
static uint8_t current_opcode_in_buffer = 0;
|
||||
static uint8_t opcode_counter = 0;
|
||||
|
||||
@@ -136,7 +137,7 @@ insert_semicolon (void)
|
||||
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_dump_opcode (&opcode); opcode_counter++; } while (0)
|
||||
|
||||
#define REWRITE_OPCODE(OC, GETOP, ...) \
|
||||
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_rewrite_opcode ((int8_t) (OC - opcode_counter), &opcode); } while (0)
|
||||
do { opcode=getop_##GETOP (__VA_ARGS__); serializer_rewrite_opcode (OC, &opcode); } while (0)
|
||||
|
||||
static T_IDX
|
||||
integer_zero (void)
|
||||
@@ -624,23 +625,23 @@ parse_literal (void)
|
||||
{
|
||||
case TOK_NULL:
|
||||
lhs = next_temp_name ();
|
||||
DUMP_OPCODE (assignment, OPCODE_ARG_TYPE_SIMPLE, lhs, ECMA_SIMPLE_VALUE_NULL);
|
||||
DUMP_OPCODE (assignment, lhs, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_NULL);
|
||||
return lhs;
|
||||
|
||||
case TOK_BOOL:
|
||||
lhs = next_temp_name ();
|
||||
DUMP_OPCODE (assignment, OPCODE_ARG_TYPE_SIMPLE, lhs,
|
||||
DUMP_OPCODE (assignment, lhs, OPCODE_ARG_TYPE_SIMPLE,
|
||||
tok.data.uid ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
return lhs;
|
||||
|
||||
case TOK_INT:
|
||||
lhs = next_temp_name ();
|
||||
DUMP_OPCODE (assignment, OPCODE_ARG_TYPE_NUMBER, lhs, tok.data.uid);
|
||||
DUMP_OPCODE (assignment, lhs, OPCODE_ARG_TYPE_NUMBER, tok.data.uid);
|
||||
return lhs;
|
||||
|
||||
case TOK_STRING:
|
||||
lhs = next_temp_name ();
|
||||
DUMP_OPCODE (assignment, OPCODE_ARG_TYPE_STRING, lhs, tok.data.uid);
|
||||
DUMP_OPCODE (assignment, lhs, OPCODE_ARG_TYPE_STRING, tok.data.uid);
|
||||
return lhs;
|
||||
|
||||
default:
|
||||
@@ -1143,7 +1144,7 @@ parse_conditional_expression (bool *was_conditional)
|
||||
|
||||
DUMP_OPCODE (is_true_jmp, expr, (uint8_t) (opcode_counter + 2));
|
||||
jmp_oc = opcode_counter;
|
||||
DUMP_OPCODE (jmp_down, 1);
|
||||
DUMP_OPCODE (jmp_down, INVALID_VALUE);
|
||||
|
||||
NEXT (lhs, assignment_expression);
|
||||
DUMP_OPCODE (assignment, res, OPCODE_ARG_TYPE_VARIABLE, lhs);
|
||||
@@ -1151,7 +1152,7 @@ parse_conditional_expression (bool *was_conditional)
|
||||
|
||||
REWRITE_OPCODE (jmp_oc, jmp_down, (uint8_t) (opcode_counter - jmp_oc));
|
||||
jmp_oc = opcode_counter;
|
||||
DUMP_OPCODE (jmp_down, 1);
|
||||
DUMP_OPCODE (jmp_down, INVALID_VALUE);
|
||||
|
||||
NEXT (lhs, assignment_expression);
|
||||
DUMP_OPCODE (assignment, res, OPCODE_ARG_TYPE_VARIABLE, lhs);
|
||||
@@ -1435,10 +1436,10 @@ plain_for:
|
||||
stop = integer_one ();
|
||||
|
||||
end_oc = opcode_counter;
|
||||
DUMP_OPCODE (is_false_jmp, stop, 1);
|
||||
DUMP_OPCODE (is_false_jmp, stop, INVALID_VALUE);
|
||||
|
||||
body_oc = opcode_counter;
|
||||
DUMP_OPCODE (jmp_down, 1);
|
||||
DUMP_OPCODE (jmp_down, INVALID_VALUE);
|
||||
|
||||
step_oc = opcode_counter;
|
||||
skip_newlines ();
|
||||
@@ -1450,10 +1451,8 @@ plain_for:
|
||||
DUMP_OPCODE (jmp_up, (uint8_t) (opcode_counter - cond_oc));
|
||||
REWRITE_OPCODE (body_oc, jmp_down, (uint8_t) (opcode_counter - body_oc));
|
||||
|
||||
token_after_newlines_must_be (TOK_OPEN_BRACE);
|
||||
skip_newlines ();
|
||||
parse_source_element_list ();
|
||||
next_token_must_be (TOK_CLOSE_BRACE);
|
||||
parse_statement ();
|
||||
|
||||
DUMP_OPCODE (jmp_up, (uint8_t) (opcode_counter - step_oc));
|
||||
REWRITE_OPCODE (end_oc, is_false_jmp, stop, opcode_counter);
|
||||
@@ -1506,7 +1505,7 @@ parse_if_statement (void)
|
||||
|
||||
cond = parse_expression_inside_parens ();
|
||||
cond_oc = opcode_counter;
|
||||
DUMP_OPCODE (is_false_jmp, cond, 1);
|
||||
DUMP_OPCODE (is_false_jmp, cond, INVALID_VALUE);
|
||||
|
||||
skip_newlines ();
|
||||
parse_statement ();
|
||||
@@ -1556,7 +1555,7 @@ parse_while_statement (void)
|
||||
cond_oc = opcode_counter;
|
||||
cond = parse_expression_inside_parens ();
|
||||
jmp_oc = opcode_counter;
|
||||
DUMP_OPCODE (is_false_jmp, cond, 1);
|
||||
DUMP_OPCODE (is_false_jmp, cond, INVALID_VALUE);
|
||||
|
||||
skip_newlines ();
|
||||
parse_statement ();
|
||||
|
||||
Reference in New Issue
Block a user