Created
August 23, 2010 12:58
-
-
Save papamitra/545417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -deprecation "$0" | |
!# | |
// ScalaのfjbgでHello,World | |
import ch.epfl.lamp.fjbg._ | |
val context = new FJBGContext() | |
import JAccessFlags._ | |
val jclass = context.JClass(ACC_PUBLIC, | |
"Hello", | |
"java/lang/Object", | |
JClass.NO_INTERFACES, | |
"") | |
// コンストラクタ生成 | |
val initMethod = jclass.addNewMethod(ACC_PUBLIC, | |
"<init>", | |
JType.VOID, | |
JType.EMPTY_ARRAY, | |
new Array[String](0)) | |
val init = initMethod.getCode().asInstanceOf[JExtendedCode] | |
init.emitALOAD_0 | |
init.emitINVOKESPECIAL("java/lang/Object", | |
"<init>", | |
JMethodType.ARGLESS_VOID_FUNCTION) | |
init.emitRETURN() | |
// main生成 | |
val mainMethod = | |
jclass.addNewMethod(ACC_PUBLIC | ACC_STATIC, | |
"main", | |
JType.VOID, | |
Array(new JArrayType(new JObjectType("java.lang.String"))), | |
Array("args")) | |
val maincode = mainMethod.getCode().asInstanceOf[JExtendedCode] | |
maincode.emitGETSTATIC("java.lang.System", "out", new | |
JObjectType("java.io.PrintStream")) | |
maincode.emitLDC("Hello,World") | |
maincode.emitINVOKEVIRTUAL("java.io.PrintStream", | |
"println", | |
new JMethodType(JType.VOID, Array(new JObjectType("java.lang.String")))) | |
maincode.emitRETURN() | |
jclass.writeTo("Hello.class") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment