summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-28 14:35:50 +0000
committerPaul Phillips <paulp@improving.org>2010-02-28 14:35:50 +0000
commitba5dbbd44db2c23c7532cde13453c6a031afb6e5 (patch)
tree00fbae4846f215cf90efda508f924cb790537e31 /src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
parent432e16ce906cb1f03aabe26c0e51674780f44625 (diff)
downloadscala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.tar.gz
scala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.tar.bz2
scala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.zip
Added ## method to Any as our scala hashCode me...
Added ## method to Any as our scala hashCode method which provides consistent answers for primitive types. And I'm sure we're all tired of new starrs, but it's hard to add a method to Any without one. This patch only brings ## into existence, but nothing calls it yet. // some true assertions scala> assert(5.5f.## == 5.5f.hashCode) scala> assert(5.0f.## != 5.0f.hashCode && 5.0f.## == 5L.##) No review. (Already reviewed by odersky.)
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/icode/GenICode.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 048d0b7bec..35a5f80d1f 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -423,6 +423,8 @@ abstract class GenICode extends SubComponent {
genArithmeticOp(tree, ctx, code)
else if (code == scalaPrimitives.CONCAT)
(genStringConcat(tree, ctx), STRING)
+ else if (code == scalaPrimitives.HASH)
+ (genScalaHash(receiver, ctx), INT)
else if (isArrayOp(code))
genArrayOp(tree, ctx, code, expectedType)
else if (isLogicalOp(code) || isComparisonOp(code)) {
@@ -1167,6 +1169,19 @@ abstract class GenICode extends SubComponent {
ctx1
}
+ /** Generate the scala ## method.
+ */
+ def genScalaHash(tree: Tree, ctx: Context): Context = {
+ val hashMethod = {
+ ctx.bb.emit(LOAD_MODULE(definitions.ScalaRunTimeModule))
+ definitions.getMember(definitions.ScalaRunTimeModule, "hash")
+ }
+
+ val ctx1 = genLoad(tree, ctx, ANY_REF_CLASS)
+ ctx1.bb.emit(CALL_METHOD(hashMethod, Static(false)))
+ ctx1
+ }
+
/**
* Returns a list of trees that each should be concatenated, from
* left to right. It turns a chained call like "a".+("b").+("c") into