Bytecode index inc/dec for ScriptTest cases

This commit is contained in:
Sergey Chernov 2026-01-29 03:33:31 +03:00
parent 8407dbe880
commit eaee738dee
2 changed files with 39 additions and 18 deletions

View File

@ -1268,16 +1268,17 @@ class BytecodeCompiler(
} }
private fun compileIncDec(ref: IncDecRef, wantResult: Boolean): CompiledValue? { private fun compileIncDec(ref: IncDecRef, wantResult: Boolean): CompiledValue? {
val target = ref.target as? LocalSlotRef ?: return null val target = ref.target as? LocalSlotRef
if (!allowLocalSlots) return null if (target != null) {
if (!target.isMutable || target.isDelegated) return null if (!allowLocalSlots) return null
val slot = resolveSlot(target) ?: return null if (!target.isMutable || target.isDelegated) return null
val slotType = slotTypes[slot] ?: SlotType.UNKNOWN val slot = resolveSlot(target) ?: return null
if (slot < scopeSlotCount && slotType != SlotType.UNKNOWN) { val slotType = slotTypes[slot] ?: SlotType.UNKNOWN
val addrSlot = ensureScopeAddr(slot) if (slot < scopeSlotCount && slotType != SlotType.UNKNOWN) {
val current = allocSlot() val addrSlot = ensureScopeAddr(slot)
emitLoadFromAddr(addrSlot, current, slotType) val current = allocSlot()
val result = when (slotType) { emitLoadFromAddr(addrSlot, current, slotType)
val result = when (slotType) {
SlotType.INT -> { SlotType.INT -> {
if (wantResult && ref.isPost) { if (wantResult && ref.isPost) {
val old = allocSlot() val old = allocSlot()
@ -1335,9 +1336,9 @@ class BytecodeCompiler(
} }
else -> null else -> null
} }
if (result != null) return result if (result != null) return result
} }
return when (slotType) { return when (slotType) {
SlotType.INT -> { SlotType.INT -> {
if (wantResult && ref.isPost) { if (wantResult && ref.isPost) {
val old = allocSlot() val old = allocSlot()
@ -1409,8 +1410,32 @@ class BytecodeCompiler(
CompiledValue(result, SlotType.OBJ) CompiledValue(result, SlotType.OBJ)
} }
} }
else -> null else -> null
}
} }
val indexTarget = ref.target as? IndexRef ?: return null
if (indexTarget.optionalRef) return null
val receiver = compileRefWithFallback(indexTarget.targetRef, null, Pos.builtIn) ?: return null
val index = compileRefWithFallback(indexTarget.indexRef, null, Pos.builtIn) ?: return null
val current = allocSlot()
builder.emit(Opcode.GET_INDEX, receiver.slot, index.slot, current)
updateSlotType(current, SlotType.OBJ)
val oneSlot = allocSlot()
val oneId = builder.addConst(BytecodeConst.ObjRef(ObjInt.One))
builder.emit(Opcode.CONST_OBJ, oneId, oneSlot)
val result = allocSlot()
val op = if (ref.isIncrement) Opcode.ADD_OBJ else Opcode.SUB_OBJ
if (wantResult && ref.isPost) {
val old = allocSlot()
builder.emit(Opcode.MOVE_OBJ, current, old)
builder.emit(op, current, oneSlot, result)
builder.emit(Opcode.SET_INDEX, receiver.slot, index.slot, result)
return CompiledValue(old, SlotType.OBJ)
}
builder.emit(op, current, oneSlot, result)
builder.emit(Opcode.SET_INDEX, receiver.slot, index.slot, result)
return CompiledValue(result, SlotType.OBJ)
} }
private fun compileConditional(ref: ConditionalRef): CompiledValue? { private fun compileConditional(ref: ConditionalRef): CompiledValue? {

View File

@ -1015,7 +1015,6 @@ class ScriptTest {
.toInt()) .toInt())
} }
@Ignore("Bytecode: unsupported or incorrect behavior")
@Test @Test
fun testDecrIncr3() = runTest { fun testDecrIncr3() = runTest {
val c = Scope() val c = Scope()
@ -3444,7 +3443,6 @@ class ScriptTest {
} }
@Ignore("Bytecode: unsupported or incorrect behavior")
@Test @Test
fun testIndexIntIncrements() = runTest { fun testIndexIntIncrements() = runTest {
eval( eval(
@ -3465,7 +3463,6 @@ class ScriptTest {
) )
} }
@Ignore("Bytecode: unsupported or incorrect behavior")
@Test @Test
fun testIndexIntDecrements() = runTest { fun testIndexIntDecrements() = runTest {
eval( eval(
@ -4127,7 +4124,6 @@ class ScriptTest {
) )
} }
@Ignore("Bytecode: unsupported or incorrect behavior")
@Test @Test
fun testInlineMapLiteral() = runTest { fun testInlineMapLiteral() = runTest {
eval( eval(