Skip to content

Commit

Permalink
remove branch from pushing frames
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieTap committed Jan 15, 2025
1 parent e56c29b commit cf666f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


plugins {
alias(libs.plugins.kotlin.allopen) apply false
alias(libs.plugins.kotlin.android) apply false
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ inline fun Stack.pushf64(f64: Double) {
push(F64(f64))
}

inline fun Stack.pushFrame(frame: ActivationFrame): Result<Unit, InvocationError> {
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {

Expand All @@ -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()
Expand All @@ -44,9 +44,11 @@ class StackExtTest {
frames = List(Stack.MAX_DEPTH) { frame },
)

val actual = stack.pushFrame(frame)
val actual = assertFailsWith<InvocationException> {
stack.pushFrame(frame)
}

assertEquals(Err(InvocationError.CallStackExhausted), actual)
assertEquals(InvocationError.CallStackExhausted, actual.error)
assertEquals(Stack.MAX_DEPTH, stack.size())
}

Expand Down

0 comments on commit cf666f8

Please sign in to comment.