sigma.serialization.ValUseSerializer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sigma-state_2.12 Show documentation
Show all versions of sigma-state_2.12 Show documentation
Interpreter of a Sigma-State language
The newest version!
package sigma.serialization
import sigma.ast._
case class ValUseSerializer(cons: (Int, SType) => Value[SType]) extends ValueSerializer[ValUse[SType]] {
override def opDesc = ValUse
override def serialize(obj: ValUse[SType], w: SigmaByteWriter): Unit = {
w.putUInt(obj.valId)
}
override def parse(r: SigmaByteReader): Value[SType] = {
val id = r.getUInt.toInt
// Note, when id < 0 as a result of Int overflow, the r.valDefTypeStore(id) won't throw
// and also ValUse node will be created, but then its evaluation will throw (because
// there will be no ValDef with negative id in the env.
// However, in general, there is no guarantee that this ValUse will ever be executed
// as it may be in an `if` branch.
val tpe = r.valDefTypeStore(id)
cons(id, tpe)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy