Skip to content

Commit 1d26c33

Browse files
committed
add jump admin instructions
1 parent be45c9e commit 1d26c33

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
11
package io.github.charlietap.chasm.ir.instruction
22

3+
import io.github.charlietap.chasm.type.ReferenceType
4+
35
sealed interface AdminInstruction : Instruction {
46

57
data object EndBlock : AdminInstruction
68

79
data object EndFunction : AdminInstruction
10+
11+
data class Jump(
12+
val offset: Int,
13+
val adjustment: StackAdjustment,
14+
) : AdminInstruction
15+
16+
data class JumpIf(
17+
val offset: Int,
18+
val adjustment: StackAdjustment,
19+
) : AdminInstruction
20+
21+
data class JumpTable(
22+
val offsets: List<Int>,
23+
val defaultOffset: Int,
24+
val adjustments: List<StackAdjustment>,
25+
) : AdminInstruction
26+
27+
data class JumpOnNull(
28+
val offset: Int,
29+
val adjustment: StackAdjustment,
30+
) : AdminInstruction
31+
32+
data class JumpOnNonNull(
33+
val offset: Int,
34+
val adjustment: StackAdjustment,
35+
) : AdminInstruction
36+
37+
data class JumpOnCast(
38+
val offset: Int,
39+
val srcReferenceType: ReferenceType,
40+
val dstReferenceType: ReferenceType,
41+
val adjustment: StackAdjustment,
42+
) : AdminInstruction
43+
44+
data class JumpOnCastFail(
45+
val offset: Int,
46+
val srcReferenceType: ReferenceType,
47+
val dstReferenceType: ReferenceType,
48+
val adjustment: StackAdjustment,
49+
) : AdminInstruction
850
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.charlietap.chasm.ir.instruction
2+
3+
import kotlin.jvm.JvmInline
4+
5+
fun StackAdjustment(
6+
depth: Int,
7+
keep: Int,
8+
): StackAdjustment {
9+
val encoded = (depth.toLong() shl 32) or (keep.toLong() and 0xFFFFFFFFL)
10+
return StackAdjustment(encoded)
11+
}
12+
13+
@JvmInline
14+
value class StackAdjustment(
15+
@PublishedApi internal val encoded: Long,
16+
) {
17+
inline val depth: Int
18+
get() = (encoded ushr 32).toInt()
19+
20+
inline val keep: Int
21+
get() = (encoded and 0xFFFFFFFF).toInt()
22+
23+
override fun toString(): String = "StackAdjustment(depth=$depth, keep=$keep)"
24+
}

predecoder/src/commonMain/kotlin/io/github/charlietap/chasm/predecoder/instruction/admin/AdminInstructionPredecoder.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ internal inline fun AdminInstructionPredecoder(
3232
when (instruction) {
3333
is AdminInstruction.EndBlock -> endBlockDispatcher(EndBlock)
3434
is AdminInstruction.EndFunction -> endFunctionDispatcher(EndFunction)
35+
is AdminInstruction.Jump -> TODO()
36+
is AdminInstruction.JumpIf -> TODO()
37+
is AdminInstruction.JumpOnCast -> TODO()
38+
is AdminInstruction.JumpOnCastFail -> TODO()
39+
is AdminInstruction.JumpOnNonNull -> TODO()
40+
is AdminInstruction.JumpOnNull -> TODO()
41+
is AdminInstruction.JumpTable -> TODO()
3542
}
3643
}

predecoder/src/commonMain/kotlin/io/github/charlietap/chasm/predecoder/instruction/control/ControlInstructionPredecoder.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@ import io.github.charlietap.chasm.predecoder.Predecoder
77
import io.github.charlietap.chasm.predecoder.PredecodingContext
88
import io.github.charlietap.chasm.runtime.dispatch.DispatchableInstruction
99
import io.github.charlietap.chasm.runtime.error.ModuleTrapError
10-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.Br
11-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrIf
12-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrOnCast
13-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrOnCastFail
14-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrOnNonNull
15-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrOnNull
16-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.BrTable
17-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.CallIndirect
18-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.CallRef
19-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.Nop
20-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.Return
21-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.ReturnCallIndirect
22-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.ReturnCallRef
23-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.Throw
24-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.ThrowRef
25-
import io.github.charlietap.chasm.runtime.instruction.ControlInstruction.Unreachable
2610

2711
internal fun ControlInstructionPredecoder(
2812
context: PredecodingContext,

0 commit comments

Comments
 (0)