Skip to content

Commit

Permalink
Merge pull request #52 from CASC-Lang/trait-impl
Browse files Browse the repository at this point in the history
Trait impl implementation phase III: Trait Impl
  • Loading branch information
ChAoSUnItY authored May 16, 2022
2 parents a30f18b + da2036b commit bc71993
Show file tree
Hide file tree
Showing 65 changed files with 877 additions and 453 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: test -DrunExecutionTest=false # ignore execution test due to local file accessing might causing unexpected issues
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: always() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Upload test report
uses: codecov/codecov-action@v2
with:
files: "build/coverage/coverage.xml"
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: test -DrunExecutionTest=false # ignore execution test due to local file accessing might causing unexpected issues
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: always() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Upload test report
uses: codecov/codecov-action@v2
with:
files: "build/coverage/coverage.xml"
88 changes: 44 additions & 44 deletions .github/workflows/weekly_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: CASC Weekly Release
name: CASC Weekly Release

on:
schedule:
- cron: "0 0 * * 1"
- cron: "0 0 * * 1"
workflow_dispatch:

jobs:
Expand All @@ -18,45 +18,45 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Jar built files with Gradle
run: ./gradlew jar
- name: Create release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: false
release_name: ${{ steps.version.outputs.version }}
tag_name: ${{ steps.date.outputs.date }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Upload Jar file to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/libs/CASC-0.0.1.jar
asset_name: CASC-Weekly-${{ steps.date.outputs.date }}.jar
asset_content_type: application/zip
- name: Publish Jar file
uses: actions/[email protected]
with:
# Artifact name
name: CASC-Weekly-${{ steps.date.outputs.date }}.jar
# A file, directory or wildcard pattern that describes what to upload
path: ./build/libs/CASC-0.0.1.jar
# The desired behavior if no files are found using the provided path.
- uses: actions/checkout@v2
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Jar built files with Gradle
run: ./gradlew jar
- name: Create release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: false
release_name: ${{ steps.version.outputs.version }}
tag_name: ${{ steps.date.outputs.date }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Upload Jar file to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/libs/CASC-0.0.1.jar
asset_name: CASC-Weekly-${{ steps.date.outputs.date }}.jar
asset_content_type: application/zip
- name: Publish Jar file
uses: actions/[email protected]
with:
# Artifact name
name: CASC-Weekly-${{ steps.date.outputs.date }}.jar
# A file, directory or wildcard pattern that describes what to upload
path: ./build/libs/CASC-0.0.1.jar
# The desired behavior if no files are found using the provided path.
28 changes: 20 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## TODO List

``There is no precedence for this list, all tasks are currently invloving.``

To see release-based TODOs, checkout GitHub repository's project

### Category

#### Language Spec

##### TO BE INCLUDED IN UNIT TEST
Expand Down Expand Up @@ -30,24 +33,33 @@ To see release-based TODOs, checkout GitHub repository's project
##### IMPLEMENTATION IN PROGRESS

- [ ] loops
- - [x] for loop (Java loop)<sup id="a1">[1](#f1)</sup>
- - [ ] range for loop<sup id="a2">[2](#f2)</sup>
- - [ ] while loop
- - [ ] do-while loop
-
- [x] for loop (Java loop)<sup id="a1">[1](#f1)</sup>
-
- [ ] range for loop<sup id="a2">[2](#f2)</sup>
-
- [ ] while loop
-
- [ ] do-while loop
- [ ] label
- [ ] generic
- [ ] <type>.class
- [ ] inheritance
- - [x] class
- - [ ] abstract class
- - [ ] interface
- - [x] `super` call
-
- [x] class
-
- [ ] abstract class
-
- [ ] interface
-
- [x] `super` call

### Compiler Unit

- [x] multiple file compilation
- [ ] more customizable compilation arguments(?)

#### FOOTNOTES

<b id="f1">1</b>. Most likely will remove after range for loop is done. Due to syntax parsing collision. [](#a1)
<b id="f2">2</b>. Requires inheritance fully supported. [](#a2)
3 changes: 1 addition & 2 deletions src/main/kotlin/org/casc/lang/asm/BytecodeClassLoader.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.casc.lang.asm

import java.net.URLClassLoader
import java.lang.ClassNotFoundException
import java.net.URL
import java.net.URLClassLoader

class BytecodeClassLoader(urls: Array<URL?>?, parent: ClassLoader?) : URLClassLoader(urls, parent) {
fun defineClass(className: String?, bytecode: ByteArray): Class<*> {
Expand Down
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)
}
}
14 changes: 4 additions & 10 deletions src/main/kotlin/org/casc/lang/ast/ClassInstance.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package org.casc.lang.ast

import org.casc.lang.table.HasFlag
import org.casc.lang.table.Reference
import org.casc.lang.utils.getOrElse
import org.objectweb.asm.Opcodes

data class ClassInstance(
override val packageReference: Reference?,
val accessorToken: Token?,
val abstrToken: Token?, // Unused
val abstrToken: Token?,
val mutKeyword: Token?,
val classKeyword: Token?,
val classKeyword: Token,
override val typeReference: Reference,
override val fields: List<Field>,
override val accessor: Accessor = Accessor.fromString(accessorToken?.literal)
) : TypeInstance(), HasFlag {
) : TypeInstance() {
override val flag: Int by lazy {
var flag = Opcodes.ACC_SUPER
flag += accessor.access
flag += abstrToken.getOrElse(Opcodes.ACC_ABSTRACT)
flag += mutKeyword.getOrElse(0, Opcodes.ACC_FINAL)
flag += abstrToken.getOrElse(Opcodes.ACC_ABSTRACT, mutKeyword.getOrElse(0, Opcodes.ACC_FINAL))
flag
}

val parentClassReference: Reference by lazy {
impl?.parentClassReference ?: Reference.OBJECT_TYPE_REFERENCE
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/org/casc/lang/ast/CompanionBlock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.casc.lang.ast

data class CompanionBlock(val compKeyword: Token, val statements: List<Statement>)
3 changes: 2 additions & 1 deletion src/main/kotlin/org/casc/lang/ast/Constructor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class Constructor(
val ownerReference: Reference?,
var parentReference: Reference?,
val accessorToken: Token?,
val newKeyword: Token?,
val newKeyword: Token,
val parameters: List<Parameter>,
val statements: List<Statement>,
val superKeyword: Token?,
Expand Down 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: 0 additions & 1 deletion src/main/kotlin/org/casc/lang/ast/Expression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.casc.lang.table.PrimitiveType
import org.casc.lang.table.Reference
import org.casc.lang.table.Type
import org.objectweb.asm.Opcodes
import org.objectweb.asm.TypeReference

sealed class Expression {
companion object {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/org/casc/lang/ast/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package org.casc.lang.ast

import org.casc.lang.table.Reference

data class File(val path: String, val relativeFilePath: String, val usages: List<Reference>, var typeInstance: TypeInstance) {
data class File(
val path: String,
val relativeFilePath: String,
val usages: List<Reference>,
var typeInstance: TypeInstance
) {
val fileName: String by lazy {
relativeFilePath.split('\\', '/').last()
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/casc/lang/ast/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package org.casc.lang.ast
import org.casc.lang.table.*
import org.casc.lang.utils.getOrElse
import org.objectweb.asm.Opcodes
import java.lang.reflect.Modifier

data class Function(
val ownerReference: Reference?,
val accessorToken: Token?,
val ovrdKeyword: Token?,
val abstrKeyword: Token?,
val mutKeyword: Token?,
val fnKeyword: Token,
val selfKeyword: Token?, // determine whether function is companion
val name: Token?,
val parameters: List<Parameter>,
Expand All @@ -26,7 +26,7 @@ data class Function(
parameterTypes?.fold("") { s, type ->
s + type?.descriptor
}
})${returnType?.descriptor}"
})${returnType?.descriptor ?: "V"}"
override val flag: Int by lazy {
var flag = accessor.access
flag += selfKeyword.getOrElse(0, Opcodes.ACC_STATIC)
Expand All @@ -35,13 +35,15 @@ data class Function(
flag += mutKeyword.getOrElse(0, Opcodes.ACC_FINAL)
flag
}
var abstract: Boolean = abstrKeyword != null

override fun asSignature() =
FunctionSignature(
ownerReference!!,
ownerType,
selfKeyword == null,
mutKeyword != null,
abstrKeyword != null,
accessor,
name?.literal ?: "",
parameterTypes!!.mapNotNull { it },
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/casc/lang/ast/Impl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.casc.lang.table.Reference
data class Impl(
val implKeyword: Token,
val parentClassReference: Reference?,
var companionBlock: List<Statement>,
var companionBlock: CompanionBlock?,
var constructors: List<Constructor>,
var functions: List<Function>
)
3 changes: 2 additions & 1 deletion src/main/kotlin/org/casc/lang/ast/Statement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ sealed class Statement {
val expressions: List<Expression?>,
var indexes: MutableList<Int> = mutableListOf(),
override val pos: Position? = Position.fromMultipleAndExtend(
*variables.firstOrNull()?.toList()?.map { it?.pos }?.toTypedArray() ?: arrayOf())
*variables.firstOrNull()?.toList()?.map { it?.pos }?.toTypedArray() ?: arrayOf()
)
?.extend(expressions.lastOrNull()?.pos)
) : Statement()

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/casc/lang/ast/TraitImpl.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.casc.lang.ast

data class TraitImpl(val implKeyword: Token, val functions: List<Function>)
import org.casc.lang.table.Reference

data class TraitImpl(val implKeyword: Token, val implementedTraitReference: Reference, val functions: List<Function>)
3 changes: 1 addition & 2 deletions src/main/kotlin/org/casc/lang/ast/TraitInstance.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.casc.lang.ast

import org.casc.lang.table.HasFlag
import org.casc.lang.table.Reference
import org.objectweb.asm.Opcodes

Expand All @@ -11,7 +10,7 @@ data class TraitInstance(
override val typeReference: Reference,
override val fields: List<Field>,
override val accessor: Accessor = Accessor.fromString(accessorToken?.literal)
) : TypeInstance(), HasFlag {
) : TypeInstance() {
override val flag: Int by lazy {
accessor.access + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE
}
Expand Down
Loading

0 comments on commit bc71993

Please sign in to comment.