Skip to content

Commit

Permalink
JS tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 4, 2024
1 parent 933b2cc commit 3a5c6d6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
27 changes: 19 additions & 8 deletions core/shared/src/main/scala/sigma/reflection/ReflectionData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
)
)
Expand Down
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/sigma/reflection/StaticImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")})")
}
}

Expand Down
12 changes: 12 additions & 0 deletions sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
}
)
)
Expand Down Expand Up @@ -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
}
)
)
Expand Down Expand Up @@ -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]])
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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](),
Expand Down Expand Up @@ -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](),
Expand All @@ -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"
))
}
}
Expand Down
2 changes: 2 additions & 0 deletions sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1950,4 +1950,6 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
)
}



}

0 comments on commit 3a5c6d6

Please sign in to comment.