Skip to content

Commit

Permalink
Merge pull request #103 from xuwei-k/scala-3
Browse files Browse the repository at this point in the history
Scala 3
  • Loading branch information
kmizu authored Jan 11, 2025
2 parents 220a775 + 04c6bae commit 8141f7a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
6 changes: 1 addition & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,14 @@ def javacc(classpath: Classpath, output: File, log: Logger): Seq[File] = {

lazy val onionSettings = Seq(
version := "0.2.0-SNAPSHOT",
scalaVersion := "2.13.15",
scalaVersion := "3.6.2",
name := "onion",
organization := "org.onion_lang",
Compile / unmanagedSourceDirectories := {
(Seq((Compile / javaSource).value) ++ Seq((Compile / scalaSource).value) ++ Seq((Compile / sourceManaged).value))
},
scalacOptions ++= Seq("-encoding", "utf8", "-unchecked", "-deprecation", "-feature", "-language:implicitConversions", "-language:existentials"),
javacOptions ++= Seq("-sourcepath", "src.lib", "-Xlint:unchecked", "-source", "21"),
libraryDependencies += {
val version = scalaVersion.value
"org.scala-lang" % "scala-compiler" % version
},
libraryDependencies ++= Seq(
"org.apache.bcel" % "bcel" % "6.0",
"org.ow2.asm" % "asm" % "5.0.2",
Expand Down
18 changes: 9 additions & 9 deletions src/main/scala/onion/compiler/CodeGeneration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ object CodeGeneration {

private def toJavaModifier(src: Int): Int = {
var modifier: Int = 0
modifier |= (if (Modifier.isPrivate(src)) Constants.ACC_PRIVATE else modifier)
modifier |= (if (Modifier.isProtected(src)) Constants.ACC_PROTECTED else modifier)
modifier |= (if (Modifier.isPublic(src)) Constants.ACC_PUBLIC else modifier)
modifier |= (if (Modifier.isStatic(src)) Constants.ACC_STATIC else modifier)
modifier |= (if (Modifier.isSynchronized(src)) Constants.ACC_SYNCHRONIZED else modifier)
modifier |= (if (Modifier.isAbstract(src)) Constants.ACC_ABSTRACT else modifier)
modifier |= (if (Modifier.isFinal(src)) Constants.ACC_FINAL else modifier)
modifier |= (if (Modifier.isPrivate(src)) (Constants.ACC_PRIVATE: Int) else modifier)
modifier |= (if (Modifier.isProtected(src)) (Constants.ACC_PROTECTED: Int) else modifier)
modifier |= (if (Modifier.isPublic(src)) (Constants.ACC_PUBLIC: Int) else modifier)
modifier |= (if (Modifier.isStatic(src)) (Constants.ACC_STATIC: Int) else modifier)
modifier |= (if (Modifier.isSynchronized(src)) (Constants.ACC_SYNCHRONIZED: Int) else modifier)
modifier |= (if (Modifier.isAbstract(src)) (Constants.ACC_ABSTRACT: Int) else modifier)
modifier |= (if (Modifier.isFinal(src)) (Constants.ACC_FINAL: Int) else modifier)
modifier
}

Expand Down Expand Up @@ -335,8 +335,8 @@ class CodeGeneration(config: CompilerConfig) {

private def classModifier(node: IRT.ClassDefinition): Int = {
var modifier: Int = toJavaModifier(node.modifier)
modifier |= (if (node.isInterface) Constants.ACC_INTERFACE else modifier)
modifier |= (if ((!Modifier.isInternal(modifier))) Constants.ACC_PUBLIC else modifier)
modifier |= (if (node.isInterface) (Constants.ACC_INTERFACE: Int) else modifier)
modifier |= (if ((!Modifier.isInternal(modifier))) (Constants.ACC_PUBLIC: Int) else modifier)
modifier
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/onion/compiler/OnionTypeConversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ class OnionTypeConversion(table: ClassTable) {
if (klass.isArray) {
var dimension: Int = 0
var component: Class[_] = null
do {
while({
dimension += 1
component = component.getComponentType
} while (component.getComponentType != null)
(component.getComponentType != null)
})()
val componentType: IRT.Type = toOnionType(component)
return table.loadArray(componentType, dimension)
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/scala/onion/compiler/toolbox/Boxing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ import onion.compiler.ClassTable
*
*/
object Boxing {
private final val TABLE: Array[Array[AnyRef]] = Array(Array(IRT.BasicType.BOOLEAN, "java.lang.Boolean"), Array(IRT.BasicType.BYTE, "java.lang.Byte"), Array(IRT.BasicType.SHORT, "java.lang.Short"), Array(IRT.BasicType.CHAR, "java.lang.Character"), Array(IRT.BasicType.INT, "java.lang.Integer"), Array(IRT.BasicType.LONG, "java.lang.Long"), Array(IRT.BasicType.FLOAT, "java.lang.Float"), Array(IRT.BasicType.DOUBLE, "java.lang.Double"))
private final val TABLE: Array[Array[AnyRef]] = Array(
Array[AnyRef](IRT.BasicType.BOOLEAN, "java.lang.Boolean"),
Array[AnyRef](IRT.BasicType.BYTE, "java.lang.Byte"),
Array[AnyRef](IRT.BasicType.SHORT, "java.lang.Short"),
Array[AnyRef](IRT.BasicType.CHAR, "java.lang.Character"),
Array[AnyRef](IRT.BasicType.INT, "java.lang.Integer"),
Array[AnyRef](IRT.BasicType.LONG, "java.lang.Long"),
Array[AnyRef](IRT.BasicType.FLOAT, "java.lang.Float"),
Array[AnyRef](IRT.BasicType.DOUBLE, "java.lang.Double")
)

private def boxedType(table: ClassTable, `type`: IRT.BasicType): IRT.ClassType = {
for (row <- TABLE) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/onion/tools/Shell.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Shell (val classLoader: ClassLoader, val classpath: Seq[String]) {

private def findFirstMainMethod(loader: OnionClassLoader, classes: Seq[CompiledClass]): Option[Method] = {
for (i <- 0 until classes.length) {
val className = classes(i).getClassName()
val className = classes(i).className
val clazz = Class.forName(className, true, loader)
try {
val main = clazz.getMethod("main", classOf[Array[String]])
Expand Down

0 comments on commit 8141f7a

Please sign in to comment.