Skip to content

Commit

Permalink
fixing JS reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 4, 2024
1 parent e4a611d commit c5c37ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
8 changes: 8 additions & 0 deletions data/shared/src/main/scala/sigma/SigmaDataReflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ object SigmaDataReflection {
)
)

registerClassEntry(classOf[ByteArrayToLong],
constructors = Array(
mkConstructor(Array(classOf[Value[_]])) { args =>
new ByteArrayToLong(args(0).asInstanceOf[Value[SByteArray]])
}
)
)

registerClassEntry(classOf[LongToByteArray],
constructors = Array(
mkConstructor(Array(classOf[Value[_]])) { args =>
Expand Down
18 changes: 0 additions & 18 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1718,24 +1718,6 @@ case object SGlobalMethods extends MonoTypeMethods {
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "Decode nbits-encoded big integer number", ArgInfo("nbits", "NBits-encoded argument"))

/**
* encodeNBits evaluation with costing
*/
def encodeNbits_eval(mc: MethodCall, G: SigmaDslBuilder, bigInt: BigInt)(implicit E: ErgoTreeEvaluator): Long = {
E.addFixedCost(EnDecodeNBitsCost, encodeNBitsMethod.opDesc) {
NBitsUtils.encodeCompactBits(bigInt.asInstanceOf[CBigInt].wrappedValue)
}
}

/**
* decodeNBits evaluation with costing
*/
def decodeNbits_eval(mc: MethodCall, G: SigmaDslBuilder, l: Long)(implicit E: ErgoTreeEvaluator): BigInt = {
E.addFixedCost(EnDecodeNBitsCost, decodeNBitsMethod.opDesc) {
CBigInt(NBitsUtils.decodeCompactBits(l).bigInteger)
}
}

lazy val serializeMethod = SMethod(this, "serialize",
SFunc(Array(SGlobal, tT), SByteArray, Array(paramT)), 3, DynamicCost)
.withIRInfo(MethodCallIrBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sigma.compiler.ir

import sigma.{BigInt, SigmaDslBuilder}
import sigma.ast.SType
import sigma.compiler.ir.primitives.Thunks
import sigma.data.RType
Expand Down Expand Up @@ -512,6 +513,12 @@ object GraphIRReflection {
mkMethod(clazz, "serialize", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaDslBuilder].serialize(args(0).asInstanceOf[ctx.Ref[Any]])
},
mkMethod(clazz, "encodeNbits", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaDslBuilder].encodeNbits(args(0).asInstanceOf[ctx.Ref[ctx.BigInt]])
},
mkMethod(clazz, "decodeNbits", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaDslBuilder].decodeNbits(args(0).asInstanceOf[ctx.Ref[Long]])
},
mkMethod(clazz, "fromBigEndianBytes", Array[Class[_]](classOf[Base#Ref[_]], classOf[TypeDescs#Elem[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaDslBuilder].fromBigEndianBytes(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])(args(1).asInstanceOf[ctx.Elem[SType]])
}
Expand Down

0 comments on commit c5c37ff

Please sign in to comment.