Clean up compiler warnings

This commit is contained in:
Sergey Chernov 2026-02-18 18:16:33 +03:00
parent 64debf78bd
commit 79a541b148
14 changed files with 61 additions and 90 deletions

View File

@ -1014,7 +1014,7 @@ class Compiler(
declareSlotNameAt( declareSlotNameAt(
modulePlan, modulePlan,
name, name,
seedSlotIndex!!, seedSlotIndex,
sourceRecord.isMutable, sourceRecord.isMutable,
sourceRecord.type == ObjRecord.Type.Delegated sourceRecord.type == ObjRecord.Type.Delegated
) )
@ -1490,9 +1490,10 @@ class Compiler(
private suspend fun parseScript(): Script { private suspend fun parseScript(): Script {
val statements = mutableListOf<Statement>() val statements = mutableListOf<Statement>()
val start = cc.currentPos() val start = cc.currentPos()
val atTopLevel = resolutionSink != null && resolutionScriptDepth == 0 val topLevelSink = if (resolutionScriptDepth == 0) resolutionSink else null
val atTopLevel = topLevelSink != null
if (atTopLevel) { if (atTopLevel) {
resolutionSink?.enterScope(ScopeKind.MODULE, start, null) topLevelSink.enterScope(ScopeKind.MODULE, start, null)
seedScope?.let { seedResolutionFromScope(it, start) } seedScope?.let { seedResolutionFromScope(it, start) }
seedResolutionFromScope(importManager.rootScope, start) seedResolutionFromScope(importManager.rootScope, start)
} }
@ -1537,7 +1538,6 @@ class Compiler(
// A standalone newline not immediately following a comment resets doc buffer // A standalone newline not immediately following a comment resets doc buffer
if (!prevWasComment) clearPendingDoc() else prevWasComment = false if (!prevWasComment) clearPendingDoc() else prevWasComment = false
} }
else -> {}
} }
cc.next() cc.next()
continue continue
@ -1672,7 +1672,7 @@ class Compiler(
} finally { } finally {
resolutionScriptDepth-- resolutionScriptDepth--
if (atTopLevel) { if (atTopLevel) {
resolutionSink?.exitScope(cc.currentPos()) topLevelSink.exitScope(cc.currentPos())
} }
if (needsSlotPlan) { if (needsSlotPlan) {
slotPlanStack.removeLast() slotPlanStack.removeLast()
@ -1843,9 +1843,7 @@ class Compiler(
private fun captureLocalRef(name: String, slotLoc: SlotLocation, pos: Pos): LocalSlotRef? { private fun captureLocalRef(name: String, slotLoc: SlotLocation, pos: Pos): LocalSlotRef? {
if (capturePlanStack.isEmpty() || slotLoc.depth == 0) return null if (capturePlanStack.isEmpty() || slotLoc.depth == 0) return null
val functionPlan = capturePlanStack.asReversed().firstOrNull { it.isFunction } ?: return null val functionPlan = capturePlanStack.asReversed().firstOrNull { it.isFunction } ?: return null
val functionIndex = functionPlan?.let { plan -> val functionIndex = slotPlanStack.indexOfLast { it.id == functionPlan.slotPlan.id }
slotPlanStack.indexOfLast { it.id == plan.slotPlan.id }
} ?: -1
val scopeIndex = slotPlanStack.indexOfLast { it.id == slotLoc.scopeId } val scopeIndex = slotPlanStack.indexOfLast { it.id == slotLoc.scopeId }
if (functionIndex >= 0 && scopeIndex >= functionIndex) return null if (functionIndex >= 0 && scopeIndex >= functionIndex) return null
val modulePlan = moduleSlotPlan() val modulePlan = moduleSlotPlan()
@ -2127,7 +2125,6 @@ class Compiler(
is WhenEqualsCondition -> containsDelegatedRefs(cond.expr) is WhenEqualsCondition -> containsDelegatedRefs(cond.expr)
is WhenInCondition -> containsDelegatedRefs(cond.expr) is WhenInCondition -> containsDelegatedRefs(cond.expr)
is WhenIsCondition -> false is WhenIsCondition -> false
else -> true
} }
} || containsDelegatedRefs(case.block) } || containsDelegatedRefs(case.block)
} || } ||
@ -2161,21 +2158,16 @@ class Compiler(
is IndexRef -> containsDelegatedRefs(ref.targetRef) || containsDelegatedRefs(ref.indexRef) is IndexRef -> containsDelegatedRefs(ref.targetRef) || containsDelegatedRefs(ref.indexRef)
is ListLiteralRef -> ref.entries().any { is ListLiteralRef -> ref.entries().any {
when (it) { when (it) {
is ListEntry.Element -> containsDelegatedRefs(it.ref as net.sergeych.lyng.obj.ObjRef) is ListEntry.Element -> containsDelegatedRefs(it.ref)
is ListEntry.Spread -> containsDelegatedRefs(it.ref as net.sergeych.lyng.obj.ObjRef) is ListEntry.Spread -> containsDelegatedRefs(it.ref)
} }
} }
is MapLiteralRef -> ref.entries().any { is MapLiteralRef -> ref.entries().any {
when (it) { when (it) {
is net.sergeych.lyng.obj.MapLiteralEntry.Named -> { is net.sergeych.lyng.obj.MapLiteralEntry.Named -> {
val v = it.value containsDelegatedRefs(it.value)
when (v) {
is Statement -> containsDelegatedRefs(stmt = v)
is net.sergeych.lyng.obj.ObjRef -> containsDelegatedRefs(ref = v)
else -> false
}
} }
is net.sergeych.lyng.obj.MapLiteralEntry.Spread -> containsDelegatedRefs(it.ref as net.sergeych.lyng.obj.ObjRef) is net.sergeych.lyng.obj.MapLiteralEntry.Spread -> containsDelegatedRefs(it.ref)
} }
} }
is CallRef -> containsDelegatedRefs(ref.target) || ref.args.any { is CallRef -> containsDelegatedRefs(ref.target) || ref.args.any {
@ -3037,8 +3029,7 @@ class Compiler(
} }
if (captureSlots.isNotEmpty()) { if (captureSlots.isNotEmpty()) {
if (captureRecords != null) { if (captureRecords != null) {
val records = captureRecords as List<ObjRecord> context.captureRecords = captureRecords
context.captureRecords = records
context.captureNames = captureSlots.map { it.name } context.captureNames = captureSlots.map { it.name }
} else { } else {
val resolvedRecords = ArrayList<ObjRecord>(captureSlots.size) val resolvedRecords = ArrayList<ObjRecord>(captureSlots.size)
@ -3725,8 +3716,8 @@ class Compiler(
var first = true var first = true
val typeStart = cc.currentPos() val typeStart = cc.currentPos()
var lastEnd = typeStart var lastEnd = typeStart
var lastName: String? = null var lastName = ""
var lastPos: Pos? = null var lastPos = typeStart
while (true) { while (true) {
val idTok = val idTok =
if (first) cc.requireToken(Token.Type.ID, "type name or type expression required") else cc.requireToken( if (first) cc.requireToken(Token.Type.ID, "type name or type expression required") else cc.requireToken(
@ -3767,11 +3758,9 @@ class Compiler(
return TypeDecl.TypeVar(qualified, isNullable) to miniRef return TypeDecl.TypeVar(qualified, isNullable) to miniRef
} }
if (segments.size > 1) { if (segments.size > 1) {
lastPos?.let { pos -> resolutionSink?.reference(qualified, pos) } resolutionSink?.reference(qualified, lastPos)
} else { } else {
lastName?.let { name -> resolutionSink?.reference(lastName, lastPos)
lastPos?.let { pos -> resolutionSink?.reference(name, pos) }
}
} }
// Helper to build MiniTypeRef (base or generic) // Helper to build MiniTypeRef (base or generic)
fun buildBaseRef(rangeEnd: Pos, args: List<MiniTypeRef>?, nullable: Boolean): MiniTypeRef { fun buildBaseRef(rangeEnd: Pos, args: List<MiniTypeRef>?, nullable: Boolean): MiniTypeRef {
@ -3833,8 +3822,8 @@ class Compiler(
var first = true var first = true
val typeStart = cc.currentPos() val typeStart = cc.currentPos()
var lastEnd = typeStart var lastEnd = typeStart
var lastName: String? = null var lastName = ""
var lastPos: Pos? = null var lastPos = typeStart
while (true) { while (true) {
val idTok = val idTok =
if (first) cc.requireToken(Token.Type.ID, "type name or type expression required") else cc.requireToken( if (first) cc.requireToken(Token.Type.ID, "type name or type expression required") else cc.requireToken(
@ -3889,11 +3878,9 @@ class Compiler(
return TypeDecl.TypeVar(qualified, isNullable) to miniRef return TypeDecl.TypeVar(qualified, isNullable) to miniRef
} }
if (segments.size > 1) { if (segments.size > 1) {
lastPos?.let { pos -> resolutionSink?.reference(qualified, pos) } resolutionSink?.reference(qualified, lastPos)
} else { } else {
lastName?.let { name -> resolutionSink?.reference(lastName, lastPos)
lastPos?.let { pos -> resolutionSink?.reference(name, pos) }
}
} }
fun buildBaseRef(rangeEnd: Pos, args: List<MiniTypeRef>?, nullable: Boolean): MiniTypeRef { fun buildBaseRef(rangeEnd: Pos, args: List<MiniTypeRef>?, nullable: Boolean): MiniTypeRef {
val base = MiniTypeName(MiniRange(typeStart, rangeEnd), segments.toList(), nullable = false) val base = MiniTypeName(MiniRange(typeStart, rangeEnd), segments.toList(), nullable = false)
@ -4164,7 +4151,7 @@ class Compiler(
} }
private fun inferObjClassFromRef(ref: ObjRef): ObjClass? = when (ref) { private fun inferObjClassFromRef(ref: ObjRef): ObjClass? = when (ref) {
is ConstRef -> ref.constValue as? ObjClass ?: (ref.constValue as? Obj)?.objClass is ConstRef -> ref.constValue as? ObjClass ?: ref.constValue.objClass
is LocalVarRef -> nameObjClass[ref.name] ?: resolveClassByName(ref.name) is LocalVarRef -> nameObjClass[ref.name] ?: resolveClassByName(ref.name)
is FastLocalVarRef -> nameObjClass[ref.name] ?: resolveClassByName(ref.name) is FastLocalVarRef -> nameObjClass[ref.name] ?: resolveClassByName(ref.name)
is LocalSlotRef -> { is LocalSlotRef -> {
@ -4234,7 +4221,7 @@ class Compiler(
val targetClass = resolveClassByName(ref.receiverTypeName()) val targetClass = resolveClassByName(ref.receiverTypeName())
inferFieldReturnClass(targetClass, ref.name) inferFieldReturnClass(targetClass, ref.name)
} }
is ConstRef -> ref.constValue as? ObjClass ?: (ref.constValue as? Obj)?.objClass is ConstRef -> ref.constValue as? ObjClass ?: ref.constValue.objClass
is ListLiteralRef -> ObjList.type is ListLiteralRef -> ObjList.type
is MapLiteralRef -> ObjMap.type is MapLiteralRef -> ObjMap.type
is RangeRef -> ObjRange.type is RangeRef -> ObjRange.type
@ -4780,9 +4767,7 @@ class Compiler(
is RecordSlotRef -> direct.read() is RecordSlotRef -> direct.read()
else -> direct else -> direct
} }
if (value is Obj) { collectRuntimeTypeVarBindings(param.type, value, inferred)
collectRuntimeTypeVarBindings(param.type, value, inferred)
}
} }
val boundValues = LinkedHashMap<String, Obj>(typeParams.size) val boundValues = LinkedHashMap<String, Obj>(typeParams.size)
for (tp in typeParams) { for (tp in typeParams) {
@ -5987,7 +5972,8 @@ class Compiler(
val baseName = declaredName ?: generateAnonName(startPos) val baseName = declaredName ?: generateAnonName(startPos)
val className = if (declaredName != null && outerClassName != null) "$outerClassName.$declaredName" else baseName val className = if (declaredName != null && outerClassName != null) "$outerClassName.$declaredName" else baseName
if (declaredName != null) { if (declaredName != null) {
resolutionSink?.declareSymbol(declaredName, SymbolKind.CLASS, isMutable = false, pos = nameToken!!.pos) val namePos = nameToken.pos
resolutionSink?.declareSymbol(declaredName, SymbolKind.CLASS, isMutable = false, pos = namePos)
declareLocalName(declaredName, isMutable = false) declareLocalName(declaredName, isMutable = false)
if (codeContexts.lastOrNull() is CodeContext.Module) { if (codeContexts.lastOrNull() is CodeContext.Module) {
objectDeclNames.add(declaredName) objectDeclNames.add(declaredName)
@ -6207,13 +6193,14 @@ class Compiler(
} }
val ctorForcedLocalSlots = LinkedHashMap<String, Int>() val ctorForcedLocalSlots = LinkedHashMap<String, Int>()
if (constructorArgsDeclaration != null) { if (constructorArgsDeclaration != null) {
val ctorDecl = constructorArgsDeclaration
val snapshot = slotPlanIndices(classSlotPlan) val snapshot = slotPlanIndices(classSlotPlan)
for (param in constructorArgsDeclaration!!.params) { for (param in ctorDecl.params) {
val idx = snapshot[param.name] ?: continue val idx = snapshot[param.name] ?: continue
ctorForcedLocalSlots[param.name] = idx ctorForcedLocalSlots[param.name] = idx
} }
constructorArgsDeclaration = constructorArgsDeclaration =
wrapDefaultArgsBytecode(constructorArgsDeclaration!!, ctorForcedLocalSlots, classSlotPlan.id) wrapDefaultArgsBytecode(ctorDecl, ctorForcedLocalSlots, classSlotPlan.id)
} }
constructorArgsDeclaration?.params?.forEach { param -> constructorArgsDeclaration?.params?.forEach { param ->
if (param.accessType != null) { if (param.accessType != null) {
@ -7078,7 +7065,7 @@ class Compiler(
isDelegated = true isDelegated = true
delegateExpression = parseExpression() ?: throw ScriptError(cc.current().pos, "Expected delegate expression") delegateExpression = parseExpression() ?: throw ScriptError(cc.current().pos, "Expected delegate expression")
if (compileBytecode) { if (compileBytecode) {
delegateExpression = wrapFunctionBytecode(delegateExpression!!, "delegate@$name") delegateExpression = wrapFunctionBytecode(delegateExpression, "delegate@$name")
} }
} }
if (isDelegated && declKind != SymbolKind.MEMBER) { if (isDelegated && declKind != SymbolKind.MEMBER) {
@ -7259,17 +7246,17 @@ class Compiler(
val fnBody = object : Statement(), BytecodeBodyProvider { val fnBody = object : Statement(), BytecodeBodyProvider {
override val pos: Pos = start override val pos: Pos = start
override fun bytecodeBody(): BytecodeStatement? = fnStatements as? BytecodeStatement override fun bytecodeBody(): BytecodeStatement? = fnStatements as? BytecodeStatement
override suspend fun execute(callerContext: Scope): Obj { override suspend fun execute(scope: Scope): Obj {
callerContext.pos = start scope.pos = start
// restore closure where the function was defined, and making a copy of it // restore closure where the function was defined, and making a copy of it
// for local space. If there is no closure, we are in, say, class context where // for local space. If there is no closure, we are in, say, class context where
// the closure is in the class initialization and we needn't more: // the closure is in the class initialization and we needn't more:
val context = closureBox.closure?.let { closure -> val context = closureBox.closure?.let { closure ->
callerContext.applyClosureForBytecode(closure).also { scope.applyClosureForBytecode(closure).also {
it.args = callerContext.args it.args = scope.args
} }
} ?: callerContext } ?: scope
// Capacity hint: parameters + declared locals + small overhead // Capacity hint: parameters + declared locals + small overhead
val capacityHint = paramNames.size + fnLocalDecls + 4 val capacityHint = paramNames.size + fnLocalDecls + 4
@ -7325,11 +7312,11 @@ class Compiler(
} }
} }
if (extTypeName != null) { if (extTypeName != null) {
context.thisObj = callerContext.thisObj context.thisObj = scope.thisObj
} }
} }
return try { return try {
net.sergeych.lyng.bytecode.CmdVm().execute(bytecodeFn, context, callerContext.args, binder) net.sergeych.lyng.bytecode.CmdVm().execute(bytecodeFn, context, scope.args, binder)
} catch (e: ReturnException) { } catch (e: ReturnException) {
if (e.label == null || e.label == name || e.label == outerLabel) e.result if (e.label == null || e.label == name || e.label == outerLabel) e.result
else throw e else throw e
@ -7551,6 +7538,11 @@ class Compiler(
is ObjBool -> ObjBool.type is ObjBool -> ObjBool.type
is ObjString -> ObjString.type is ObjString -> ObjString.type
is ObjRange -> ObjRange.type is ObjRange -> ObjRange.type
is ObjList -> ObjList.type
is ObjMap -> ObjMap.type
is ObjChar -> ObjChar.type
is ObjNull -> Obj.rootObjectType
is ObjVoid -> ObjVoid.objClass
else -> null else -> null
} }
is ListLiteralRef -> ObjList.type is ListLiteralRef -> ObjList.type
@ -7625,19 +7617,6 @@ class Compiler(
else -> null else -> null
} }
} }
is ConstRef -> when (directRef.constValue) {
is ObjList -> ObjList.type
is ObjMap -> ObjMap.type
is ObjRange -> ObjRange.type
is ObjString -> ObjString.type
is ObjInt -> ObjInt.type
is ObjReal -> ObjReal.type
is ObjBool -> ObjBool.type
is ObjChar -> ObjChar.type
is ObjNull -> Obj.rootObjectType
is ObjVoid -> ObjVoid.objClass
else -> null
}
else -> null else -> null
} }
} }

View File

@ -31,7 +31,7 @@ class DelegatedVarDeclStatement(
) : Statement() { ) : Statement() {
override val pos: Pos = startPos override val pos: Pos = startPos
override suspend fun execute(context: Scope): Obj { override suspend fun execute(scope: Scope): Obj {
return bytecodeOnly(context, "delegated var declaration") return bytecodeOnly(scope, "delegated var declaration")
} }
} }

View File

@ -28,7 +28,7 @@ class DestructuringVarDeclStatement(
val isTransient: Boolean, val isTransient: Boolean,
override val pos: Pos, override val pos: Pos,
) : Statement() { ) : Statement() {
override suspend fun execute(context: Scope): Obj { override suspend fun execute(scope: Scope): Obj {
return bytecodeOnly(context, "destructuring declaration") return bytecodeOnly(scope, "destructuring declaration")
} }
} }

View File

@ -28,7 +28,7 @@ class ExtensionPropertyDeclStatement(
) : Statement() { ) : Statement() {
override val pos: Pos = startPos override val pos: Pos = startPos
override suspend fun execute(context: Scope): Obj { override suspend fun execute(scope: Scope): Obj {
return bytecodeOnly(context, "extension property declaration") return bytecodeOnly(scope, "extension property declaration")
} }
} }

View File

@ -864,7 +864,7 @@ open class Scope(
val receiver = rec.receiver ?: thisObj val receiver = rec.receiver ?: thisObj
val del = rec.delegate ?: run { val del = rec.delegate ?: run {
if (receiver is ObjInstance) { if (receiver is ObjInstance) {
(receiver as ObjInstance).writeField(this, name, newValue) receiver.writeField(this, name, newValue)
return return
} }
raiseError("Internal error: delegated property $name has no delegate") raiseError("Internal error: delegated property $name has no delegate")

View File

@ -323,7 +323,7 @@ class Script(
addVoidFn("assert") { addVoidFn("assert") {
val cond = requiredArg<ObjBool>(0) val cond = requiredArg<ObjBool>(0)
val message = if (args.size > 1) val message = if (args.size > 1)
": " + toStringOf(call(args[1] as Obj)).value ": " + toStringOf(call(args[1])).value
else "" else ""
if (!cond.value == true) if (!cond.value == true)
raiseError(ObjAssertionFailedException(requireScope(), "Assertion failed$message")) raiseError(ObjAssertionFailedException(requireScope(), "Assertion failed$message"))

View File

@ -32,7 +32,7 @@ class VarDeclStatement(
) : Statement() { ) : Statement() {
override val pos: Pos = startPos override val pos: Pos = startPos
override suspend fun execute(context: Scope): Obj { override suspend fun execute(scope: Scope): Obj {
return bytecodeOnly(context, "var declaration") return bytecodeOnly(scope, "var declaration")
} }
} }

View File

@ -5090,9 +5090,7 @@ class BytecodeCompiler(
lifted = stmt.lifted lifted = stmt.lifted
) )
) )
val dst = stmt.declaredName?.let { name -> val dst = resolveDirectNameSlot(stmt.declaredName)?.slot ?: allocSlot()
resolveDirectNameSlot(name)?.slot
} ?: allocSlot()
builder.emit(Opcode.DECL_ENUM, constId, dst) builder.emit(Opcode.DECL_ENUM, constId, dst)
updateSlotType(dst, SlotType.OBJ) updateSlotType(dst, SlotType.OBJ)
return CompiledValue(dst, SlotType.OBJ) return CompiledValue(dst, SlotType.OBJ)
@ -5357,7 +5355,6 @@ class BytecodeCompiler(
is net.sergeych.lyng.ContinueStatement -> compileContinue(target) is net.sergeych.lyng.ContinueStatement -> compileContinue(target)
is net.sergeych.lyng.ReturnStatement -> compileReturn(target) is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
is net.sergeych.lyng.ThrowStatement -> compileThrow(target) is net.sergeych.lyng.ThrowStatement -> compileThrow(target)
is net.sergeych.lyng.TryStatement -> emitTry(target, false)
is net.sergeych.lyng.NopStatement -> { is net.sergeych.lyng.NopStatement -> {
val slot = allocSlot() val slot = allocSlot()
val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid)) val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid))
@ -6947,7 +6944,6 @@ class BytecodeCompiler(
is LocalVarRef -> ref.name is LocalVarRef -> ref.name
is FastLocalVarRef -> ref.name is FastLocalVarRef -> ref.name
is LocalSlotRef -> ref.name is LocalSlotRef -> ref.name
else -> "unknown"
} }
val refKind = ref::class.simpleName ?: "LocalRef" val refKind = ref::class.simpleName ?: "LocalRef"
val loopKeys = loopSlotOverrides.keys.sorted().joinToString(prefix = "[", postfix = "]") val loopKeys = loopSlotOverrides.keys.sorted().joinToString(prefix = "[", postfix = "]")
@ -8445,9 +8441,6 @@ class BytecodeCompiler(
is StatementRef -> { is StatementRef -> {
collectScopeSlots(ref.statement) collectScopeSlots(ref.statement)
} }
is ImplicitThisMethodCallRef -> {
collectScopeSlotsArgs(ref.arguments())
}
is ThisMethodSlotCallRef -> { is ThisMethodSlotCallRef -> {
collectScopeSlotsArgs(ref.arguments()) collectScopeSlotsArgs(ref.arguments())
} }

View File

@ -502,7 +502,6 @@ object CmdDisassembler {
is CmdIterPush -> Opcode.ITER_PUSH to intArrayOf(cmd.iterSlot) is CmdIterPush -> Opcode.ITER_PUSH to intArrayOf(cmd.iterSlot)
is CmdIterPop -> Opcode.ITER_POP to intArrayOf() is CmdIterPop -> Opcode.ITER_POP to intArrayOf()
is CmdIterCancel -> Opcode.ITER_CANCEL to intArrayOf() is CmdIterCancel -> Opcode.ITER_CANCEL to intArrayOf()
else -> error("Unsupported cmd in disassembler: ${cmd::class.simpleName}")
} }
} }

View File

@ -880,7 +880,7 @@ open class Obj {
is Enum<*> -> ObjString(obj.name) is Enum<*> -> ObjString(obj.name)
Unit -> ObjVoid Unit -> ObjVoid
null -> ObjNull null -> ObjNull
is Iterator<*> -> ObjKotlinIterator(obj as Iterator<Any?>) is Iterator<*> -> ObjKotlinIterator(obj)
else -> throw IllegalArgumentException("cannot convert to Obj: $obj") else -> throw IllegalArgumentException("cannot convert to Obj: $obj")
} }
} }

View File

@ -166,7 +166,7 @@ class ObjInt(val value: Long, override val isConst: Boolean = false) : Obj(), Nu
internal const val CACHE_LOW: Long = -1024L internal const val CACHE_LOW: Long = -1024L
internal const val CACHE_HIGH: Long = 1023L internal const val CACHE_HIGH: Long = 1023L
private val cache = Array((CACHE_HIGH - CACHE_LOW + 1).toInt()) { private val cache = Array((CACHE_HIGH - CACHE_LOW + 1).toInt()) {
ObjInt((it + CACHE_LOW).toLong(), true) ObjInt(it + CACHE_LOW, true)
} }
fun of(value: Long): ObjInt { fun of(value: Long): ObjInt {

View File

@ -77,7 +77,7 @@ class NestedRangeBenchmarkTest {
} }
var depth = 1 var depth = 1
while (current is BytecodeStatement && current.original is ForInStatement) { while (current is BytecodeStatement && current.original is ForInStatement) {
val original = current.original as ForInStatement val original = current.original
println( println(
"[DEBUG_LOG] [BENCH] nested-happy loop depth=$depth " + "[DEBUG_LOG] [BENCH] nested-happy loop depth=$depth " +
"constRange=${original.constRange} canBreak=${original.canBreak} " + "constRange=${original.constRange} canBreak=${original.canBreak} " +

View File

@ -55,7 +55,7 @@ class WebsiteSamplesTest {
squares squares
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjList) assertTrue(result is ObjList)
val list = (result as ObjList).list.map { (it as ObjInt).value } val list = result.list.map { (it as ObjInt).value }
assertEquals(listOf(4L, 16L, 36L, 64L, 100L), list) assertEquals(listOf(4L, 16L, 36L, 64L, 100L), list)
} }
@ -75,7 +75,7 @@ class WebsiteSamplesTest {
[intBox.get(), realBox.get()] [intBox.get(), realBox.get()]
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjList) assertTrue(result is ObjList)
val l = (result as ObjList).list val l = result.list
assertEquals(42L, (l[0] as ObjInt).value) assertEquals(42L, (l[0] as ObjInt).value)
assertEquals(3.14, (l[1] as ObjReal).value) assertEquals(3.14, (l[1] as ObjReal).value)
} }
@ -108,7 +108,7 @@ class WebsiteSamplesTest {
full full
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjMap) assertTrue(result is ObjMap)
val m = (result as ObjMap).map val m = result.map
assertEquals(101L, (m[ObjString("id")] as ObjInt).value) assertEquals(101L, (m[ObjString("id")] as ObjInt).value)
assertEquals("Lyng", (m[ObjString("name")] as ObjString).value) assertEquals("Lyng", (m[ObjString("name")] as ObjString).value)
assertEquals("1.5.0-SNAPSHOT", (m[ObjString("version")] as ObjString).value) assertEquals("1.5.0-SNAPSHOT", (m[ObjString("version")] as ObjString).value)
@ -138,7 +138,7 @@ class WebsiteSamplesTest {
[first, middle, last] [first, middle, last]
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjList) assertTrue(result is ObjList)
val rl = (result as ObjList).list val rl = result.list
assertEquals(1L, (rl[0] as ObjInt).value) assertEquals(1L, (rl[0] as ObjInt).value)
val middle = rl[1] as ObjList val middle = rl[1] as ObjList
assertEquals(listOf(2L, 3L, 4L, 5L), middle.list.map { (it as ObjInt).value }) assertEquals(listOf(2L, 3L, 4L, 5L), middle.list.map { (it as ObjInt).value })
@ -178,7 +178,7 @@ class WebsiteSamplesTest {
["hello".shout(), [10, 20, 30].second] ["hello".shout(), [10, 20, 30].second]
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjList) assertTrue(result is ObjList)
val el = (result as ObjList).list val el = result.list
assertEquals("HELLO!!!", (el[0] as ObjString).value) assertEquals("HELLO!!!", (el[0] as ObjString).value)
assertEquals(20L, (el[1] as ObjInt).value) assertEquals(20L, (el[1] as ObjInt).value)
} }
@ -253,7 +253,7 @@ class WebsiteSamplesTest {
[d1.await(), d2.await()] [d1.await(), d2.await()]
""".trimIndent()) """.trimIndent())
assertTrue(result is ObjList) assertTrue(result is ObjList)
val dl = (result as ObjList).list val dl = result.list
assertEquals("Task A finished", (dl[0] as ObjString).value) assertEquals("Task A finished", (dl[0] as ObjString).value)
assertEquals("Task B finished", (dl[1] as ObjString).value) assertEquals("Task B finished", (dl[1] as ObjString).value)
} }

View File

@ -743,7 +743,7 @@ class Wallet( id, ownerKey, balance=0, createdAt=Instant.now().truncateToSecond(
""".trimIndent() """.trimIndent()
) )
suspend fun encBits(obj: Obj): Long = ObjLynonClass.encodeAny(scope, obj).bitArray.size.toLong() suspend fun encBits(obj: Obj): Long = ObjLynonClass.encodeAny(scope, obj).bitArray.size
suspend fun encBytes(obj: Obj): Long = ObjLynonClass.encodeAny(scope, obj).bitArray.asUByteArray().size.toLong() suspend fun encBytes(obj: Obj): Long = ObjLynonClass.encodeAny(scope, obj).bitArray.asUByteArray().size.toLong()
assertEquals(54L, encBits(ObjString("Point"))) assertEquals(54L, encBits(ObjString("Point")))