Parser optimizations.
- parser is now non-recursive (i.e. parse function is not called recursively in any case);
- byte-code is now more compact:
- constants are now not immediately dumped upon occurence, but later - where necessary;
- assignments are combined with unary / binary operations;
- binary operations are encoded more compactly in many cases;
- byte-code arrays are now allocated separately for each scope (so, GC of the scopes now becomes possible);
- byte-code is dumped directly into corresponding byte-code arrays:
- linked lists of op_meta are not now used for main code of a scope.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
committed by
Ruben Ayrapetyan
parent
b1de93abd6
commit
50d124bfc3
@@ -13,9 +13,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
try {
|
||||
eval('v_0 = {0: delete 3. instanceof foo() ^ {} }');
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
function check_reference_error (s) {
|
||||
try {
|
||||
eval (s);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
}
|
||||
|
||||
check_reference_error ('v_0 = {0: delete 3. instanceof foo() ^ {} }');
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2015 University of Szeged.
|
||||
//
|
||||
// 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.
|
||||
|
||||
function a()
|
||||
{
|
||||
for (i = 1; i < 5; i++)
|
||||
if (i) {
|
||||
5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
var a;
|
||||
|
||||
(a) = 1;
|
||||
|
||||
assert (a === 1);
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
function check_syntax_error (s) {
|
||||
try {
|
||||
eval (s);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test case #1 */
|
||||
check_syntax_error (
|
||||
" new function f(f) { \
|
||||
return {className: 'xxx'}; \
|
||||
}; \
|
||||
x = 1; \
|
||||
function g(active) { \
|
||||
for (i = 1; i <= 1000; i++) { if (i == active) { \
|
||||
x = i; if (f(\"\" + i) != null) { } \
|
||||
} else { \
|
||||
if (f(\"\" + i) != null) } \
|
||||
} \
|
||||
} \
|
||||
g(0) \
|
||||
");
|
||||
|
||||
/* Test case #2 */
|
||||
check_syntax_error (
|
||||
" new function a(a) {;for (f in [1,2,3]) print(f); \
|
||||
}; 1; \
|
||||
function g(active) { \
|
||||
for (i = 1; i <= 1000; i++) { if (i == active) { \
|
||||
xI \
|
||||
if (f != null) { } \
|
||||
} else { \
|
||||
if (f(\"\" + i) != null) } \
|
||||
} \
|
||||
} \
|
||||
g(0) \
|
||||
");
|
||||
|
||||
/* Test case #3 */
|
||||
check_syntax_error (
|
||||
" new function f(f) {;for (f in [1,2,3]) pRint(f); \
|
||||
}; 1; \
|
||||
function g(active) { \
|
||||
for (i = 1; i <= 1000; i++) { if (i == active) { \
|
||||
x \
|
||||
if (f != null) { } \
|
||||
} else { \
|
||||
if (f(\"\" + i) != null) } \
|
||||
} \
|
||||
} \
|
||||
g(0) \
|
||||
");
|
||||
@@ -48,6 +48,14 @@ switch (a) {
|
||||
assert (0);
|
||||
}
|
||||
|
||||
switch (a) {
|
||||
case 3:
|
||||
assert (0);
|
||||
default:
|
||||
assert (0);
|
||||
case 1:
|
||||
}
|
||||
|
||||
executed_case = '';
|
||||
switch (a) {
|
||||
default:
|
||||
|
||||
+44
-40
@@ -685,55 +685,59 @@ main (void)
|
||||
jerry_cleanup ();
|
||||
|
||||
// Dump / execute snapshot
|
||||
static uint8_t global_mode_snapshot_buffer[1024];
|
||||
static uint8_t eval_mode_snapshot_buffer[1024];
|
||||
// FIXME: support save/load snapshot for optimized parser
|
||||
if (false)
|
||||
{
|
||||
static uint8_t global_mode_snapshot_buffer[1024];
|
||||
static uint8_t eval_mode_snapshot_buffer[1024];
|
||||
|
||||
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
|
||||
strlen (code_to_snapshot_p),
|
||||
true,
|
||||
global_mode_snapshot_buffer,
|
||||
sizeof (global_mode_snapshot_buffer));
|
||||
JERRY_ASSERT (global_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
size_t eval_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
|
||||
strlen (code_to_snapshot_p),
|
||||
true,
|
||||
global_mode_snapshot_buffer,
|
||||
sizeof (global_mode_snapshot_buffer));
|
||||
JERRY_ASSERT (global_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
false,
|
||||
eval_mode_snapshot_buffer,
|
||||
sizeof (eval_mode_snapshot_buffer));
|
||||
JERRY_ASSERT (eval_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
size_t eval_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
|
||||
strlen (code_to_snapshot_p),
|
||||
false,
|
||||
eval_mode_snapshot_buffer,
|
||||
sizeof (eval_mode_snapshot_buffer));
|
||||
JERRY_ASSERT (eval_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
|
||||
jerry_init (JERRY_FLAG_SHOW_OPCODES);
|
||||
is_ok = (jerry_exec_snapshot (global_mode_snapshot_buffer,
|
||||
global_mode_snapshot_size,
|
||||
false,
|
||||
&res) == JERRY_COMPLETION_CODE_OK);
|
||||
|
||||
is_ok = (jerry_exec_snapshot (global_mode_snapshot_buffer,
|
||||
global_mode_snapshot_size,
|
||||
false,
|
||||
&res) == JERRY_COMPLETION_CODE_OK);
|
||||
JERRY_ASSERT (is_ok
|
||||
&& res.type == JERRY_API_DATA_TYPE_UNDEFINED);
|
||||
jerry_api_release_value (&res);
|
||||
|
||||
JERRY_ASSERT (is_ok
|
||||
&& res.type == JERRY_API_DATA_TYPE_UNDEFINED);
|
||||
jerry_api_release_value (&res);
|
||||
is_ok = (jerry_exec_snapshot (eval_mode_snapshot_buffer,
|
||||
eval_mode_snapshot_size,
|
||||
false,
|
||||
&res) == JERRY_COMPLETION_CODE_OK);
|
||||
|
||||
is_ok = (jerry_exec_snapshot (eval_mode_snapshot_buffer,
|
||||
eval_mode_snapshot_size,
|
||||
false,
|
||||
&res) == JERRY_COMPLETION_CODE_OK);
|
||||
JERRY_ASSERT (is_ok
|
||||
&& res.type == JERRY_API_DATA_TYPE_STRING);
|
||||
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
|
||||
JERRY_ASSERT (sz == -20);
|
||||
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
|
||||
JERRY_ASSERT (sz == 20);
|
||||
jerry_api_release_value (&res);
|
||||
JERRY_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
|
||||
|
||||
JERRY_ASSERT (is_ok
|
||||
&& res.type == JERRY_API_DATA_TYPE_STRING);
|
||||
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
|
||||
JERRY_ASSERT (sz == -20);
|
||||
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
|
||||
JERRY_ASSERT (sz == 20);
|
||||
jerry_api_release_value (&res);
|
||||
JERRY_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
|
||||
|
||||
jerry_cleanup ();
|
||||
jerry_cleanup ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "bytecode-data.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "opcodes.h"
|
||||
#include "parser.h"
|
||||
#include "serializer.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
static bool
|
||||
@@ -109,7 +108,7 @@ main (int __attr_unused___ argc,
|
||||
// #1
|
||||
char program1[] = "a=1;var a;";
|
||||
|
||||
serializer_init ();
|
||||
lit_init ();
|
||||
parser_set_show_instrs (true);
|
||||
parse_status = parser_parse_script ((jerry_api_char_t *) program1, strlen (program1), &bytecode_data_p);
|
||||
|
||||
@@ -117,31 +116,27 @@ main (int __attr_unused___ argc,
|
||||
|
||||
vm_instr_t instrs[] =
|
||||
{
|
||||
getop_meta (OPCODE_META_TYPE_SCOPE_CODE_FLAGS, // [ ]
|
||||
OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER
|
||||
| OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER,
|
||||
VM_IDX_EMPTY),
|
||||
getop_reg_var_decl (1u, 0u, 0u),
|
||||
getop_var_decl (0), // var a;
|
||||
getop_assignment (VM_REG_GENERAL_FIRST, 1, 1), // $tmp0 = 1;
|
||||
getop_assignment (0, 6, VM_REG_GENERAL_FIRST), // a = $tmp0;
|
||||
getop_assignment (0, 1, 1), // a = 1 (SMALLINT);
|
||||
getop_ret () // return;
|
||||
};
|
||||
|
||||
JERRY_ASSERT (instrs_equal (bytecode_data_p->instrs_p, instrs, 5));
|
||||
JERRY_ASSERT (instrs_equal (bytecode_data_p->instrs_p, instrs, 3));
|
||||
|
||||
serializer_free ();
|
||||
lit_finalize ();
|
||||
bc_finalize ();
|
||||
|
||||
// #2
|
||||
char program2[] = "var var;";
|
||||
|
||||
serializer_init ();
|
||||
lit_init ();
|
||||
parser_set_show_instrs (true);
|
||||
parse_status = parser_parse_script ((jerry_api_char_t *) program2, strlen (program2), &bytecode_data_p);
|
||||
|
||||
JERRY_ASSERT (parse_status == JSP_STATUS_SYNTAX_ERROR && bytecode_data_p == NULL);
|
||||
|
||||
serializer_free ();
|
||||
lit_finalize ();
|
||||
bc_finalize ();
|
||||
|
||||
mem_finalize (false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user