-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c52b1fe
commit 833542d
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
.../io/github/charlietap/chasm/executor/invoker/dispatch/referencefused/RefTestDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.github.charlietap.chasm.executor.invoker.dispatch.referencefused | ||
|
||
import io.github.charlietap.chasm.executor.invoker.instruction.referencefused.RefTestExecutor | ||
import io.github.charlietap.chasm.executor.runtime.dispatch.DispatchableInstruction | ||
import io.github.charlietap.chasm.executor.runtime.execution.Executor | ||
import io.github.charlietap.chasm.executor.runtime.instruction.FusedReferenceInstruction | ||
|
||
fun RefTestDispatcher( | ||
instruction: FusedReferenceInstruction.RefTest, | ||
) = RefTestDispatcher( | ||
instruction = instruction, | ||
executor = ::RefTestExecutor, | ||
) | ||
|
||
internal inline fun RefTestDispatcher( | ||
instruction: FusedReferenceInstruction.RefTest, | ||
crossinline executor: Executor<FusedReferenceInstruction.RefTest>, | ||
): DispatchableInstruction = { context -> | ||
executor(context, instruction) | ||
} |
38 changes: 38 additions & 0 deletions
38
...io/github/charlietap/chasm/executor/invoker/instruction/referencefused/RefTestExecutor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.charlietap.chasm.executor.invoker.instruction.referencefused | ||
|
||
import io.github.charlietap.chasm.executor.invoker.type.TypeOf | ||
import io.github.charlietap.chasm.executor.invoker.type.TypeOfReferenceValue | ||
import io.github.charlietap.chasm.executor.runtime.execution.ExecutionContext | ||
import io.github.charlietap.chasm.executor.runtime.instruction.FusedReferenceInstruction | ||
import io.github.charlietap.chasm.type.ReferenceType | ||
import io.github.charlietap.chasm.type.matching.ReferenceTypeMatcher | ||
import io.github.charlietap.chasm.type.matching.TypeMatcher | ||
|
||
internal fun RefTestExecutor( | ||
context: ExecutionContext, | ||
instruction: FusedReferenceInstruction.RefTest, | ||
) = RefTestExecutor( | ||
context = context, | ||
instruction = instruction, | ||
referenceTypeMatcher = ::ReferenceTypeMatcher, | ||
typeOfReferenceValue = ::TypeOfReferenceValue, | ||
) | ||
|
||
internal inline fun RefTestExecutor( | ||
context: ExecutionContext, | ||
instruction: FusedReferenceInstruction.RefTest, | ||
crossinline referenceTypeMatcher: TypeMatcher<ReferenceType>, | ||
crossinline typeOfReferenceValue: TypeOf<Long, ReferenceType>, | ||
) { | ||
val stack = context.vstack | ||
val store = context.store | ||
val frame = context.cstack.peekFrame() | ||
val moduleInstance = frame.instance | ||
|
||
val referenceType = typeOfReferenceValue(instruction.reference(stack), store, moduleInstance) | ||
if (referenceTypeMatcher(referenceType, instruction.referenceType, context)) { | ||
instruction.destination(1L, stack) | ||
} else { | ||
instruction.destination(0L, stack) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters