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,7 +1268,8 @@ 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 (target != null) {
if (!allowLocalSlots) return null if (!allowLocalSlots) return null
if (!target.isMutable || target.isDelegated) return null if (!target.isMutable || target.isDelegated) return null
val slot = resolveSlot(target) ?: return null val slot = resolveSlot(target) ?: return null
@ -1413,6 +1414,30 @@ class BytecodeCompiler(
} }
} }
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? {
val condition = compileRefWithFallback(ref.condition, SlotType.BOOL, Pos.builtIn) ?: return null val condition = compileRefWithFallback(ref.condition, SlotType.BOOL, Pos.builtIn) ?: return null
if (condition.type != SlotType.BOOL) return null if (condition.type != SlotType.BOOL) return null

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(