Skip to content

Improve JVM/JS Evaluation Int representation #1581

@johnynek

Description

@johnynek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions