CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-scala-native--auxlib-native0-5-3

Auxiliary libraries for Scala Native runtime providing essential runtime support including boxed types, concurrent collections, and utility functions

Pending
Overview
Eval results
Files

mathematical-support.mddocs/

Mathematical Number Support

Abstract base classes and utilities for Scala's numeric type hierarchy, providing foundation for custom numeric types and mathematical operations. Includes runtime utilities, hash functions, and function interoperability support.

Core Imports

import scala.math.ScalaNumber
import scala.runtime.Statics
import scala.runtime.function.{JProcedure0, JProcedure1, JProcedure2} // Scala 3 only
import scala.scalanative.runtime.BoxedUnit

Capabilities

Scala Number Base Class

Abstract base class for Scala's numeric type hierarchy.

abstract class ScalaNumber extends java.lang.Number {
  protected def isWhole(): Boolean
  def underlying(): Object
}

Runtime Static Utilities

Core runtime utilities for hashing, memory operations, and error handling.

object Statics {
  // Hash functions
  def mix(hash: Int, data: Int): Int
  def mixLast(hash: Int, data: Int): Int
  def finalizeHash(hash: Int, length: Int): Int
  def avalanche(h: Int): Int
  def longHash(lv: Long): Int
  def longHashShifted(lv: Long): Int
  def doubleHash(dv: Double): Int
  def floatHash(fv: Float): Int
  def anyHash(x: Object): Int
  
  // Utilities
  def pfMarker: java.lang.Object
  def releaseFence(): Unit
  def ioobe[T](n: Int): T
}

Function Interoperability (Scala 3)

Java-compatible procedure traits that return Unit but integrate with Java Function interfaces.

trait JProcedure0 extends scala.Function0[Object] with java.io.Serializable {
  def applyVoid(): Unit
  def apply(): Object
}

trait JProcedure1[T1] extends scala.Function1[T1, Object] with java.io.Serializable {
  def applyVoid(t1: T1): Unit
  def apply(t1: T1): Object
}

trait JProcedure2[T1, T2] extends scala.Function2[T1, T2, Object] with java.io.Serializable {
  def applyVoid(t1: T1, t2: T2): Unit
  def apply(t1: T1, t2: T2): Object
}

// ... Additional JProcedure traits from JProcedure3 to JProcedure22

Trait Support

Marker class for trait initialization support.

class TraitSetter

BoxedUnit Support

Scala Native-specific BoxedUnit implementation.

object BoxedUnit extends scala.runtime.BoxedUnit

Usage Examples

import scala.math.ScalaNumber
import scala.runtime.Statics

// Extending ScalaNumber for custom numeric types
class MyNumber(value: Double) extends ScalaNumber {
  protected def isWhole(): Boolean = value == value.toLong
  def underlying(): Object = Double.box(value)
  
  def intValue(): Int = value.toInt
  def longValue(): Long = value.toLong
  def floatValue(): Float = value.toFloat
  def doubleValue(): Double = value
}

// Using hash functions
val hash1 = Statics.mix(0, 42)
val hash2 = Statics.longHash(123456789L)
val hash3 = Statics.doubleHash(3.14159)
val anyHash = Statics.anyHash("hello")

// Using JProcedure traits (Scala 3)
import scala.runtime.function.JProcedure1

class MyProcedure extends JProcedure1[String] {
  def applyVoid(s: String): Unit = println(s"Processing: $s")
}

val proc = new MyProcedure()
proc.applyVoid("test")  // Prints: Processing: test
val result = proc.apply("test")  // Returns BoxedUnit.UNIT

Hash Function Details

The Statics object provides optimized hash functions used internally by the Scala Native runtime:

  • mix and mixLast: MurmurHash3-based mixing functions
  • finalizeHash and avalanche: Hash finalization with bit avalanching
  • Type-specific hash functions for Long, Double, Float with proper handling of special values
  • anyHash: Universal hash function for any object with null safety

JProcedure Trait Hierarchy

The JProcedure traits (available in Scala 3) provide Java interoperability for functions that return Unit:

  • JProcedure0 through JProcedure22 support 0-22 parameters
  • Each trait extends the corresponding Scala Function trait
  • applyVoid method performs the actual Unit-returning operation
  • apply method wraps the result in BoxedUnit.UNIT for Java compatibility

Install with Tessl CLI

npx tessl i tessl/maven-org-scala-native--auxlib-native0-5-3

docs

array-runtime.md

boxing-unboxing.md

concurrent-collections.md

index.md

mathematical-support.md

reference-types.md

tile.json