Skip to content

Commit

Permalink
✨ Add arry type
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed May 15, 2024
1 parent 49ba31f commit 502c6ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/kotlin/vm/classloader/ArrayType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yhs0602.vm.classloader

import com.yhs0602.vm.MethodWrapper

class ArrayType(
val elementType: Type,
clonableType: Type,
serializableType: Type
) : Type() {
override val directSuperClass: Type = ObjectType // 모든 배열 타입의 슈퍼 클래스는 Object
override val interfaces: List<Type> = listOf(clonableType, serializableType) // 배열이 구현하는 인터페이스
override val interfaceTable: Map<MethodTableEntry, MethodTableEntry> = emptyMap()
override val virtualTable: Map<MethodTableEntry, MethodTableEntry> = emptyMap()
override val descriptor: String = "[" + elementType.descriptor
override val methods: Map<MethodTableEntry, MethodWrapper> = emptyMap()
override val staticMethods: Map<MethodTableEntry, MethodWrapper> = emptyMap()
override val constructors: Map<MethodTableEntry, MethodWrapper> = emptyMap()
override val clazz: Class<*> = java.lang.reflect.Array.newInstance(elementType.clazz, 0).javaClass
override fun callClInit() {} // 배열 타입은 clinit이 없음
}
3 changes: 3 additions & 0 deletions src/main/kotlin/vm/classloader/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ sealed class Type {
open fun isAssignableTo(other: Type): Boolean {
if (this == other)
return true
if (this is ArrayType && other is ArrayType) {
return elementType.isAssignableTo(other.elementType)
}
// Check if 'other' is a superclass of this class
var currentClass: Type? = this
while (currentClass != null) {
Expand Down

0 comments on commit 502c6ea

Please sign in to comment.