-
Notifications
You must be signed in to change notification settings - Fork 12
Improve JVM/JS Evaluation Int representation #1581
Copy link
Copy link
Closed
Description
Currently, the scala Evaluation representation of bosatsu Int is scala BigInt. Since we don't need the syntax of scala BigInt there (which itself just wraps BigInteger) we could instead use:
opaque type EvalInt = java.lang.Long | java.math.BigInteger
object EvalInt {
// add an extension method here for all the methods we need.
class EvalIntMatch(private val v: Any) extends AnyVal {
def isEmpty = v match {
case _: (java.lang.Long | java.match.BigInteger) => false
case _ => true
}
def get = v.asInstanceOf[java.lang.Long | java.math.BigInteger]
}
def unapply(v: Any): EvalIntMatch = ...
def fromInt(i: Int): EvalInt = java.lang.Long.valueOf(i.toLong)
...
}Then we can just match on Long or BigInteger and not do any additional wrapping.
The next part is that on scalajs, Long is less efficient than Int, so we could put the above in .jvm/ directory and have a Long backed implementation, but on scalajs we use EvalInt = java.lang.Int | java.math.BigInteger in the .js directory with the exact same API, so we have an Int backed system which will perform better in browsers on or nodejs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels