1
1
package io.github.charlietap.chasm.executor.invoker.instruction.control
2
2
3
- import com.github.michaelbull.result.Err
4
3
import com.github.michaelbull.result.Result
5
4
import com.github.michaelbull.result.binding
6
5
import io.github.charlietap.chasm.ast.instruction.ControlInstruction
@@ -30,10 +29,13 @@ internal fun ControlInstructionExecutor(
30
29
brOnNullExecutor = ::BrOnNullExecutor ,
31
30
brOnNonNullExecutor = ::BrOnNonNullExecutor ,
32
31
brOnCastExecutor = ::BrOnCastExecutor ,
32
+ brOnCastFailExecutor = ::BrOnCastFailExecutor ,
33
+ nopExecutor = ::NopExecutor ,
33
34
returnExecutor = ::ReturnExecutor ,
34
35
throwExecutor = ::ThrowExecutor ,
35
36
throwRefExecutor = ::ThrowRefExecutor ,
36
37
tryTableExecutor = ::TryTableExecutor ,
38
+ unreachableExecutor = ::UnreachableExecutor ,
37
39
)
38
40
39
41
internal inline fun ControlInstructionExecutor (
@@ -45,28 +47,30 @@ internal inline fun ControlInstructionExecutor(
45
47
crossinline returnCallIndirectExecutor : Executor <ControlInstruction .ReturnCallIndirect >,
46
48
crossinline callRefExecutor : Executor <ControlInstruction .CallRef >,
47
49
crossinline returnCallRefExecutor : Executor <ControlInstruction .ReturnCallRef >,
48
- crossinline blockExecutor : BlockExecutor ,
50
+ crossinline blockExecutor : Executor < ControlInstruction . Block > ,
49
51
crossinline loopExecutor : Executor <ControlInstruction .Loop >,
50
52
crossinline ifExecutor : Executor <ControlInstruction .If >,
51
- crossinline breakExecutor : BreakExecutor ,
53
+ crossinline breakExecutor : Executor < ControlInstruction . Br > ,
52
54
crossinline brIfExecutor : Executor <ControlInstruction .BrIf >,
53
55
crossinline brTableExecutor : Executor <ControlInstruction .BrTable >,
54
56
crossinline brOnNullExecutor : Executor <ControlInstruction .BrOnNull >,
55
57
crossinline brOnNonNullExecutor : Executor <ControlInstruction .BrOnNonNull >,
56
- crossinline brOnCastExecutor : BrOnCastExecutor ,
58
+ crossinline brOnCastExecutor : Executor <ControlInstruction .BrOnCast >,
59
+ crossinline brOnCastFailExecutor : Executor <ControlInstruction .BrOnCastFail >,
60
+ crossinline nopExecutor : Executor <ControlInstruction .Nop >,
57
61
crossinline returnExecutor : Executor <ControlInstruction .Return >,
58
62
crossinline throwExecutor : Executor <ControlInstruction .Throw >,
59
63
crossinline throwRefExecutor : Executor <ControlInstruction .ThrowRef >,
60
64
crossinline tryTableExecutor : Executor <ControlInstruction .TryTable >,
65
+ crossinline unreachableExecutor : Executor <ControlInstruction .Unreachable >,
61
66
): Result <Unit , InvocationError > = binding {
62
- val (stack, store) = context
63
67
when (instruction) {
64
- is ControlInstruction .Nop -> Unit
65
- is ControlInstruction .Unreachable -> Err ( InvocationError . Trap . TrapEncountered ).bind< Unit > ()
66
- is ControlInstruction .Block -> blockExecutor(store, stack, instruction.blockType, instruction.instructions ).bind()
68
+ is ControlInstruction .Nop -> nopExecutor(context, instruction).bind()
69
+ is ControlInstruction .Unreachable -> unreachableExecutor(context, instruction ).bind()
70
+ is ControlInstruction .Block -> blockExecutor(context, instruction).bind()
67
71
is ControlInstruction .Loop -> loopExecutor(context, instruction).bind()
68
72
is ControlInstruction .If -> ifExecutor(context, instruction).bind()
69
- is ControlInstruction .Br -> breakExecutor(stack , instruction.labelIndex ).bind()
73
+ is ControlInstruction .Br -> breakExecutor(context , instruction).bind()
70
74
is ControlInstruction .BrIf -> brIfExecutor(context, instruction).bind()
71
75
is ControlInstruction .BrTable -> brTableExecutor(context, instruction).bind()
72
76
is ControlInstruction .BrOnNull -> brOnNullExecutor(context, instruction).bind()
@@ -78,10 +82,8 @@ internal inline fun ControlInstructionExecutor(
78
82
is ControlInstruction .ReturnCallIndirect -> returnCallIndirectExecutor(context, instruction).bind()
79
83
is ControlInstruction .CallRef -> callRefExecutor(context, instruction).bind()
80
84
is ControlInstruction .ReturnCallRef -> returnCallRefExecutor(context, instruction).bind()
81
- is ControlInstruction .BrOnCast ->
82
- brOnCastExecutor(context, instruction.labelIndex, instruction.srcReferenceType, instruction.dstReferenceType, true ).bind()
83
- is ControlInstruction .BrOnCastFail ->
84
- brOnCastExecutor(context, instruction.labelIndex, instruction.srcReferenceType, instruction.dstReferenceType, false ).bind()
85
+ is ControlInstruction .BrOnCast -> brOnCastExecutor(context, instruction).bind()
86
+ is ControlInstruction .BrOnCastFail -> brOnCastFailExecutor(context, instruction).bind()
85
87
is ControlInstruction .Throw -> throwExecutor(context, instruction).bind()
86
88
is ControlInstruction .ThrowRef -> throwRefExecutor(context, instruction).bind()
87
89
is ControlInstruction .TryTable -> tryTableExecutor(context, instruction).bind()
0 commit comments