Skip to content

Commit

Permalink
arg descs, 2.11 comp fix, BOS tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 12, 2024
1 parent a2f3030 commit 297265f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
28 changes: 13 additions & 15 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,7 @@ object SNumericTypeMethods extends MethodsContainer {
case SBigIntMethods => BigIntIsExactIntegral.bitwiseInverse(obj.asInstanceOf[BigInt])
}
})
.withInfo(PropertyCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin)
.withInfo(PropertyCall, desc = "Returns bitwise inverse of this numeric. ")

val BitwiseOrMethod: SMethod = SMethod(
this, "bitwiseOr", SFunc(Array(tNum, tNum), tNum), 9, BitwiseInverse_CostKind)
Expand All @@ -307,9 +304,8 @@ object SNumericTypeMethods extends MethodsContainer {
}
})
.withInfo(MethodCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin)
""" Returns bitwise or of this numeric and provided one. """.stripMargin,
ArgInfo("that", "A numeric value to calculate or with."))

val BitwiseAndMethod: SMethod = SMethod(
this, "bitwiseAnd", SFunc(Array(tNum, tNum), tNum), 10, BitwiseInverse_CostKind)
Expand All @@ -324,9 +320,8 @@ object SNumericTypeMethods extends MethodsContainer {
}
})
.withInfo(MethodCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin)
""" Returns bitwise and of this numeric and provided one. """.stripMargin,
ArgInfo("that", "A numeric value to calculate and with."))

val BitwiseXorMethod: SMethod = SMethod(
this, "bitwiseXor", SFunc(Array(tNum, tNum), tNum), 11, BitwiseInverse_CostKind)
Expand All @@ -341,9 +336,8 @@ object SNumericTypeMethods extends MethodsContainer {
}
})
.withInfo(MethodCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin)
""" Returns bitwise xor of this numeric and provided one. """.stripMargin,
ArgInfo("that", "A numeric value to calculate xor with."))

val ShiftLeftMethod: SMethod = SMethod(
this, "shiftLeft", SFunc(Array(tNum, SInt), tNum), 12, BitwiseInverse_CostKind)
Expand All @@ -360,7 +354,9 @@ object SNumericTypeMethods extends MethodsContainer {
.withInfo(MethodCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin) // todo: describe shift arg and its limits
""".stripMargin,
ArgInfo("bits", "Number of bit to shift to the left. Note, that bits value must be non-negative and less than " +
"the size of the number in bits (e.g. 64 for Long, 256 for BigInt)"))

val ShiftRightMethod: SMethod = SMethod(
this, "shiftRight", SFunc(Array(tNum, SInt), tNum), 13, BitwiseInverse_CostKind)
Expand All @@ -377,7 +373,9 @@ object SNumericTypeMethods extends MethodsContainer {
.withInfo(MethodCall,
""" Returns a big-endian representation of this numeric in a collection of Booleans.
| Each boolean corresponds to one bit.
""".stripMargin) // todo: describe shift arg and its limits
""".stripMargin,
ArgInfo("bits", "Number of bit to shift to the right. Note, that bits value must be non-negative and less than " +
"the size of the number in bits (e.g. 64 for Long, 256 for BigInt)"))

lazy val v5Methods = Array(
ToByteMethod, // see Downcast
Expand Down
10 changes: 5 additions & 5 deletions sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
((byte >> bit) & 1) == 1

lazy val toBits = newFeature[Short, Coll[Boolean]](
{ x: Short => Colls.fromArray(Shorts.toByteArray(x).flatMap(b => byte2Bools(b).toArray)) },
{ x: Short => Colls.fromArray(Shorts.toByteArray(x)).flatMap(b => Colls.fromArray(byte2Bools(b).toArray)) },
"{ (x: Short) => x.toBits }",
FuncValue(
Array((1, SShort)),
Expand Down Expand Up @@ -393,7 +393,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
Seq(
(3.toShort, 3) -> new Expected(ExpectedResult(Success(24.toShort), None)),
(3.toShort, 8) -> new Expected(ExpectedResult(Success(768.toShort), None)),
((-2).toShort, 10) -> new Expected(ExpectedResult(Success((-2048).toShort), None)),
((-2).toShort, 10) -> new Expected(ExpectedResult(Success((-2048).toShort), None))
),
shiftLeft,
preGeneratedSamples = Some(Seq())
Expand Down Expand Up @@ -549,7 +549,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
((byte >> bit) & 1) == 1

lazy val toBits = newFeature[Int, Coll[Boolean]](
{ x: Int => Colls.fromArray(Ints.toByteArray(x).flatMap(b => byte2Bools(b).toArray)) },
{ x: Int => Colls.fromArray(Ints.toByteArray(x)).flatMap(b => Colls.fromArray(byte2Bools(b).toArray)) },
"{ (x: Int) => x.toBits }",
FuncValue(
Array((1, SInt)),
Expand Down Expand Up @@ -753,7 +753,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
((byte >> bit) & 1) == 1

lazy val toBits = newFeature[Long, Coll[Boolean]](
{ x: Long => Colls.fromArray(Longs.toByteArray(x).flatMap(b => byte2Bools(b).toArray)) },
{ x: Long => Colls.fromArray(Longs.toByteArray(x)).flatMap(b => Colls.fromArray(byte2Bools(b).toArray)) },
"{ (x: Long) => x.toBits }",
FuncValue(
Array((1, SLong)),
Expand Down Expand Up @@ -1018,7 +1018,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
((byte >> bit) & 1) == 1

lazy val toBits = newFeature[BigInt, Coll[Boolean]](
{ x: BigInt => Colls.fromArray(x.toBytes.toArray.flatMap(b => byte2Bools(b).toArray)) },
{ x: BigInt => x.toBytes.flatMap(b => Colls.fromArray(byte2Bools(b).toArray)) },
"{ (x: BigInt) => x.toBits }",
FuncValue(
Array((1, SBigInt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
)

if (VersionContext.current.isV6SoftForkActivated) {
shiftLeftTest()
an[IllegalArgumentException] shouldBe thrownBy(shiftLeftTest())
} else {
an[Exception] shouldBe thrownBy(shiftLeftTest())
}
Expand Down Expand Up @@ -455,7 +455,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
)

if (VersionContext.current.isV6SoftForkActivated) {
shiftRightTest()
an[IllegalArgumentException] shouldBe thrownBy(shiftRightTest())
} else {
an[Exception] shouldBe thrownBy(shiftRightTest())
}
Expand Down Expand Up @@ -489,7 +489,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
)

if (VersionContext.current.isV6SoftForkActivated) {
shiftRightTest()
an[IllegalArgumentException] shouldBe thrownBy(shiftRightTest())
} else {
an[Exception] shouldBe thrownBy(shiftRightTest())
}
Expand Down Expand Up @@ -525,7 +525,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
)

if (VersionContext.current.isV6SoftForkActivated) {
shiftRightTest()
an[IllegalArgumentException] shouldBe thrownBy(shiftRightTest())
} else {
an[Exception] shouldBe thrownBy(shiftRightTest())
}
Expand Down

0 comments on commit 297265f

Please sign in to comment.