From 3678d6b20f79042d622477fcf33d3f56d992f657 Mon Sep 17 00:00:00 2001 From: Pradeep Krishnan Date: Wed, 4 Apr 2012 15:23:49 -0700 Subject: [PATCH] Implement InvokeInterface Conflicts: src/main/scala/cafebabe/AbstractByteCode.scala --- src/main/scala/cafebabe/AbstractByteCode.scala | 14 ++++++-------- src/main/scala/cafebabe/package.scala | 5 +++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/scala/cafebabe/AbstractByteCode.scala b/src/main/scala/cafebabe/AbstractByteCode.scala index 1d46c57..49b0c0c 100644 --- a/src/main/scala/cafebabe/AbstractByteCode.scala +++ b/src/main/scala/cafebabe/AbstractByteCode.scala @@ -213,15 +213,13 @@ object AbstractByteCodes { ch.constantPool.addString(fieldName), ch.constantPool.addString(fieldType)))) } - - // Method invocations - - // Not implemented yet. We should generate the two extra bytes properly ("count" and 0). - /* object InvokeInterface { + + object InvokeInterface { def apply(className: String, methodName: String, methodSig: String): AbstractByteCodeGenerator = - invokeMethod(INVOKEINTERFACE, className, methodName, methodSig) - } */ - + _ << invokeMethod(INVOKEINTERFACE, className, methodName, methodSig) << + RawByte(methodSignatureArgStackEffect(methodSig) + 1) << RawByte(0) + } + object InvokeSpecial { def apply(className: String, methodName: String, methodSig: String): AbstractByteCodeGenerator = invokeMethod(INVOKESPECIAL, className, methodName, methodSig) diff --git a/src/main/scala/cafebabe/package.scala b/src/main/scala/cafebabe/package.scala index f421350..ec9878a 100644 --- a/src/main/scala/cafebabe/package.scala +++ b/src/main/scala/cafebabe/package.scala @@ -41,6 +41,11 @@ package object cafebabe { case MethSigRE(args,ret) => typeToByteCount(ret) - typesToByteCount(args) case _ => sys.error("Malformed method signature: " + sig) } + private[cafebabe] def methodSignatureArgStackEffect(sig: String) : Int = sig match { + case MethSigRE(args,ret) => + typesToByteCount(args) // does not account for 'this' since we don't know if this is static + case _ => sys.error("Malformed method signature: " + sig) + } // the meat of the parser private def parseRec(s : String) : (Int,String,String) = if(s.isEmpty) (0,s,s) else {