From 91f2580162143e9e54947ca9f4b8ce6cc10e9d4b Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Fri, 4 Jul 2025 14:01:29 +0300 Subject: [PATCH 1/4] Fixed some handwritten primitive casts Signed-off-by: Alexander Gorshenev --- arkoala-arkts/arkui/src/ets/LazyForEach.ets | 14 +++++++------- .../src/ets/handwritten/ArkPageTransition.ets | 10 +++++----- .../arkui/src/ets/handwritten/resources.ets | 2 +- incremental/common/src/index.ts | 1 + incremental/compat/src/arkts/primitive.ts | 4 ++++ incremental/compat/src/index.ts | 1 + incremental/compat/src/ohos/index.ts | 1 + incremental/compat/src/typescript/primitive.ts | 4 ++++ .../runtime/test-arkts/animation/Easing.test.ts | 4 ++-- .../runtime/test-arkts/memo/repeat.test.ts | 16 ++++++++-------- .../runtime/test-arkts/tree/TreeNode.test.ts | 4 ++-- incremental/tools/panda/arkts/ui2abc | 2 +- 12 files changed, 37 insertions(+), 26 deletions(-) diff --git a/arkoala-arkts/arkui/src/ets/LazyForEach.ets b/arkoala-arkts/arkui/src/ets/LazyForEach.ets index 0744650d9..5c67873ec 100644 --- a/arkoala-arkts/arkui/src/ets/LazyForEach.ets +++ b/arkoala-arkts/arkui/src/ets/LazyForEach.ets @@ -171,11 +171,11 @@ export function LazyForEach(dataSource: IDataSource, let listener = remember((): InternalListener => new InternalListener(parent.peer.ptr, version)) const changeIndex = listener.flush(offset) // first item index that's affected by DataChange - const currentLocal = current.value >= 0 ? Math.max(current.value - offset, 0) as int32 : -1; // translated to local index + const currentLocal = current.value >= 0 ? Math.max(current.value - offset, 0).toInt() : -1; // translated to local index const visibleRange = new VisibleRange(parent, currentLocal, currentLocal) remember((): void => { dataSource.registerDataChangeListener(listener) - LazyForEachManager.OnRangeUpdate(visibleRange.parent, dataSource.totalCount() as int32, (currentIndex: int32, currentMark: pointer, end: int32) => { + LazyForEachManager.OnRangeUpdate(visibleRange.parent, dataSource.totalCount().toInt(), (currentIndex: int32, currentMark: pointer, end: int32) => { // console.log(`LazyForEach[${parent}]: current updated to ${currentIndex} ${currentMark} end=${end}`) current.value = currentIndex mark.value = currentMark @@ -185,15 +185,15 @@ export function LazyForEach(dataSource: IDataSource, // Subscribe to version changes. version.value - let generator = (element: T, index: number): int32 => keyGenerator ? hashCodeFromString(keyGenerator!(element, index)) : index as int32 - let index: number = visibleRange.indexUp as number + let generator = (element: T, index: number): int32 => keyGenerator ? hashCodeFromString(keyGenerator!(element, index)) : index.toInt() + let index: number = (visibleRange.indexUp).toDouble() - LazyForEachManager.Prepare(parent, dataSource.totalCount() as int32, offset) + LazyForEachManager.Prepare(parent, dataSource.totalCount().toInt(), offset) LazyForEachManager.SetInsertMark(parent, mark.value, false) while (index >= 0 && index < dataSource.totalCount()) { // console.log(`LazyForEach[${parent}]: index=${index}`) - const element: T = dataSource.getData(index as number) + const element: T = dataSource.getData(index) memoEntry2( __context(), generator(element, index), @@ -215,6 +215,6 @@ export function LazyForEach(dataSource: IDataSource, parent.setInsertMark(nullptr, false) // create DataNode to provide count information to parent - const identifier = new LazyForEachIdentifier(__id(), dataSource.totalCount() as int32, visibleRange.activeCount) + const identifier = new LazyForEachIdentifier(__id(), dataSource.totalCount().toInt(), visibleRange.activeCount) DataNode.attach(LazyForEachType, identifier) } diff --git a/arkoala-arkts/arkui/src/ets/handwritten/ArkPageTransition.ets b/arkoala-arkts/arkui/src/ets/handwritten/ArkPageTransition.ets index bb6aac78a..2463a42d9 100644 --- a/arkoala-arkts/arkui/src/ets/handwritten/ArkPageTransition.ets +++ b/arkoala-arkts/arkui/src/ets/handwritten/ArkPageTransition.ets @@ -14,7 +14,7 @@ import { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koala * limitations under the License. */ -import { int32, float32 } from "@koalaui/common" +import { int32, float32, float64ToInt } from "@koalaui/common" import { contextNode, remember } from "@koalaui/runtime" import { PeerNode, PeerNodeType } from "../PeerNode" import { @@ -97,10 +97,10 @@ function progressAnimation(state: RouterTransitionVisibility, style: ArkPageTran { return { propertyName: KEY_PAGE_TRANSITION_PROPERTY, - startValue: 0 as float32, - endValue: 1.0 as float32, - duration: (style.params.duration ?? 0) as int32, - delay: (style.params.delay ?? 0) as int32, + startValue: 0.0f, + endValue: 1.0f, + duration: (style.params.duration ?? 0.0).toInt(), + delay: (style.params.delay ?? 0.0).toInt(), curve: style.params.curve ?? Curve.EASE_OUT, onProgress: (state == RouterTransitionVisibility.Hiding && style._onExit != undefined) ? (progress: float32) => style._onExit!(RouteType.Pop, progress) : diff --git a/arkoala-arkts/arkui/src/ets/handwritten/resources.ets b/arkoala-arkts/arkui/src/ets/handwritten/resources.ets index 450e1991b..5f3905fb2 100644 --- a/arkoala-arkts/arkui/src/ets/handwritten/resources.ets +++ b/arkoala-arkts/arkui/src/ets/handwritten/resources.ets @@ -62,7 +62,7 @@ class ArkResource implements Resource { thisSerializer.release(); return this._id; } - thisSerializer.writeInt32(param.length as int32); + thisSerializer.writeInt32(param.length.toInt()); for (let i = 0; i < param.length; i++) { const params_element: string = param[i]; thisSerializer.writeString(params_element); diff --git a/incremental/common/src/index.ts b/incremental/common/src/index.ts index ec40ff6d2..832985e47 100644 --- a/incremental/common/src/index.ts +++ b/incremental/common/src/index.ts @@ -25,6 +25,7 @@ export { float64ToInt, float64ToLong, int32BitsFromFloat, + int32ToFloat64, Array_from_set, AtomicRef, CustomTextDecoder, diff --git a/incremental/compat/src/arkts/primitive.ts b/incremental/compat/src/arkts/primitive.ts index 99d14992b..e5f8e53f0 100644 --- a/incremental/compat/src/arkts/primitive.ts +++ b/incremental/compat/src/arkts/primitive.ts @@ -48,6 +48,10 @@ export function float64ToLong(value: float64): int64 { return value.toLong() } +export function int32ToFloat64(value: int32): float64 { + return value.toDouble() +} + export function charToInt(value: char): int32 { return value.toInt() } diff --git a/incremental/compat/src/index.ts b/incremental/compat/src/index.ts index 24e868eac..2ad1a467f 100644 --- a/incremental/compat/src/index.ts +++ b/incremental/compat/src/index.ts @@ -27,6 +27,7 @@ export { float32To64, float32FromBits, int32BitsFromFloat, + int32ToFloat64, charToInt, Thunk, finalizerRegister, diff --git a/incremental/compat/src/ohos/index.ts b/incremental/compat/src/ohos/index.ts index cafcfb1cd..49110ee3f 100644 --- a/incremental/compat/src/ohos/index.ts +++ b/incremental/compat/src/ohos/index.ts @@ -26,6 +26,7 @@ export { float64ToLong, float32To64, float32FromBits, + int32ToFloat64, int32BitsFromFloat, charToInt, Thunk, diff --git a/incremental/compat/src/typescript/primitive.ts b/incremental/compat/src/typescript/primitive.ts index 08ffda6e1..72b37b206 100644 --- a/incremental/compat/src/typescript/primitive.ts +++ b/incremental/compat/src/typescript/primitive.ts @@ -47,6 +47,10 @@ export function float64ToLong(value: float64): int64 { return value } +export function int32ToFloat64(value: int32): float64 { + return value +} + export function charToInt(value: string): int32 { return parseInt(value) } diff --git a/incremental/runtime/test-arkts/animation/Easing.test.ts b/incremental/runtime/test-arkts/animation/Easing.test.ts index 45bfb1445..4956731b4 100644 --- a/incremental/runtime/test-arkts/animation/Easing.test.ts +++ b/incremental/runtime/test-arkts/animation/Easing.test.ts @@ -22,8 +22,8 @@ function assertEasing(easing: EasingCurve, ...expected: int32[]) { const last = expected.length - 1 for (let i = 0; i <= last; i++) { Assert.equal( - Math.round(100 * easing((i as float64) / last)) as int32, - expected[i] as int32, + float64ToInt32(Math.round(100 * easing((i as float64) / last))) + expected[i], `i=${i}: expected=${expected[i]} - ${i / last} => ${easing(i / last)} => ${Math.round(100 * easing(i / last))}` ) } diff --git a/incremental/runtime/test-arkts/memo/repeat.test.ts b/incremental/runtime/test-arkts/memo/repeat.test.ts index 7cf348c58..a75f7fb39 100644 --- a/incremental/runtime/test-arkts/memo/repeat.test.ts +++ b/incremental/runtime/test-arkts/memo/repeat.test.ts @@ -15,7 +15,7 @@ // TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS import { Assert, suite, test } from "@koalaui/harness" -import { asArray, int32, KoalaCallsiteKey, toKoalaCallsiteKey as key } from "@koalaui/common" +import { asArray, int32, float64ToInt32, KoalaCallsiteKey, toKoalaCallsiteKey as key } from "@koalaui/common" import { GlobalStateManager, Repeat, @@ -113,7 +113,7 @@ suite("repeat tests", () => { GlobalStateManager.reset() const state = mutableState(createPages()) const root = TestNode.create((_) => { - Repeat(state.value.length as int32, (index: int32) => { + Repeat(float64ToInt32(state.value.length), (index: int32) => { state.value[index].page() // index-based key }) }) @@ -134,7 +134,7 @@ suite("repeat tests", () => { test("RepeatWithKey.insert", () => { testInsert((array) => { RepeatWithKey( - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -153,7 +153,7 @@ suite("repeat tests", () => { testInsert((array) => { RepeatRange( 0, - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) @@ -164,7 +164,7 @@ suite("repeat tests", () => { test("RepeatWithKey.remove", () => { testRemove((array) => { RepeatWithKey( - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -183,7 +183,7 @@ suite("repeat tests", () => { testRemove((array) => { RepeatRange( 0, - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) @@ -194,7 +194,7 @@ suite("repeat tests", () => { test("RepeatWithKey.swap", () => { testSwap((array) => { RepeatWithKey( - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -213,7 +213,7 @@ suite("repeat tests", () => { testSwap((array) => { RepeatRange( 0, - array.length as int32, + float64ToInt32(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) diff --git a/incremental/runtime/test-arkts/tree/TreeNode.test.ts b/incremental/runtime/test-arkts/tree/TreeNode.test.ts index f852bce5f..4eb1a9e90 100644 --- a/incremental/runtime/test-arkts/tree/TreeNode.test.ts +++ b/incremental/runtime/test-arkts/tree/TreeNode.test.ts @@ -15,7 +15,7 @@ // TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS import { Assert, suite, test } from "@koalaui/harness" -import { float64, int32, uint32 } from "@koalaui/common" +import { float64, float54ToInt32, int32, uint32 } from "@koalaui/common" import { TreeNode } from "../../src/tree/TreeNode" class StringNode extends TreeNode { @@ -166,7 +166,7 @@ suite("TreeNode", () => { Assert.isTrue(root.every((node, index) => { Assert.equal(index, count) count++ - return children[index as int32] === contentOf(node) + return children[float64AsInt32(index)] === contentOf(node) })) Assert.equal(count, 3) }) diff --git a/incremental/tools/panda/arkts/ui2abc b/incremental/tools/panda/arkts/ui2abc index e9c4652a4..87c697535 100755 --- a/incremental/tools/panda/arkts/ui2abc +++ b/incremental/tools/panda/arkts/ui2abc @@ -14,5 +14,5 @@ # limitations under the License. SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` -PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" +PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" --dump-plugin-ast -- Gitee From b01ea450bb72bc60ef41d2214cecf905920f39be Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Fri, 4 Jul 2025 14:02:54 +0300 Subject: [PATCH 2/4] dropped garbage Signed-off-by: Alexander Gorshenev --- incremental/tools/panda/arkts/ui2abc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incremental/tools/panda/arkts/ui2abc b/incremental/tools/panda/arkts/ui2abc index 87c697535..e9c4652a4 100755 --- a/incremental/tools/panda/arkts/ui2abc +++ b/incremental/tools/panda/arkts/ui2abc @@ -14,5 +14,5 @@ # limitations under the License. SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` -PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" --dump-plugin-ast +PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" -- Gitee From fb5c49ecf2745548157a774693e8b34494ceb8f0 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Fri, 4 Jul 2025 14:41:45 +0300 Subject: [PATCH 3/4] more Signed-off-by: Alexander Gorshenev --- incremental/runtime/test-arkts/animation/Easing.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incremental/runtime/test-arkts/animation/Easing.test.ts b/incremental/runtime/test-arkts/animation/Easing.test.ts index 4956731b4..e48a989d5 100644 --- a/incremental/runtime/test-arkts/animation/Easing.test.ts +++ b/incremental/runtime/test-arkts/animation/Easing.test.ts @@ -22,7 +22,7 @@ function assertEasing(easing: EasingCurve, ...expected: int32[]) { const last = expected.length - 1 for (let i = 0; i <= last; i++) { Assert.equal( - float64ToInt32(Math.round(100 * easing((i as float64) / last))) + float64ToInt32(Math.round(100 * easing((i as float64) / last))), expected[i], `i=${i}: expected=${expected[i]} - ${i / last} => ${easing(i / last)} => ${Math.round(100 * easing(i / last))}` ) -- Gitee From 5339d29432f4ba8018a73ce1fd088515ee94e7b9 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Fri, 4 Jul 2025 14:55:43 +0300 Subject: [PATCH 4/4] more Signed-off-by: Alexander Gorshenev --- .../runtime/test-arkts/animation/Easing.test.ts | 4 ++-- .../runtime/test-arkts/memo/repeat.test.ts | 16 ++++++++-------- .../runtime/test-arkts/tree/TreeNode.test.ts | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/incremental/runtime/test-arkts/animation/Easing.test.ts b/incremental/runtime/test-arkts/animation/Easing.test.ts index e48a989d5..e382d4a4f 100644 --- a/incremental/runtime/test-arkts/animation/Easing.test.ts +++ b/incremental/runtime/test-arkts/animation/Easing.test.ts @@ -15,14 +15,14 @@ // TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS import { Assert, suite, test } from "@koalaui/harness" -import { float64, int32 } from "@koalaui/common" +import { float64, float64ToInt, int32 } from "@koalaui/common" import { Easing, EasingCurve, EasingStepJump } from "../../src/animation/Easing" function assertEasing(easing: EasingCurve, ...expected: int32[]) { const last = expected.length - 1 for (let i = 0; i <= last; i++) { Assert.equal( - float64ToInt32(Math.round(100 * easing((i as float64) / last))), + float64ToInt(Math.round(100 * easing((i as float64) / last))), expected[i], `i=${i}: expected=${expected[i]} - ${i / last} => ${easing(i / last)} => ${Math.round(100 * easing(i / last))}` ) diff --git a/incremental/runtime/test-arkts/memo/repeat.test.ts b/incremental/runtime/test-arkts/memo/repeat.test.ts index a75f7fb39..f42dea0ed 100644 --- a/incremental/runtime/test-arkts/memo/repeat.test.ts +++ b/incremental/runtime/test-arkts/memo/repeat.test.ts @@ -15,7 +15,7 @@ // TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS import { Assert, suite, test } from "@koalaui/harness" -import { asArray, int32, float64ToInt32, KoalaCallsiteKey, toKoalaCallsiteKey as key } from "@koalaui/common" +import { asArray, int32, float64ToInt, KoalaCallsiteKey, toKoalaCallsiteKey as key } from "@koalaui/common" import { GlobalStateManager, Repeat, @@ -113,7 +113,7 @@ suite("repeat tests", () => { GlobalStateManager.reset() const state = mutableState(createPages()) const root = TestNode.create((_) => { - Repeat(float64ToInt32(state.value.length), (index: int32) => { + Repeat(float64ToInt(state.value.length), (index: int32) => { state.value[index].page() // index-based key }) }) @@ -134,7 +134,7 @@ suite("repeat tests", () => { test("RepeatWithKey.insert", () => { testInsert((array) => { RepeatWithKey( - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -153,7 +153,7 @@ suite("repeat tests", () => { testInsert((array) => { RepeatRange( 0, - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) @@ -164,7 +164,7 @@ suite("repeat tests", () => { test("RepeatWithKey.remove", () => { testRemove((array) => { RepeatWithKey( - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -183,7 +183,7 @@ suite("repeat tests", () => { testRemove((array) => { RepeatRange( 0, - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) @@ -194,7 +194,7 @@ suite("repeat tests", () => { test("RepeatWithKey.swap", () => { testSwap((array) => { RepeatWithKey( - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index].id, (index: int32) => { array[index].page() }) }) @@ -213,7 +213,7 @@ suite("repeat tests", () => { testSwap((array) => { RepeatRange( 0, - float64ToInt32(array.length), + float64ToInt(array.length), (index: int32) => array[index], (element: Page, _: int32) => element.id, (element: Page, _: int32) => { element.page() }) diff --git a/incremental/runtime/test-arkts/tree/TreeNode.test.ts b/incremental/runtime/test-arkts/tree/TreeNode.test.ts index 4eb1a9e90..4a00c58aa 100644 --- a/incremental/runtime/test-arkts/tree/TreeNode.test.ts +++ b/incremental/runtime/test-arkts/tree/TreeNode.test.ts @@ -15,7 +15,7 @@ // TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS import { Assert, suite, test } from "@koalaui/harness" -import { float64, float54ToInt32, int32, uint32 } from "@koalaui/common" +import { float64, float64ToInt, int32, uint32 } from "@koalaui/common" import { TreeNode } from "../../src/tree/TreeNode" class StringNode extends TreeNode { @@ -166,7 +166,7 @@ suite("TreeNode", () => { Assert.isTrue(root.every((node, index) => { Assert.equal(index, count) count++ - return children[float64AsInt32(index)] === contentOf(node) + return children[float64ToInt(index)] === contentOf(node) })) Assert.equal(count, 3) }) -- Gitee