jerryscript/tests/unit/test_try_catch.c
Ilmir Usmanov e77bd4f4e5 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.
2014-09-16 21:32:59 +04:00

70 lines
2.2 KiB
C

/* 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"
/**
* Unit test's main function.
*/
int
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_try (0, 8),
[ 4] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1),
[ 5] = getop_assignment (1, OPCODE_ARG_TYPE_VARIABLE, 0),
[ 6] = getop_throw (1),
[ 7] = getop_assignment (1, OPCODE_ARG_TYPE_SMALLINT, 12),
[ 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_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_down (0, 0, 2),
[16] = getop_exitval (0),
[17] = getop_exitval (1),
[18] = getop_meta (OPCODE_META_TYPE_END_TRY_CATCH_FINALLY, 255, 255),
[19] = getop_exitval (1)
};
mem_init();
const char *strings[] = { "a",
"b",
"c" };
ecma_number_t nums [] = { 2.0 };
uint16_t offset = serializer_dump_strings( strings, 3);
serializer_dump_nums( nums, 1, offset, 3);
init_int( test_program, false);
bool is_ok = run_int();
serializer_free ();
mem_finalize (false);
return (is_ok ? 0 : 1);
} /* main */