From ce3e6344605e51d9fc7295040da103c641333a93 Mon Sep 17 00:00:00 2001 From: Korobkov Ilya Date: Thu, 19 Oct 2023 09:52:30 +0300 Subject: [PATCH 1/3] Added default value for input parameter and checking the size of string before call native code Signed-off-by: Korobkov Ilya --- plugins/ets/stdlib/std/core/String.ets | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/ets/stdlib/std/core/String.ets b/plugins/ets/stdlib/std/core/String.ets index 9e859cf70..8ac194cc8 100644 --- a/plugins/ets/stdlib/std/core/String.ets +++ b/plugins/ets/stdlib/std/core/String.ets @@ -606,8 +606,11 @@ export final class String extends Object implements Comparable, JSONable * * @returns new String which is a concatenation of this + to */ - public concat(to: String): String { - return StringBuilder.concatStrings(this, to); + public concat(to: String = ""): String { + if (0 < to.length()) { + return StringBuilder.concatStrings(this, to); + } + return this; } /* -- Gitee From eda7f8711fef5f685c1715c1ce534c766fcf4e19 Mon Sep 17 00:00:00 2001 From: dr-irina Date: Tue, 17 Oct 2023 13:27:10 +0300 Subject: [PATCH 2/3] add toString for numeric types with radix parameter Signed-off-by: dr-irina --- plugins/ets/stdlib/std/core/Byte.ets | 9 +++++++ plugins/ets/stdlib/std/core/Int.ets | 9 +++++++ plugins/ets/stdlib/std/core/Long.ets | 36 +++++++++++++++++++++++++++ plugins/ets/stdlib/std/core/Short.ets | 9 +++++++ 4 files changed, 63 insertions(+) diff --git a/plugins/ets/stdlib/std/core/Byte.ets b/plugins/ets/stdlib/std/core/Byte.ets index d8650ce89..508e4f7c5 100644 --- a/plugins/ets/stdlib/std/core/Byte.ets +++ b/plugins/ets/stdlib/std/core/Byte.ets @@ -189,6 +189,15 @@ export final class Byte extends Integral implements Comparable, JSONable, JSONable, JSONable 36) { + throw new RangeError('Radix must be between 2 and 36'); + } + if (this.value == 0) { + return "0"; + } + const chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + let val = this.value; + let negative: boolean = (val < 0); + let digitsNum = (log(abs(val)) / log(radix as int) + 1) as int; + if (negative) { + ++digitsNum; + } + let data = new char[digitsNum]; + let curPlace = digitsNum - 1; + while (val != 0) { + let remainder = val % (radix as int); + if (negative) { + remainder = -remainder; + } + data[curPlace] = chars.charAt(remainder as int); + val /= (radix as int); + curPlace -= 1; + } + if (negative) { + data[0] = c'-'; + } + return new String(data); + } + /** * Returns a hash code (integer representation) for this instance * diff --git a/plugins/ets/stdlib/std/core/Short.ets b/plugins/ets/stdlib/std/core/Short.ets index 45f097a91..f87d8bc58 100644 --- a/plugins/ets/stdlib/std/core/Short.ets +++ b/plugins/ets/stdlib/std/core/Short.ets @@ -188,6 +188,15 @@ export final class Short extends Integral implements Comparable, JSONable return new String(data); } + /** + * Converts this object to a string + * + * @returns result of the conversion + */ + public toString(radix: number): string { + return (new Long(this.value)).toString(radix); + } + /** * Returns a hash code (shorteger representation) for this instance * -- Gitee From 09d63ccdc32dbc5fbcfaba907a50b86741cfc8fb Mon Sep 17 00:00:00 2001 From: Ivan Tyulyandin Date: Fri, 27 Oct 2023 09:26:16 +0300 Subject: [PATCH 3/3] [ArkTS] Fix build without benchmarks Signed-off-by: Ivan Tyulyandin --- .../ets/tests/micro-benchmarks/CMakeLists.txt | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/plugins/ets/tests/micro-benchmarks/CMakeLists.txt b/plugins/ets/tests/micro-benchmarks/CMakeLists.txt index a671048e1..989bc503b 100644 --- a/plugins/ets/tests/micro-benchmarks/CMakeLists.txt +++ b/plugins/ets/tests/micro-benchmarks/CMakeLists.txt @@ -15,63 +15,65 @@ if (CMAKE_CROSSCOMPILING) return() endif() -add_custom_target(ets_microbenchmarks COMMENT "Running ets micro-benchmarks") -add_dependencies(benchmarks ets_microbenchmarks) +if(PANDA_WITH_BENCHMARKS) + add_custom_target(ets_microbenchmarks COMMENT "Running ets micro-benchmarks") + add_dependencies(benchmarks ets_microbenchmarks) -set(INTERPRETER_ARGUMENTS_LIST "cpp") -set(MODES_LIST "int" "jit" "aot") + set(INTERPRETER_ARGUMENTS_LIST "cpp") + set(MODES_LIST "int" "jit" "aot") -if(PANDA_TARGET_ARM64 OR PANDA_TARGET_AMD64) - list(APPEND INTERPRETER_ARGUMENTS_LIST "irtoc") - if (PANDA_LLVMAOT) - list(APPEND INTERPRETER_ARGUMENTS_LIST "llvm") + if(PANDA_TARGET_ARM64 OR PANDA_TARGET_AMD64) + list(APPEND INTERPRETER_ARGUMENTS_LIST "irtoc") + if (PANDA_LLVMAOT) + list(APPEND INTERPRETER_ARGUMENTS_LIST "llvm") + endif() endif() -endif() -set(script_dir "${PANDA_ROOT}/plugins/ets/tests/scripts/micro-benchmarks") + set(script_dir "${PANDA_ROOT}/plugins/ets/tests/scripts/micro-benchmarks") -string(TOLOWER "${CMAKE_BUILD_TYPE}" cm_build_type) -if ("${cm_build_type}" STREQUAL "") - set(cm_build_type "debug") -endif() -if ("${cm_build_type}" STREQUAL "debug") - set(benchmark_timeout "5s") -endif() -if ("${cm_build_type}" STREQUAL "fastverify") - set(benchmark_timeout "5s") -endif() + string(TOLOWER "${CMAKE_BUILD_TYPE}" cm_build_type) + if ("${cm_build_type}" STREQUAL "") + set(cm_build_type "debug") + endif() + if ("${cm_build_type}" STREQUAL "debug") + set(benchmark_timeout "5s") + endif() + if ("${cm_build_type}" STREQUAL "fastverify") + set(benchmark_timeout "5s") + endif() -if (NOT "${benchmark_timeout}" STREQUAL "") - set(timeout_signal 10) - set(timeout_prefix "timeout --preserve-status --signal=${timeout_signal} --kill-after=10s ${benchmark_timeout}") - set(timeout_suffix "|| [ `expr \$? % 128` -eq ${timeout_signal} ]") -else() - set(timeout_prefix "") - set(timeout_suffix "") -endif() + if (NOT "${benchmark_timeout}" STREQUAL "") + set(timeout_signal 10) + set(timeout_prefix "timeout --preserve-status --signal=${timeout_signal} --kill-after=10s ${benchmark_timeout}") + set(timeout_suffix "|| [ `expr \$? % 128` -eq ${timeout_signal} ]") + else() + set(timeout_prefix "") + set(timeout_suffix "") + endif() -foreach(mode_arg ${MODES_LIST}) - foreach(int_arg ${INTERPRETER_ARGUMENTS_LIST}) - set(launch_file "${CMAKE_CURRENT_BINARY_DIR}/launch_${mode_arg}_${int_arg}.sh") - set(error_file "${CMAKE_CURRENT_BINARY_DIR}/run_${mode_arg}_${int_arg}.err") - set(launcher - "${timeout_prefix}" - "python3 run_micro_benchmarks.py --bindir ${CMAKE_BINARY_DIR}/bin --interpreter-type=${int_arg} --mode=${mode_arg} --log-level=silence" - "${timeout_suffix}" - "2> ${error_file}" - ) - string(REPLACE ";" " " launcher "${launcher}") - file(GENERATE OUTPUT ${launch_file} CONTENT "${launcher}") + foreach(mode_arg ${MODES_LIST}) + foreach(int_arg ${INTERPRETER_ARGUMENTS_LIST}) + set(launch_file "${CMAKE_CURRENT_BINARY_DIR}/launch_${mode_arg}_${int_arg}.sh") + set(error_file "${CMAKE_CURRENT_BINARY_DIR}/run_${mode_arg}_${int_arg}.err") + set(launcher + "${timeout_prefix}" + "python3 run_micro_benchmarks.py --bindir ${CMAKE_BINARY_DIR}/bin --interpreter-type=${int_arg} --mode=${mode_arg} --log-level=silence" + "${timeout_suffix}" + "2> ${error_file}" + ) + string(REPLACE ";" " " launcher "${launcher}") + file(GENERATE OUTPUT ${launch_file} CONTENT "${launcher}") - add_custom_target(ets_microbenchmarks_${mode_arg}_${int_arg} - COMMENT "Running ${ARG_TARGET}" - COMMAND . ${launch_file} || (cat ${error_file} && false) - WORKING_DIRECTORY ${script_dir} - DEPENDS ark etsstdlib ark_asm ark_aot - ) - add_dependencies(ets_microbenchmarks ets_microbenchmarks_${mode_arg}_${int_arg}) + add_custom_target(ets_microbenchmarks_${mode_arg}_${int_arg} + COMMENT "Running ${ARG_TARGET}" + COMMAND . ${launch_file} || (cat ${error_file} && false) + WORKING_DIRECTORY ${script_dir} + DEPENDS ark etsstdlib ark_asm ark_aot + ) + add_dependencies(ets_microbenchmarks ets_microbenchmarks_${mode_arg}_${int_arg}) + endforeach() endforeach() -endforeach() +endif() add_dependencies(ets_tests sampler_etsnapi_test_suite) \ No newline at end of file -- Gitee