Add try-catch-finally support: parse and generate opcodes for this construct
Fix varg generation: generate *_n opcodes with parameters in following meta opcodes Add stack internal structure: dimanically allocated stack. Use dynamically allocated memory in parser: every local and global variables are stored in dinamically allocated stacks. Use dynamically allocated memory in serializer: opcodes are also stored in stack. Change is_true_jmp and is_false_jmp opcodes to relative. Change *jmp* opcodes to be able to store opcode_counter_t instead of idx_t.
This commit is contained in:
@@ -37,6 +37,7 @@ main( int __unused argc,
|
||||
};
|
||||
|
||||
mem_init();
|
||||
serializer_init (false);
|
||||
|
||||
const char *strings[] = { "a",
|
||||
"b" };
|
||||
|
||||
+17
-16
@@ -28,7 +28,7 @@ main( int __unused argc,
|
||||
{
|
||||
const opcode_t test_program[] = {
|
||||
[ 0] = getop_reg_var_decl (240, 255),
|
||||
[ 1] = getop_jmp_down (2),
|
||||
[ 1] = getop_jmp_down (0, 2),
|
||||
[ 2] = getop_exitval (1),
|
||||
|
||||
/* var a, b; */
|
||||
@@ -52,35 +52,35 @@ main( int __unused argc,
|
||||
[14] = getop_prop_getter (240, 0, 240),
|
||||
[15] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 3),
|
||||
[16] = getop_equal_value_type (240, 240, 241),
|
||||
[17] = getop_is_false_jmp (240, 2),
|
||||
[17] = getop_is_false_jmp_up (240, 0, 15),
|
||||
|
||||
/* assert (a[0] === 12.0); */
|
||||
[18] = getop_assignment (240, OPCODE_ARG_TYPE_SMALLINT, 0),
|
||||
[19] = getop_prop_getter (240, 0, 240),
|
||||
[20] = getop_assignment (241, OPCODE_ARG_TYPE_NUMBER, 5),
|
||||
[21] = getop_equal_value_type (240, 240, 241),
|
||||
[22] = getop_is_false_jmp (240, 2),
|
||||
[22] = getop_is_false_jmp_up (240, 0, 20),
|
||||
|
||||
/* assert (a['1'] === 'length'); */
|
||||
[23] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 3),
|
||||
[24] = getop_prop_getter (240, 0, 240),
|
||||
[25] = getop_assignment (241, OPCODE_ARG_TYPE_STRING, 2),
|
||||
[26] = getop_equal_value_type (240, 240, 241),
|
||||
[27] = getop_is_false_jmp (240, 2),
|
||||
[27] = getop_is_false_jmp_up (240, 0, 25),
|
||||
|
||||
/* assert (a[2.0] === null); */
|
||||
[28] = getop_assignment (240, OPCODE_ARG_TYPE_NUMBER, 4),
|
||||
[29] = getop_prop_getter (240, 0, 240),
|
||||
[30] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_NULL),
|
||||
[31] = getop_equal_value_type (240, 240, 241),
|
||||
[32] = getop_is_false_jmp (240, 2),
|
||||
[32] = getop_is_false_jmp_up (240, 0, 30),
|
||||
|
||||
/* assert (a[2.5] === undefined); */
|
||||
[33] = getop_assignment (240, OPCODE_ARG_TYPE_NUMBER, 6),
|
||||
[34] = getop_prop_getter (240, 0, 240),
|
||||
[35] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
[36] = getop_equal_value_type (240, 240, 241),
|
||||
[37] = getop_is_false_jmp (240, 2),
|
||||
[37] = getop_is_false_jmp_up (240, 0, 35),
|
||||
|
||||
/* a.length = 1; */
|
||||
[38] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 2),
|
||||
@@ -92,27 +92,27 @@ main( int __unused argc,
|
||||
[42] = getop_prop_getter (240, 0, 240),
|
||||
[43] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 1),
|
||||
[44] = getop_equal_value_type (240, 240, 241),
|
||||
[45] = getop_is_false_jmp (240, 2),
|
||||
[45] = getop_is_false_jmp_up (240, 0, 43),
|
||||
|
||||
/* assert (a[0] === 12.0); */
|
||||
[46] = getop_assignment (240, OPCODE_ARG_TYPE_SMALLINT, 0),
|
||||
[47] = getop_prop_getter (240, 0, 240),
|
||||
[48] = getop_assignment (241, OPCODE_ARG_TYPE_NUMBER, 5),
|
||||
[49] = getop_equal_value_type (240, 240, 241),
|
||||
[50] = getop_is_false_jmp (240, 2),
|
||||
[50] = getop_is_false_jmp_up (240, 0, 48),
|
||||
|
||||
/* assert (a['1'] === undefined); */
|
||||
[51] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 3),
|
||||
[52] = getop_prop_getter (240, 0, 240),
|
||||
[53] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
[54] = getop_equal_value_type (240, 240, 241),
|
||||
[55] = getop_is_false_jmp (240, 2),
|
||||
[55] = getop_is_false_jmp_up (240, 0, 53),
|
||||
|
||||
/* assert (a[2.0] === undefined); */
|
||||
[56] = getop_assignment (240, OPCODE_ARG_TYPE_NUMBER, 4),
|
||||
[57] = getop_prop_getter (240, 0, 240),
|
||||
[58] = getop_equal_value_type (240, 240, 241),
|
||||
[59] = getop_is_false_jmp (240, 2),
|
||||
[59] = getop_is_false_jmp_up (240, 0, 57),
|
||||
|
||||
/* a.length = 8; */
|
||||
[60] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 2),
|
||||
@@ -124,7 +124,7 @@ main( int __unused argc,
|
||||
[64] = getop_prop_getter (240, 0, 240),
|
||||
[65] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 8),
|
||||
[66] = getop_equal_value_type (240, 240, 241),
|
||||
[67] = getop_is_false_jmp (240, 2),
|
||||
[67] = getop_is_false_jmp_up (240, 0, 65),
|
||||
|
||||
/* a[10] = true; */
|
||||
[68] = getop_assignment (240, OPCODE_ARG_TYPE_SMALLINT, 10),
|
||||
@@ -136,34 +136,34 @@ main( int __unused argc,
|
||||
[72] = getop_prop_getter (240, 0, 240),
|
||||
[73] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 11),
|
||||
[74] = getop_equal_value_type (240, 240, 241),
|
||||
[75] = getop_is_false_jmp (240, 2),
|
||||
[75] = getop_is_false_jmp_up (240, 0, 73),
|
||||
|
||||
/* assert (a[0] === 12.0); */
|
||||
[76] = getop_assignment (240, OPCODE_ARG_TYPE_SMALLINT, 0),
|
||||
[77] = getop_prop_getter (240, 0, 240),
|
||||
[78] = getop_assignment (241, OPCODE_ARG_TYPE_NUMBER, 5),
|
||||
[79] = getop_equal_value_type (240, 240, 241),
|
||||
[80] = getop_is_false_jmp (240, 2),
|
||||
[80] = getop_is_false_jmp_up (240, 0, 78),
|
||||
|
||||
/* assert (a['1'] === undefined); */
|
||||
[81] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 3),
|
||||
[82] = getop_prop_getter (240, 0, 240),
|
||||
[83] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
[84] = getop_equal_value_type (240, 240, 241),
|
||||
[85] = getop_is_false_jmp (240, 2),
|
||||
[85] = getop_is_false_jmp_up (240, 0, 83),
|
||||
|
||||
/* assert (a[2.0] === undefined); */
|
||||
[86] = getop_assignment (240, OPCODE_ARG_TYPE_NUMBER, 4),
|
||||
[87] = getop_prop_getter (240, 0, 240),
|
||||
[88] = getop_equal_value_type (240, 240, 241),
|
||||
[89] = getop_is_false_jmp (240, 2),
|
||||
[89] = getop_is_false_jmp_up (240, 0, 87),
|
||||
|
||||
/* assert (a[17] === true); */
|
||||
[90] = getop_assignment (240, OPCODE_ARG_TYPE_SMALLINT, 10),
|
||||
[91] = getop_prop_getter (240, 0, 240),
|
||||
[92] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_TRUE),
|
||||
[93] = getop_equal_value_type (240, 240, 241),
|
||||
[94] = getop_is_false_jmp (240, 2),
|
||||
[94] = getop_is_false_jmp_up (240, 0, 92),
|
||||
|
||||
[95] = getop_exitval (0),
|
||||
};
|
||||
@@ -186,6 +186,7 @@ main( int __unused argc,
|
||||
bool status = run_int();
|
||||
|
||||
serializer_free ();
|
||||
mem_heap_print (true, false, true);
|
||||
mem_finalize (false);
|
||||
|
||||
return (status ? 0 : 1);
|
||||
|
||||
@@ -27,18 +27,18 @@ main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
const opcode_t test_program[] = {
|
||||
/* 0: */ getop_reg_var_decl( 255, 255),
|
||||
/* 1: */ getop_var_decl( 0),
|
||||
/* 2: */ getop_var_decl( 1),
|
||||
/* 3: */ getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
|
||||
/* 4: */ getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
|
||||
/* 5: */ getop_is_true_jmp( 1, 7),
|
||||
/* 6: */ getop_jmp_down( 5),
|
||||
/* 7: */ getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
|
||||
/* 8: */ getop_assignment( 1, OPCODE_ARG_TYPE_NUMBER, 2),
|
||||
/* 9: */ getop_is_false_jmp( 1, 11),
|
||||
/* 10: */ getop_exitval( 0),
|
||||
/* 11: */ getop_exitval( 1)
|
||||
[ 0] = getop_reg_var_decl (255, 255),
|
||||
[ 1] = getop_var_decl (0),
|
||||
[ 2] = getop_var_decl (1),
|
||||
[ 3] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1),
|
||||
[ 4] = getop_assignment (1, OPCODE_ARG_TYPE_VARIABLE, 0),
|
||||
[ 5] = getop_is_true_jmp_down (1, 0, 2),
|
||||
[ 6] = getop_jmp_down (0, 5),
|
||||
[ 7] = getop_assignment (0, OPCODE_ARG_TYPE_SMALLINT, 253),
|
||||
[ 8] = getop_assignment (1, OPCODE_ARG_TYPE_NUMBER, 2),
|
||||
[ 9] = getop_is_false_jmp_down (1, 0, 2),
|
||||
[10] = getop_exitval (0),
|
||||
[11] = getop_exitval (1)
|
||||
};
|
||||
|
||||
mem_init();
|
||||
|
||||
@@ -28,7 +28,7 @@ main( int __unused argc,
|
||||
{
|
||||
const opcode_t test_program[] = {
|
||||
[ 0] = getop_reg_var_decl (240, 255),
|
||||
[ 1] = getop_jmp_down (2),
|
||||
[ 1] = getop_jmp_down (0, 2),
|
||||
[ 2] = getop_exitval (1),
|
||||
|
||||
/* var a, b; */
|
||||
@@ -82,14 +82,14 @@ main( int __unused argc,
|
||||
[36] = getop_prop_getter (240, 0, 240),
|
||||
[37] = getop_assignment (241, OPCODE_ARG_TYPE_STRING, 5),
|
||||
[38] = getop_equal_value_type (240, 240, 241),
|
||||
[39] = getop_is_false_jmp (240, 2),
|
||||
[39] = getop_is_false_jmp_up (240, 0, 37),
|
||||
|
||||
/* assert (a.property2 === 1); */
|
||||
[40] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 3),
|
||||
[41] = getop_prop_getter (240, 0, 240),
|
||||
[42] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 1),
|
||||
[43] = getop_equal_value_type (240, 240, 241),
|
||||
[44] = getop_is_false_jmp (240, 2),
|
||||
[44] = getop_is_false_jmp_up (240, 0, 42),
|
||||
|
||||
/* a.property3 = 'value2'; */
|
||||
[45] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 4),
|
||||
@@ -101,7 +101,7 @@ main( int __unused argc,
|
||||
[49] = getop_prop_getter (240, 0, 240),
|
||||
[50] = getop_assignment (241, OPCODE_ARG_TYPE_STRING, 6),
|
||||
[51] = getop_equal_value_type (240, 240, 241),
|
||||
[52] = getop_is_false_jmp (240, 2),
|
||||
[52] = getop_is_false_jmp_up (240, 0, 50),
|
||||
|
||||
/* a.property2 = 2.5; */
|
||||
[53] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 3),
|
||||
@@ -113,7 +113,7 @@ main( int __unused argc,
|
||||
[57] = getop_prop_getter (240, 0, 240),
|
||||
[58] = getop_assignment (241, OPCODE_ARG_TYPE_SMALLINT, 25),
|
||||
[59] = getop_equal_value_type (240, 240, 241),
|
||||
[60] = getop_is_false_jmp (240, 2),
|
||||
[60] = getop_is_false_jmp_up (240, 0, 58),
|
||||
|
||||
/* b = delete a[b]; */
|
||||
[61] = getop_delete_prop (1, 0, 1),
|
||||
@@ -121,14 +121,14 @@ main( int __unused argc,
|
||||
/* assert (b === true); */
|
||||
[62] = getop_assignment (240, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_TRUE),
|
||||
[63] = getop_equal_value_type (240, 240, 1),
|
||||
[64] = getop_is_false_jmp (240, 2),
|
||||
[64] = getop_is_false_jmp_up (240, 0, 62),
|
||||
|
||||
/* assert (a.property1 === undefined); */
|
||||
[65] = getop_assignment (240, OPCODE_ARG_TYPE_STRING, 2),
|
||||
[66] = getop_prop_getter (240, 0, 240),
|
||||
[67] = getop_assignment (241, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
[68] = getop_equal_value_type (240, 240, 241),
|
||||
[69] = getop_is_false_jmp (240, 2),
|
||||
[69] = getop_is_false_jmp_up (240, 0, 67),
|
||||
|
||||
[70] = getop_exitval (0)
|
||||
};
|
||||
|
||||
@@ -1,94 +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 "globals.h"
|
||||
#include "interpreter.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "opcodes.h"
|
||||
#include "serializer.h"
|
||||
#include "optimizer-passes.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "deserializer.h"
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
opcode_t test_program[] = {
|
||||
[0] = getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
|
||||
[1] = getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
|
||||
[2] = getop_is_false_jmp (0, 10),
|
||||
[3] = getop_is_true_jmp (0, 6),
|
||||
[4] = getop_jmp_up (1),
|
||||
[5] = getop_jmp_up (4),
|
||||
[6] = getop_jmp_down (1),
|
||||
[7] = getop_jmp_down (2),
|
||||
[8] = getop_jmp_down (2),
|
||||
[9] = getop_assignment (0, OPCODE_ARG_TYPE_SMALLINT, 253),
|
||||
[10] = getop_exitval (0)
|
||||
};
|
||||
|
||||
mem_init();
|
||||
|
||||
const char *strings[] = { "a",
|
||||
"b" };
|
||||
ecma_number_t nums [] = { 2 };
|
||||
serializer_init (true);
|
||||
uint16_t offset = serializer_dump_strings (strings, 2);
|
||||
serializer_dump_nums (nums, 1, offset, 2);
|
||||
|
||||
for (int i = 0; i < 11; i++)
|
||||
serializer_dump_opcode (test_program[i]);
|
||||
|
||||
opcode_t * opcodes = (opcode_t *) deserialize_bytecode ();
|
||||
|
||||
optimizer_move_opcodes (opcodes + 9, opcodes + 2, 1);
|
||||
if (!opcodes_equal (opcodes, (opcode_t[]) {
|
||||
[0] = getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
|
||||
[1] = getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
|
||||
[2] = getop_assignment (0, OPCODE_ARG_TYPE_SMALLINT, 253),
|
||||
[3] = getop_is_false_jmp (0, 10),
|
||||
[4] = getop_is_true_jmp (0, 6),
|
||||
[5] = getop_jmp_up (1),
|
||||
[6] = getop_jmp_up (4),
|
||||
[7] = getop_jmp_down (1),
|
||||
[8] = getop_jmp_down (2),
|
||||
[9] = getop_jmp_down (2),
|
||||
[10] = getop_exitval (0)
|
||||
}, 11))
|
||||
return 1;
|
||||
|
||||
optimizer_adjust_jumps (opcodes + 3, opcodes + 10, 1);
|
||||
if (!opcodes_equal (opcodes, (opcode_t[]) {
|
||||
[0] = getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
|
||||
[1] = getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
|
||||
[2] = getop_assignment (0, OPCODE_ARG_TYPE_SMALLINT, 253),
|
||||
[3] = getop_is_false_jmp (0, 10),
|
||||
[4] = getop_is_true_jmp (0, 7),
|
||||
[5] = getop_jmp_up (1),
|
||||
[6] = getop_jmp_up (5),
|
||||
[7] = getop_jmp_down (1),
|
||||
[8] = getop_jmp_down (2),
|
||||
[9] = getop_jmp_down (1),
|
||||
[10] = getop_exitval (0)
|
||||
}, 11))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,98 +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 "globals.h"
|
||||
#include "serializer.h"
|
||||
#include "optimizer-passes.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "deserializer.h"
|
||||
#include "common.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "opcodes.h"
|
||||
|
||||
#define MAX_STRINGS 100
|
||||
#define MAX_NUMS 25
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
const char *strings[MAX_STRINGS];
|
||||
ecma_number_t nums[MAX_NUMS];
|
||||
uint8_t strings_num, nums_count;
|
||||
uint16_t offset;
|
||||
const opcode_t *opcodes;
|
||||
const char *source = "for (var i = 0; i < 10; i++) {\n"
|
||||
" var j = 10;\n"
|
||||
"}\n"
|
||||
"for (var i = 0; i < 10; i++) {\n"
|
||||
" var j = 10;\n"
|
||||
"}";
|
||||
|
||||
mem_init ();
|
||||
serializer_init (true);
|
||||
lexer_init (source, __strlen (source), true);
|
||||
lexer_run_first_pass();
|
||||
|
||||
strings_num = lexer_get_strings (strings);
|
||||
nums_count = lexer_get_nums (nums);
|
||||
lexer_adjust_num_ids ();
|
||||
|
||||
offset = serializer_dump_strings (strings, strings_num);
|
||||
serializer_dump_nums (nums, nums_count, offset, strings_num);
|
||||
|
||||
parser_init ();
|
||||
parser_parse_program ();
|
||||
|
||||
opcodes = deserialize_bytecode ();
|
||||
serializer_print_opcodes ();
|
||||
if (!opcodes_equal (opcodes, (opcode_t[]) {
|
||||
[0] = getop_reg_var_decl (2, 5), // var tmp2 .. tmp5;
|
||||
[1] = getop_var_decl (0), // var i;
|
||||
[2] = getop_var_decl (1), // var j;
|
||||
[3] = getop_assignment (2, 1, 0), // tmp2 = 0;
|
||||
[4] = getop_assignment (0, 4, 2), // i = tmp2;
|
||||
[5] = getop_assignment (4, 1, 10),// tmp4 = 10;
|
||||
[6] = getop_less_than (3, 0, 4), // tmp3 = i < tmp4;
|
||||
[7] = getop_is_false_jmp (3, 14), // if (!tmp3) goto 14;
|
||||
[8] = getop_jmp_down (3), // goto 11;
|
||||
[9] = getop_post_incr (5, 0), // tmp5 = i ++;
|
||||
[10] = getop_jmp_up (5), // goto 5;
|
||||
[11] = getop_assignment (2, 1, 10),// tmp2 = 10;
|
||||
[12] = getop_assignment (1, 4, 2), // j = tmp2;
|
||||
[13] = getop_jmp_up (5), // goto 8;
|
||||
[14] = getop_nop (), // ;
|
||||
[15] = getop_assignment (2, 1, 0), // tmp2 = 0;
|
||||
[16] = getop_assignment (0, 4, 2), // i = tmp2;
|
||||
[17] = getop_assignment (4, 1, 10),// tmp7 = 10;
|
||||
[18] = getop_less_than (3, 0, 4), // tmp3 = i < tmp7;
|
||||
[19] = getop_is_false_jmp (3, 27), // if (!tmp3) goto 27;
|
||||
[20] = getop_jmp_down (3), // goto 23;
|
||||
[21] = getop_post_incr (5, 0), // tmp5 = i ++;
|
||||
[22] = getop_jmp_up (5), // goto 17;
|
||||
[23] = getop_nop (), // ;
|
||||
[24] = getop_assignment (2, 1, 10),// tmp2 = 10;
|
||||
[25] = getop_assignment (1, 4, 5), // j = tmp2;
|
||||
[26] = getop_jmp_up (5), // goto 21;
|
||||
[27] = getop_exitval (0) // exit 0;
|
||||
}, 28))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,75 +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 "globals.h"
|
||||
#include "interpreter.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "opcodes.h"
|
||||
#include "serializer.h"
|
||||
#include "optimizer-passes.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "deserializer.h"
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
// Honestly, after RETVAL there must be RET
|
||||
opcode_t test_program[] = {
|
||||
[0] = getop_reg_var_decl (5, 5), // tmp6
|
||||
[1] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1), // a = "b"
|
||||
[2] = getop_var_decl (1), // var b
|
||||
[3] = getop_func_decl_0 (2), // function c()
|
||||
[4] = getop_jmp_down (3), // {
|
||||
[5] = getop_var_decl (1), // var b
|
||||
[6] = getop_retval (1), // return b; }
|
||||
[7] = getop_assignment (5, OPCODE_ARG_TYPE_STRING, 3), // "use strict"
|
||||
[8] = getop_exitval (0)
|
||||
};
|
||||
|
||||
mem_init();
|
||||
|
||||
const char *strings[] = { "a", "b", "c", "use strict" };
|
||||
ecma_number_t nums [] = { 2 };
|
||||
serializer_init (true);
|
||||
uint16_t offset = serializer_dump_strings (strings, 4);
|
||||
serializer_dump_nums (nums, 1, offset, 4);
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
serializer_dump_opcode (test_program[i]);
|
||||
|
||||
opcode_t * opcodes = (opcode_t *) deserialize_bytecode ();
|
||||
|
||||
optimizer_reorder_scope (1, 8);
|
||||
if (!opcodes_equal (opcodes, (opcode_t[]) {
|
||||
[0] = getop_reg_var_decl (5, 5), // tmp6
|
||||
[1] = getop_assignment (5, OPCODE_ARG_TYPE_STRING, 3), // "use strict"
|
||||
[2] = getop_func_decl_0 (2), // function c()
|
||||
[3] = getop_jmp_down (3), // {
|
||||
[4] = getop_var_decl (1), // var b
|
||||
[5] = getop_retval (1), // return b; }
|
||||
[6] = getop_var_decl (1), // var b
|
||||
[7] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1), // a = "b"
|
||||
[8] = getop_exitval (0)
|
||||
}, 9))
|
||||
return 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -38,11 +38,11 @@ main( int __unused argc,
|
||||
[ 8] = getop_meta (OPCODE_META_TYPE_CATCH, 0, 14),
|
||||
[ 9] = getop_meta (OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER, 2, 255),
|
||||
[10] = getop_equal_value_type (0, 1, 2),
|
||||
[11] = getop_is_true_jmp (0, 14),
|
||||
[11] = getop_is_true_jmp_down (0, 0, 3),
|
||||
[12] = getop_exitval (1),
|
||||
[13] = getop_assignment (0, OPCODE_ARG_TYPE_SIMPLE, ECMA_SIMPLE_VALUE_FALSE),
|
||||
[14] = getop_meta (OPCODE_META_TYPE_FINALLY, 0, 18),
|
||||
[15] = getop_is_false_jmp (0, 17),
|
||||
[15] = getop_is_false_jmp_down (0, 0, 2),
|
||||
[16] = getop_exitval (0),
|
||||
[17] = getop_exitval (1),
|
||||
[18] = getop_meta (OPCODE_META_TYPE_END_TRY_CATCH_FINALLY, 255, 255),
|
||||
|
||||
@@ -27,11 +27,11 @@ main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
const opcode_t test_program[] = {
|
||||
/* 0: */ getop_reg_var_decl( 255, 255),
|
||||
/* 1: */ getop_var_decl( 0),
|
||||
/* 2: */ getop_is_true_jmp( 0, 4),
|
||||
/* 3: */ getop_exitval( 0),
|
||||
/* 4: */ getop_exitval( 1)
|
||||
[0] = getop_reg_var_decl( 255, 255),
|
||||
[1] = getop_var_decl( 0),
|
||||
[2] = getop_is_true_jmp_down( 0, 0, 2),
|
||||
[3] = getop_exitval( 0),
|
||||
[4] = getop_exitval( 1)
|
||||
};
|
||||
|
||||
mem_init();
|
||||
|
||||
Reference in New Issue
Block a user