Skip to content

Commit 533370f

Browse files
authored
Merge pull request #107 from onion-lang/codex/bcel依存を完全に取り除く
Remove BCEL and migrate to ASM backend
2 parents 23689b1 + 4c0b0d4 commit 533370f

File tree

14 files changed

+117
-2149
lines changed

14 files changed

+117
-2149
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using JavaCC.
1010
The compiler parses source code into an untyped AST and then performs type
1111
checking to produce a **typed AST**. The old intermediate representation (IRT)
1212
has been folded into this typed tree. Code generation now runs on the typed
13-
AST via a thin compatibility layer that still reuses the existing BCEL backend.
13+
AST using a new ASM-based backend.
1414

1515
## Tools
1616

bin/onion

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ then
1818
exit
1919
fi
2020

21-
$JAVA_HOME/bin/java -classpath $CLASSPATH:$ONION_HOME/onion.jar:$ONION_HOME/onion-library.jar:$ONION_HOME/lib/bcel.jar onion.tools.ScriptRunner $@
21+
$JAVA_HOME/bin/java -classpath $CLASSPATH:$ONION_HOME/onion.jar:$ONION_HOME/onion-library.jar onion.tools.ScriptRunner "$@"
22+

bin/onion.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ echo Please set the environment variable ONION_HOME
2121
goto END
2222

2323
:START
24-
%JAVA_HOME%\bin\java -classpath %CLASSPATH%;%ONION_HOME%\onion.jar;%ONION_HOME%\lib\bcel.jar;%ONION_HOME%\onion-library.jar onion.tools.ScriptRunner %*
24+
%JAVA_HOME%\bin\java -classpath %CLASSPATH%;%ONION_HOME%\onion.jar;%ONION_HOME%\onion-library.jar onion.tools.ScriptRunner %*
2525

26-
:END
26+
:END

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ lazy val onionSettings = Seq(
8080
scalacOptions ++= Seq("-encoding", "utf8", "-unchecked", "-deprecation", "-feature", "-language:implicitConversions", "-language:existentials"),
8181
javacOptions ++= Seq("-sourcepath", "src.lib", "-Xlint:unchecked", "-source", "21"),
8282
libraryDependencies ++= Seq(
83-
"org.apache.bcel" % "bcel" % "6.0",
8483
"org.ow2.asm" % "asm" % "9.8",
8584
"org.ow2.asm" % "asm-tree" % "9.8",
8685
"org.ow2.asm" % "asm-commons" % "9.8",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Main-Class: onion.tools.CompilerFrontend
2-
Class-Path: lib/bcel.jar lib/scala-compiler.jar lib/scala-library.jar lib/onion-library.jar
2+
Class-Path: lib/scala-compiler.jar lib/scala-library.jar lib/onion-library.jar
Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,43 @@
1-
/* ************************************************************** *
2-
* *
3-
* Copyright (c) 2016-, Kota Mizushima, All rights reserved. *
4-
* *
5-
* *
6-
* This software is distributed under the modified BSD License. *
7-
* ************************************************************** */
81
package onion.compiler
92

103
import java.util.{HashMap => JHashMap}
11-
import onion.compiler.environment.BcelRefs.BcelClassType
124
import onion.compiler.environment.AsmRefs.AsmClassType
135
import onion.compiler.environment.ClassFileTable
146
import onion.compiler.environment.ReflectionRefs.ReflectClassType
157

16-
/**
17-
* @author Kota Mizushima
18-
*
19-
*/
20-
class ClassTable(classPath: String) {
8+
class ClassTable(classPath: String):
219
val classes = new OrderedTable[IRT.ClassDefinition]
2210
private val classFiles = new JHashMap[String, IRT.ClassType]
2311
private val arrayClasses = new JHashMap[String, IRT.ArrayType]
2412
private val table = new ClassFileTable(classPath)
2513

26-
def loadArray(component: IRT.Type, dimension: Int): IRT.ArrayType = {
14+
def loadArray(component: IRT.Type, dimension: Int): IRT.ArrayType =
2715
val arrayName = "[" * dimension + component.name
28-
var array: IRT.ArrayType = arrayClasses.get(arrayName)
29-
if (array != null) return array
30-
array = new IRT.ArrayType(component, dimension, this)
16+
var array = arrayClasses.get(arrayName)
17+
if array != null then return array
18+
array = IRT.ArrayType(component, dimension, this)
3119
arrayClasses.put(arrayName, array)
3220
array
33-
}
3421

35-
def load(className: String): IRT.ClassType = {
36-
var clazz: IRT.ClassType = lookup(className)
37-
if (clazz == null) {
38-
val javaClass = table.load(className)
39-
if (javaClass != null) {
40-
clazz = new BcelClassType(javaClass, this)
22+
def load(className: String): IRT.ClassType =
23+
var clazz = lookup(className)
24+
if clazz == null then
25+
val bytes = table.loadBytes(className)
26+
if bytes != null then
27+
clazz = new AsmClassType(bytes, this)
4128
classFiles.put(clazz.name, clazz)
42-
} else {
43-
val bytes = table.loadBytes(className)
44-
if (bytes != null) {
45-
clazz = new AsmClassType(bytes, this)
29+
else
30+
try
31+
clazz = new ReflectClassType(Class.forName(className, true, Thread.currentThread.getContextClassLoader), this)
4632
classFiles.put(clazz.name, clazz)
47-
} else {
48-
try {
49-
clazz = new ReflectClassType(Class.forName(className, true, Thread.currentThread.getContextClassLoader), this)
50-
classFiles.put(clazz.name, clazz)
51-
}
52-
catch {
53-
case e: ClassNotFoundException => {}
54-
}
55-
}
56-
}
57-
}
33+
catch
34+
case _: ClassNotFoundException => ()
5835
clazz
59-
}
6036

6137
def rootClass: IRT.ClassType = load("java.lang.Object")
6238

63-
def lookup(className: String): IRT.ClassType = {
64-
classes.get(className) match {
39+
def lookup(className: String): IRT.ClassType =
40+
classes.get(className) match
6541
case Some(ref) => ref
6642
case None => classFiles.get(className)
67-
}
68-
}
6943

70-
}

0 commit comments

Comments
 (0)