diff --git a/benchmarks/jerry/loop_arithmetics.js b/benchmarks/jerry/loop_arithmetics.js new file mode 100644 index 000000000..a1537913f --- /dev/null +++ b/benchmarks/jerry/loop_arithmetics.js @@ -0,0 +1,30 @@ +// 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. + +var count = 10000000; +var x = 7; +var y = 3; + +var tmp1; +var tmp2; +var tmp3; +var tmp4; + +for (var i = 0; i < count; i++) +{ + tmp1 = x * x; + tmp2 = y * y; + tmp3 = tmp1 * tmp1; + tmp4 = tmp2 * tmp2; +} diff --git a/src/generated.h b/src/generated.h index 111a64bf9..c46ac9190 100644 --- a/src/generated.h +++ b/src/generated.h @@ -16,20 +16,115 @@ #include "globals.h" static const char* generated_source = "" -"var count = 10000;\n" -"var x = 7;\n" -"var y = 3;\n" +"var tmp, a, b = 1, c = 2, d, e = 3, g = 4;\n" "\n" -"var tmp1;\n" -"var tmp2;\n" -"var tmp3;\n" -"var tmp4;\n" +"var count = 1000;\n" "\n" -"for (var i = 0; i < count; i++)\n" +"tmp = b * c;\n" +"a = tmp + g;\n" +"d = tmp * e + a;\n" +"\n" +"var waitTime = 600000;\n" +"var numOfIterations = 10;\n" +"\n" +"while (1)\n" "{\n" -"tmp1 = x * x;\n" -"tmp2 = y * y;\n" -"tmp3 = tmp1 * tmp1;\n" -"tmp4 = tmp2 * tmp2;\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"LEDOn(13);\n" +"LEDOn(14);\n" +"LEDOn(15);\n" +"wait(waitTime * 2);\n" +"LEDOff(12);\n" +"LEDOff(13);\n" +"LEDOff(14);\n" +"LEDOff(15);\n" +"wait(waitTime * 2);\n" +"}\n" +"\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"wait(waitTime);\n" +"LEDOff(12);\n" +"wait(waitTime);\n" +"LEDOn(13);\n" +"wait(waitTime);\n" +"LEDOff(13);\n" +"wait(waitTime);\n" +"LEDOn(14);\n" +"wait(waitTime);\n" +"LEDOff(14);\n" +"wait(waitTime);\n" +"LEDOn(15);\n" +"wait(waitTime);\n" +"LEDOff(15);\n" +"wait(waitTime);\n" +"}\n" +"\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"wait(waitTime);\n" +"LEDOff(12);\n" +"LEDOn(13);\n" +"wait(waitTime);\n" +"LEDOff(13);\n" +"LEDOn(14);\n" +"wait(waitTime);\n" +"LEDOff(14);\n" +"LEDOn(15);\n" +"wait(waitTime);\n" +"LEDOff(15);\n" +"}\n" +"\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"wait(waitTime / 2);\n" +"LEDOff(12);\n" +"LEDOn(13);\n" +"wait(waitTime / 2);\n" +"LEDOff(13);\n" +"LEDOn(14);\n" +"wait(waitTime / 2);\n" +"LEDOff(14);\n" +"LEDOn(15);\n" +"wait(waitTime / 2);\n" +"LEDOff(15);\n" +"}\n" +"\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"wait(waitTime / 3);\n" +"LEDOff(12);\n" +"LEDOn(13);\n" +"wait(waitTime / 3);\n" +"LEDOff(13);\n" +"LEDOn(14);\n" +"wait(waitTime / 3);\n" +"LEDOff(14);\n" +"LEDOn(15);\n" +"wait(waitTime / 3);\n" +"LEDOff(15);\n" +"}\n" +"\n" +"for (var j = 0; j < numOfIterations; j += 1)\n" +"{\n" +"LEDOn(12);\n" +"wait(waitTime / 6);\n" +"LEDOff(12);\n" +"LEDOn(13);\n" +"wait(waitTime / 6);\n" +"LEDOff(13);\n" +"LEDOn(14);\n" +"wait(waitTime / 6);\n" +"LEDOff(14);\n" +"LEDOn(15);\n" +"wait(waitTime / 6);\n" +"LEDOff(15);\n" +"}\n" "}\n" ; diff --git a/src/libecmaoperations/ecma-get-put-value.c b/src/libecmaoperations/ecma-get-put-value.c index f542ca54e..b0b593809 100644 --- a/src/libecmaoperations/ecma-get-put-value.c +++ b/src/libecmaoperations/ecma-get-put-value.c @@ -18,8 +18,11 @@ */ #include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" +#include "ecma-objects-properties.h" #include "ecma-operations.h" /** \addtogroup ecma ---TODO--- @@ -135,13 +138,19 @@ ecma_op_put_value(ecma_reference_t ref, /**< ECMA-reference */ return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_REFERENCE)); } else // PutValue_3.b { - /* - ecma_object_t *global_object_p = ecma_GetGlobalObject(); + ecma_object_t *global_object_p = ecma_get_global_object(); - return global_object_p->[[Put]]( ref.referenced_name_p, value, false); - */ + ecma_completion_value_t completion = ecma_op_object_put( global_object_p, + ref.referenced_name_p, + value, + false); - JERRY_UNIMPLEMENTED(); + ecma_deref_object( global_object_p); + + JERRY_ASSERT( ecma_is_completion_value_normal_true( completion) + || ecma_is_completion_value_normal_false( completion) ); + + return ecma_make_empty_completion_value(); } } else if ( is_property_reference ) // PutValue_4 { diff --git a/src/libecmaoperations/ecma-global-object.c b/src/libecmaoperations/ecma-global-object.c index e421c7f07..2275c478e 100644 --- a/src/libecmaoperations/ecma-global-object.c +++ b/src/libecmaoperations/ecma-global-object.c @@ -14,6 +14,7 @@ */ #include "globals.h" +#include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-global-object.h" #include "ecma-helpers.h" @@ -26,6 +27,27 @@ * @{ */ +/** + * Global object + */ +static ecma_object_t* ecma_global_object_p = NULL; + +/** + * Get Global object + * + * @return pointer to the Global object + * caller should free the reference by calling ecma_deref_object + */ +ecma_object_t* +ecma_get_global_object( void) +{ + JERRY_ASSERT( ecma_global_object_p != NULL ); + + ecma_ref_object( ecma_global_object_p); + + return ecma_global_object_p; +} /* ecma_get_global_object */ + /** * The Global Object construction routine. * @@ -36,6 +58,8 @@ ecma_object_t* ecma_op_create_global_object( void) { + JERRY_ASSERT( ecma_global_object_p == NULL ); + ecma_object_t *glob_obj_p = ecma_create_object( NULL, true, ECMA_OBJECT_TYPE_GENERAL); ecma_property_t *undefined_prop_p = ecma_create_named_data_property( glob_obj_p, @@ -47,6 +71,9 @@ ecma_op_create_global_object( void) TODO( /* Define NaN, Infinity, eval, parseInt, parseFloat, isNaN, isFinite properties */ ); + ecma_ref_object( glob_obj_p); + ecma_global_object_p = glob_obj_p; + return glob_obj_p; } /* ecma_op_create_global_object */ diff --git a/src/libecmaoperations/ecma-global-object.h b/src/libecmaoperations/ecma-global-object.h index 60782170a..d0c2cdd61 100644 --- a/src/libecmaoperations/ecma-global-object.h +++ b/src/libecmaoperations/ecma-global-object.h @@ -25,6 +25,7 @@ * @{ */ +extern ecma_object_t* ecma_get_global_object(void); extern ecma_object_t* ecma_op_create_global_object( void); /** diff --git a/src/libecmaoperations/ecma-objects-properties.c b/src/libecmaoperations/ecma-objects-properties.c index 008647f9f..e24eafe23 100644 --- a/src/libecmaoperations/ecma-objects-properties.c +++ b/src/libecmaoperations/ecma-objects-properties.c @@ -212,7 +212,8 @@ ecma_op_object_put( ecma_object_t *obj_p, /**< the object */ ecma_property_t *own_desc_p = ecma_op_object_get_own_property( obj_p, property_name_p); // 3. - if ( own_desc_p->type == ECMA_PROPERTY_NAMEDDATA ) + if ( own_desc_p != NULL + && own_desc_p->type == ECMA_PROPERTY_NAMEDDATA ) { // a. ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor(); @@ -232,7 +233,8 @@ ecma_op_object_put( ecma_object_t *obj_p, /**< the object */ ecma_property_t *desc_p = ecma_op_object_get_property( obj_p, property_name_p); // 5. - if ( desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR ) + if ( desc_p != NULL + && desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR ) { // a. ecma_object_t *setter_p = ecma_get_pointer( desc_p->u.named_accessor_property.set_p); diff --git a/src/main.c b/src/main.c index 7c8eeefae..e01a6e06a 100644 --- a/src/main.c +++ b/src/main.c @@ -130,12 +130,17 @@ read_sources (const char *script_file_names[], __rewind( file); - const size_t source_size = (size_t)script_len; - size_t bytes_read = 0; + const size_t current_source_size = (size_t)script_len; - while ( bytes_read < source_size ) + if ( source_buffer_tail + current_source_size >= source_buffer + sizeof(source_buffer) ) { - bytes_read += __fread( source_buffer_tail, 1, source_size, file); + jerry_exit (ERR_MEMORY); + } + + size_t bytes_read = 0; + while ( bytes_read < current_source_size ) + { + bytes_read += __fread( source_buffer_tail + bytes_read, sizeof(uint8_t), current_source_size - bytes_read, file); if ( __ferror( file) != 0 ) { @@ -145,11 +150,14 @@ read_sources (const char *script_file_names[], __fclose( file); - source_buffer_tail += source_size; - - *out_source_size_p += source_size; + source_buffer_tail += current_source_size; } + const size_t source_size = (size_t) (source_buffer_tail - source_buffer); + JERRY_ASSERT( source_size < sizeof(source_buffer) ); + + *out_source_size_p = source_size; + return (const char*)source_buffer; } diff --git a/tests/jerry/arithmetics.js b/tests/jerry/arithmetics.js new file mode 100644 index 000000000..5400f2d16 --- /dev/null +++ b/tests/jerry/arithmetics.js @@ -0,0 +1,19 @@ +// 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. + +var a = 1; +var b = 2; + +assertEquals(a+b, 3); +assertEquals(b+a, 3); diff --git a/tools/generator.sh b/tools/generator.sh index af4ae2fa5..d53880610 100755 --- a/tools/generator.sh +++ b/tools/generator.sh @@ -14,12 +14,12 @@ #!/bin/bash -echo "#include \"globals.h\"" > "generated.h" -echo "" >> "generated.h" -echo "static const char* generated_source = \"\"" >> "generated.h" +echo "#include \"globals.h\"" > $2 +echo "" >> $2 +echo "static const char* generated_source = \"\"" >> $2 while read line do - echo "\"$line\n\"" >> "generated.h" + echo "\"$line\n\"" >> $2 done < $1 -echo ";" >> "generated.h" +echo ";" >> $2