Created
March 17, 2016 13:51
-
-
Save masayuki038/758b5fbbef9c6a499a8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package net.wrap_trap.goju_to.macros | |
import scala.language.experimental.macros | |
import scala.reflect.macros.blackbox | |
/** | |
* goju-to: HanoiDB(LSM-trees (Log-Structured Merge Trees) Indexed Storage) clone | |
* Copyright (c) 2016 Masayuki Takahashi | |
* This software is released under the MIT License. | |
* http://opensource.org/licenses/mit-license.php | |
*/ | |
object PlainRpcProtocol { | |
final val call = 'CALL | |
final val reply = 'REPLY | |
final val cast = 'CAST | |
def CALL(from: Any, msg: Any): Tuple3[Symbol, Any, Any] = macro callImpl | |
def REPLY(ref: Any, msg: Any): Tuple3[Symbol, Any, Any] = macro replyImpl | |
def CAST(from: Any, msg: Any): Tuple3[Symbol, Any, Any] = macro castImpl | |
def callImpl(c: blackbox.Context)(from: c.Expr[Any], msg: c.Expr[Any]) = { | |
import c.universe._ | |
q"($call, $from, $msg)" | |
} | |
def replyImpl(c: blackbox.Context)(ref: c.Expr[Any], msg: c.Expr[Any]) = { | |
import c.universe._ | |
q"($reply, $ref, $msg)" | |
} | |
def castImpl(c: blackbox.Context)(from: c.Expr[Any], msg: c.Expr[Any]) = { | |
import c.universe._ | |
q"($cast, $from, $msg)" | |
} | |
} |
This file contains hidden or 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
package net.wrap_trap.goju_to.macros | |
import org.scalatest._ | |
/** | |
* goju-to: HanoiDB(LSM-trees (Log-Structured Merge Trees) Indexed Storage) clone | |
* Copyright (c) 2016 Masayuki Takahashi | |
* This software is released under the MIT License. | |
* http://opensource.org/licenses/mit-license.php | |
*/ | |
class PlainRpcProtocolSpec extends FlatSpec with Matchers { | |
"PlainRpcProtocol.CALL" should "replace to ('CALL, from, msg)" in { | |
PlainRpcProtocol.CALL('A, 'B) should equal ('CALL, 'A, 'B) | |
} | |
"PlainRpcProtocol.REPLY" should "replace to ('REPLY, ref, msg)" in { | |
PlainRpcProtocol.REPLY('A, 'B) should equal ('REPLY, 'A, 'B) | |
} | |
"PlainRpcProtocol.CAST" should "replace to ('CAST, from, msg)" in { | |
PlainRpcProtocol.CAST('A, 'B) should equal ('CAST, 'A, 'B) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment