forked from lihaoyi/Metascala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Method.scala
40 lines (34 loc) · 1.08 KB
/
Method.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package metascala
package rt
import metascala.opcodes.{Code, Conversion}
import org.objectweb.asm.tree.MethodNode
/**
* A reference to a method with a specific signature
*/
trait Method{
def sig: imm.Sig
lazy val argSize = sig.desc.args.foldLeft(0)(_ + _.size)
}
object Method{
case class Native(clsName: String,
sig: imm.Sig,
func: (rt.Thread, () => Int, Int => Unit) => Unit)
extends Method{
override def toString = s"Method.Native(${clsName}, ${sig.unparse}})"
}
/**
* A reference to a method belonging to a class
*/
case class Cls(clsIndex: Int,
methodIndex: Int,
sig: imm.Sig,
accessFlags: Int,
codeThunk: () => Code)
(implicit vm: VM) extends Method{
lazy val cls = vm.ClsTable.clsIndex(clsIndex)
lazy val code = codeThunk()
def static = (accessFlags & imm.Access.Static) != 0
def native = (accessFlags & imm.Access.Native) != 0
override def toString = s"Method.Cls(${cls.name}, ${sig.unparse}})"
}
}