From 3a5c6d6d8d9029a5e002862a6e60c41973186a68 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Mon, 4 Nov 2024 15:06:46 +0300 Subject: [PATCH] JS tests fixed --- .../sigma/reflection/ReflectionData.scala | 27 +++++++++++++------ .../scala/sigma/reflection/StaticImpl.scala | 4 ++- .../sigma/compiler/ir/GraphIRReflection.scala | 12 +++++++++ .../ir/wrappers/sigma/SigmaDslUnit.scala | 2 +- .../ir/wrappers/sigma/impl/SigmaDslImpl.scala | 6 ++--- .../scala/sigma/LanguageSpecificationV6.scala | 2 ++ 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala index 204792ee50..34bffbca34 100644 --- a/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala +++ b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala @@ -101,35 +101,43 @@ object ReflectionData { } { val clazz = classOf[sigma.BigInt] - val paramTypes = Array[Class[_]](clazz) + val noParamTypes = Array[Class[_]]() + val oneParamTypes = Array[Class[_]](clazz) registerClassEntry(clazz, methods = Map( - mkMethod(clazz, "add", paramTypes) { (obj, args) => + mkMethod(clazz, "add", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].add(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "max", paramTypes) { (obj, args) => + mkMethod(clazz, "max", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].max(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "min", paramTypes) { (obj, args) => + mkMethod(clazz, "min", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].min(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "subtract", paramTypes) { (obj, args) => + mkMethod(clazz, "subtract", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].subtract(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "multiply", paramTypes) { (obj, args) => + mkMethod(clazz, "multiply", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].multiply(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "mod", paramTypes) { (obj, args) => + mkMethod(clazz, "mod", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].mod(args(0).asInstanceOf[BigInt]) }, - mkMethod(clazz, "divide", paramTypes) { (obj, args) => + mkMethod(clazz, "divide", oneParamTypes) { (obj, args) => obj.asInstanceOf[BigInt].divide(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "toUnsigned", noParamTypes) { (obj, _) => + obj.asInstanceOf[BigInt].toUnsigned + }, + mkMethod(clazz, "toUnsignedMod", Array[Class[_]](classOf[sigma.UnsignedBigInt])) { (obj, args) => + obj.asInstanceOf[BigInt].toUnsignedMod(args(0).asInstanceOf[UnsignedBigInt]) } ) ) } { val clazz = classOf[sigma.UnsignedBigInt] + val noParamTypes = Array[Class[_]]() val oneParamTypes = Array[Class[_]](clazz) val twoParamTypes = Array[Class[_]](clazz, clazz) registerClassEntry(clazz, @@ -169,6 +177,9 @@ object ReflectionData { }, mkMethod(clazz, "multiplyMod", twoParamTypes) { (obj, args) => obj.asInstanceOf[UnsignedBigInt].multiplyMod(args(0).asInstanceOf[UnsignedBigInt], args(1).asInstanceOf[UnsignedBigInt]) + }, + mkMethod(clazz, "toSigned", noParamTypes) { (obj, _) => + obj.asInstanceOf[UnsignedBigInt].toSigned() } ) ) diff --git a/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala b/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala index e95eea1f59..6db911d9bc 100644 --- a/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala +++ b/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala @@ -72,7 +72,9 @@ class SRClass[T](val clazz: Class[T], parameterTypes: Class[_]*): RMethod = { methods.get((name, parameterTypes)) match { case Some(m) => m - case _ => throw new NoSuchMethodException(s"${clazz.getName}.$name(${parameterTypes.map(_.getName).mkString(",")})") + case _ => + println(methods) + throw new NoSuchMethodException(s"${clazz.getName}.$name(${parameterTypes.map(_.getName).mkString(",")})") } } diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala index 78e1c09ffa..ea665c247f 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala @@ -115,6 +115,12 @@ object GraphIRReflection { }, mkMethod(clazz, "divide", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => obj.asInstanceOf[ctx.BigInt].divide(args(0).asInstanceOf[ctx.Ref[ctx.BigInt]]) + }, + mkMethod(clazz, "toUnsigned", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[ctx.BigInt].toUnsigned() + }, + mkMethod(clazz, "toUnsignedMod", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => + obj.asInstanceOf[ctx.BigInt].toUnsignedMod(args(0).asInstanceOf[ctx.Ref[ctx.UnsignedBigInt]]) } ) ) @@ -159,6 +165,9 @@ object GraphIRReflection { }, mkMethod(clazz, "modInverse", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => obj.asInstanceOf[ctx.UnsignedBigInt].modInverse(args(0).asInstanceOf[ctx.Ref[ctx.UnsignedBigInt]]) + }, + mkMethod(clazz, "toSigned", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[ctx.UnsignedBigInt].toSigned } ) ) @@ -410,6 +419,9 @@ object GraphIRReflection { mkMethod(clazz, "exp", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => obj.asInstanceOf[ctx.GroupElement].exp(args(0).asInstanceOf[ctx.Ref[ctx.BigInt]]) }, + mkMethod(clazz, "expUnsigned", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => + obj.asInstanceOf[ctx.GroupElement].expUnsigned(args(0).asInstanceOf[ctx.Ref[ctx.UnsignedBigInt]]) + }, mkMethod(clazz, "multiply", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => obj.asInstanceOf[ctx.GroupElement].multiply(args(0).asInstanceOf[ctx.Ref[ctx.GroupElement]]) }, diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala index 491a196f8d..f719bb6f8f 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala @@ -28,7 +28,7 @@ import scalan._ def plusMod(that: Ref[UnsignedBigInt], m: Ref[UnsignedBigInt]): Ref[UnsignedBigInt] def subtractMod(that: Ref[UnsignedBigInt], m: Ref[UnsignedBigInt]): Ref[UnsignedBigInt] def multiplyMod(that: Ref[UnsignedBigInt], m: Ref[UnsignedBigInt]): Ref[UnsignedBigInt] - def toSigned: Ref[BigInt] + def toSigned(): Ref[BigInt] }; trait GroupElement extends Def[GroupElement] { def exp(k: Ref[BigInt]): Ref[GroupElement]; diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala index e0376b4c91..576f4138a3 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala @@ -395,7 +395,7 @@ object UnsignedBigInt extends EntityObject("UnsignedBigInt") { true, false, element[UnsignedBigInt])) } - override def toSigned: Ref[BigInt] = { + override def toSigned(): Ref[BigInt] = { asRep[BigInt](mkMethodCall(self, UnsignedBigIntClass.getMethod("toSigned"), Array[AnyRef](), @@ -499,7 +499,7 @@ object UnsignedBigInt extends EntityObject("UnsignedBigInt") { true, true, element[UnsignedBigInt])) } - def toSigned: Ref[BigInt] = { + def toSigned(): Ref[BigInt] = { asRep[BigInt](mkMethodCall(source, UnsignedBigIntClass.getMethod("toSigned"), Array[AnyRef](), @@ -522,7 +522,7 @@ object UnsignedBigInt extends EntityObject("UnsignedBigInt") { super.collectMethods ++ Elem.declaredMethods(RClass(classOf[UnsignedBigInt]), RClass(classOf[UnsignedBigInt]), Set( "add", "subtract", "multiply", "divide", "mod", "modInverse", - "min", "max", "plusMod", "subtractMod", "multiplyMod" + "min", "max", "plusMod", "subtractMod", "multiplyMod", "toSigned" )) } } diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala index 15ce673332..9750c56b01 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala @@ -1950,4 +1950,6 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => ) } + + }