Skip to content

Commit

Permalink
FunctionSignature: Add abstract field
Browse files Browse the repository at this point in the history
  • Loading branch information
ChAoSUnItY committed May 14, 2022
1 parent 0bbdc30 commit 42ae195
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/org/casc/lang/asm/CommonClassWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ class CommonClassWriter(flags: Int, private val classLoader: ClassLoader) : Clas
override fun getClassLoader(): ClassLoader {
return classLoader
}

override fun getCommonSuperClass(type1: String?, type2: String?): String {
// search common type from Table

return super.getCommonSuperClass(type1, type2)
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/org/casc/lang/ast/Constructor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data class Constructor(
ownerType,
companion = true,
mutable = false,
abstract = false,
accessor,
"<init>",
parameterTypes.mapNotNull { it },
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/casc/lang/ast/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data class Function(
ownerType,
selfKeyword == null,
mutKeyword != null,
abstrKeyword != null,
accessor,
name?.literal ?: "",
parameterTypes!!.mapNotNull { it },
Expand Down
19 changes: 18 additions & 1 deletion src/main/kotlin/org/casc/lang/checker/Checker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class Checker(private val preference: AbstractPreference) {
}
}

if (clazz.traitImpls != null) {
clazz.traitImpls!!.forEach {
it.functions.forEach {

}
}
}

return classScope
}

Expand Down Expand Up @@ -133,6 +141,14 @@ class Checker(private val preference: AbstractPreference) {
}
}

if (trait.traitImpls != null) {
trait.traitImpls!!.forEach {
it.functions.forEach {

}
}
}

return traitScope
}

Expand Down Expand Up @@ -378,7 +394,7 @@ class Checker(private val preference: AbstractPreference) {
return constructor
}

private fun checkFunction(function: Function, scope: Scope): Function {
private fun checkFunction(function: Function, scope: Scope, searchTraitFunction: Boolean = false): Function {
val localScope = Scope(scope)
checkIdentifierIsKeyword(function.name?.literal, function.name?.pos)

Expand Down Expand Up @@ -527,6 +543,7 @@ class Checker(private val preference: AbstractPreference) {
ClassType.OBJECT_TYPE,
companion = true,
mutable = false,
abstract = false,
Accessor.Pub,
"<init>",
listOf(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/casc/lang/emitter/Emitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ class Emitter(private val preference: AbstractPreference, private val declaratio
// Use INVOKEVIRTUAL instead
methodVisitor.visitMethodInsn(
when {
expression.superCall -> Opcodes.INVOKESPECIAL
functionSignature.ownerType?.isTrait == true -> Opcodes.INVOKEINTERFACE
expression.superCall -> Opcodes.INVOKESPECIAL
else -> Opcodes.INVOKEVIRTUAL
},
functionSignature.ownerReference.internalName(),
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/casc/lang/table/FunctionSignature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class FunctionSignature(
val ownerType: ClassType?,
val companion: Boolean,
val mutable: Boolean,
val abstract: Boolean,
override val accessor: Accessor,
val name: String,
val parameters: List<Type>,
Expand All @@ -21,7 +22,8 @@ data class FunctionSignature(
Reference(ownerClass),
TypeUtil.asType(ownerClass, preference) as ClassType,
Modifier.isStatic(function.modifiers),
Modifier.isFinal(function.modifiers),
!Modifier.isFinal(function.modifiers),
Modifier.isAbstract(function.modifiers),
Accessor.fromModifier(function.modifiers),
function.name,
function.parameterTypes.map { TypeUtil.asType(it, preference)!! },
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/casc/lang/table/Scope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ data class Scope(
TypeUtil.asType(ownerClazz, preference) as ClassType,
companion = true,
mutable = false,
abstract = false,
Accessor.fromModifier(constructor.modifiers),
functionName,
constructor.parameterTypes.map { TypeUtil.asType(it, preference)!! },
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/validate/project/Animal.casc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ trait Animal {
}

impl Animal {
fn roar(self)
}
4 changes: 3 additions & 1 deletion src/test/resources/validate/project/Atom.casc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ impl Atom {
}
}

impl Atom for Animal
impl Atom for Animal {
ovrd fn roar(self) {}
}
2 changes: 1 addition & 1 deletion src/test/resources/validate/project/Rock.casc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Rock: Atom {
} else {
new Rock("")
}
a.hello()
a.roar()
}

mut fn lol(self): i32 {
Expand Down

0 comments on commit 42ae195

Please sign in to comment.