From cf666f80042249f98d22fd8d887a3c592c5b2b8d Mon Sep 17 00:00:00 2001 From: CharlieTap Date: Wed, 15 Jan 2025 20:56:36 +0000 Subject: [PATCH] remove branch from pushing frames --- build.gradle.kts | 4 +++- .../executor/invoker/function/WasmFunctionCall.kt | 2 +- .../chasm/executor/runtime/ext/StackExt.kt | 7 +++---- .../chasm/executor/runtime/StackExtTest.kt | 12 +++++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 52261a6e..76d4d96b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ + + plugins { alias(libs.plugins.kotlin.allopen) apply false alias(libs.plugins.kotlin.android) apply false @@ -14,7 +16,7 @@ plugins { alias(libs.plugins.conventions.kmp) apply false alias(libs.plugins.conventions.publishing) apply false - alias(libs.plugins.conventions.linting) + alias(libs.plugins.conventions.linting) apply false alias(libs.plugins.conventions.versions) } diff --git a/executor/invoker/src/commonMain/kotlin/io/github/charlietap/chasm/executor/invoker/function/WasmFunctionCall.kt b/executor/invoker/src/commonMain/kotlin/io/github/charlietap/chasm/executor/invoker/function/WasmFunctionCall.kt index 353baa89..f5d3ebb6 100644 --- a/executor/invoker/src/commonMain/kotlin/io/github/charlietap/chasm/executor/invoker/function/WasmFunctionCall.kt +++ b/executor/invoker/src/commonMain/kotlin/io/github/charlietap/chasm/executor/invoker/function/WasmFunctionCall.kt @@ -55,7 +55,7 @@ internal inline fun WasmFunctionCall( instance = instance.module, ) - stack.pushFrame(frame).bind() + stack.pushFrame(frame) stack.push(frameCleaner) val label = Stack.Entry.Label( diff --git a/executor/runtime-internal/src/commonMain/kotlin/io/github/charlietap/chasm/executor/runtime/ext/StackExt.kt b/executor/runtime-internal/src/commonMain/kotlin/io/github/charlietap/chasm/executor/runtime/ext/StackExt.kt index 01681fe8..734f080f 100644 --- a/executor/runtime-internal/src/commonMain/kotlin/io/github/charlietap/chasm/executor/runtime/ext/StackExt.kt +++ b/executor/runtime-internal/src/commonMain/kotlin/io/github/charlietap/chasm/executor/runtime/ext/StackExt.kt @@ -36,14 +36,13 @@ inline fun Stack.pushf64(f64: Double) { push(F64(f64)) } -inline fun Stack.pushFrame(frame: ActivationFrame): Result { +inline fun Stack.pushFrame(frame: ActivationFrame) { return try { push(frame) - Ok(Unit) } catch (_: IndexOutOfBoundsException) { - Err(InvocationError.CallStackExhausted) + throw InvocationException(InvocationError.CallStackExhausted) } catch (_: IllegalArgumentException) { - Err(InvocationError.CallStackExhausted) + throw InvocationException(InvocationError.CallStackExhausted) } } diff --git a/executor/runtime-internal/src/commonTest/kotlin/io/github/charlietap/chasm/executor/runtime/StackExtTest.kt b/executor/runtime-internal/src/commonTest/kotlin/io/github/charlietap/chasm/executor/runtime/StackExtTest.kt index c0910dcb..ff4c4dd3 100644 --- a/executor/runtime-internal/src/commonTest/kotlin/io/github/charlietap/chasm/executor/runtime/StackExtTest.kt +++ b/executor/runtime-internal/src/commonTest/kotlin/io/github/charlietap/chasm/executor/runtime/StackExtTest.kt @@ -1,8 +1,7 @@ package io.github.charlietap.chasm.executor.runtime -import com.github.michaelbull.result.Err -import com.github.michaelbull.result.Ok import io.github.charlietap.chasm.executor.runtime.error.InvocationError +import io.github.charlietap.chasm.executor.runtime.exception.InvocationException import io.github.charlietap.chasm.executor.runtime.ext.binaryOperation import io.github.charlietap.chasm.executor.runtime.ext.constOperation import io.github.charlietap.chasm.executor.runtime.ext.convertOperation @@ -18,6 +17,7 @@ import io.github.charlietap.chasm.fixture.executor.runtime.stack import io.github.charlietap.chasm.fixture.executor.runtime.stack.frame import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class StackExtTest { @@ -29,7 +29,7 @@ class StackExtTest { val actual = stack.pushFrame(frame) - assertEquals(Ok(Unit), actual) + assertEquals(Unit, actual) assertEquals(1, stack.size()) val frameEntry = stack.popFrameOrNull() @@ -44,9 +44,11 @@ class StackExtTest { frames = List(Stack.MAX_DEPTH) { frame }, ) - val actual = stack.pushFrame(frame) + val actual = assertFailsWith { + stack.pushFrame(frame) + } - assertEquals(Err(InvocationError.CallStackExhausted), actual) + assertEquals(InvocationError.CallStackExhausted, actual.error) assertEquals(Stack.MAX_DEPTH, stack.size()) }