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

reference-types.mddocs/

Reference Type Wrappers

Mutable and volatile reference wrappers for all primitive types and objects. These types provide thread-safe access patterns and support for atomic operations, enabling efficient mutable variable handling in Scala Native.

Core Imports

import scala.runtime.{BooleanRef, CharRef, ByteRef, ShortRef, IntRef, LongRef, FloatRef, DoubleRef, ObjectRef}
import scala.runtime.{VolatileBooleanRef, VolatileCharRef, VolatileByteRef, VolatileShortRef, VolatileIntRef, VolatileLongRef, VolatileFloatRef, VolatileDoubleRef, VolatileObjectRef}

Capabilities

Boolean References

Mutable and volatile boolean reference types.

class BooleanRef(var elem: Boolean) extends Serializable {
  override def toString(): String
}

object BooleanRef {
  def create(elem: Boolean): BooleanRef
  def zero(): BooleanRef
}

class VolatileBooleanRef(@volatile var elem: Boolean) extends Serializable {
  override def toString(): String  
}

object VolatileBooleanRef {
  def create(elem: Boolean): VolatileBooleanRef
  def zero(): VolatileBooleanRef
}

Character References

Mutable and volatile character reference types.

class CharRef(var elem: Char) extends Serializable {
  override def toString(): String
}

object CharRef {
  def create(elem: Char): CharRef
  def zero(): CharRef
}

class VolatileCharRef(@volatile var elem: Char) extends Serializable {
  override def toString(): String
}

object VolatileCharRef {
  def create(elem: Char): VolatileCharRef
  def zero(): VolatileCharRef
}

Byte References

Mutable and volatile byte reference types.

class ByteRef(var elem: Byte) extends Serializable {
  override def toString(): String
}

object ByteRef {
  def create(elem: Byte): ByteRef
  def zero(): ByteRef
}

class VolatileByteRef(@volatile var elem: Byte) extends Serializable {
  override def toString(): String
}

object VolatileByteRef {
  def create(elem: Byte): VolatileByteRef
  def zero(): VolatileByteRef
}

Short References

Mutable and volatile short reference types.

class ShortRef(var elem: Short) extends Serializable {
  override def toString(): String
}

object ShortRef {
  def create(elem: Short): ShortRef
  def zero(): ShortRef
}

class VolatileShortRef(@volatile var elem: Short) extends Serializable {
  override def toString(): String
}

object VolatileShortRef {
  def create(elem: Short): VolatileShortRef
  def zero(): VolatileShortRef
}

Integer References

Mutable and volatile integer reference types.

class IntRef(var elem: Int) extends Serializable {
  override def toString(): String
}

object IntRef {
  def create(elem: Int): IntRef
  def zero(): IntRef
}

class VolatileIntRef(@volatile var elem: Int) extends Serializable {
  override def toString(): String
}

object VolatileIntRef {
  def create(elem: Int): VolatileIntRef
  def zero(): VolatileIntRef
}

Long References

Mutable and volatile long reference types.

class LongRef(var elem: Long) extends Serializable {
  override def toString(): String
}

object LongRef {
  def create(elem: Long): LongRef
  def zero(): LongRef
}

class VolatileLongRef(@volatile var elem: Long) extends Serializable {
  override def toString(): String
}

object VolatileLongRef {
  def create(elem: Long): VolatileLongRef
  def zero(): VolatileLongRef
}

Float References

Mutable and volatile float reference types.

class FloatRef(var elem: Float) extends Serializable {
  override def toString(): String
}

object FloatRef {
  def create(elem: Float): FloatRef
  def zero(): FloatRef
}

class VolatileFloatRef(@volatile var elem: Float) extends Serializable {
  override def toString(): String
}

object VolatileFloatRef {
  def create(elem: Float): VolatileFloatRef
  def zero(): VolatileFloatRef
}

Double References

Mutable and volatile double reference types.

class DoubleRef(var elem: Double) extends Serializable {
  override def toString(): String
}

object DoubleRef {
  def create(elem: Double): DoubleRef
  def zero(): DoubleRef
}

class VolatileDoubleRef(@volatile var elem: Double) extends Serializable {
  override def toString(): String
}

object VolatileDoubleRef {
  def create(elem: Double): VolatileDoubleRef
  def zero(): VolatileDoubleRef
}

Object References

Generic mutable and volatile object reference types.

class ObjectRef[A](var elem: A) extends Serializable {
  override def toString(): String
}

object ObjectRef {
  def create[A](elem: A): ObjectRef[A]
  def zero(): ObjectRef[Object]
}

class VolatileObjectRef[A](@volatile var elem: A) extends Serializable {
  override def toString(): String
}

object VolatileObjectRef {
  def create[A](elem: A): VolatileObjectRef[A]
  def zero(): VolatileObjectRef[Object]
}

Usage Examples

import scala.runtime.{BooleanRef, IntRef, ObjectRef, VolatileIntRef}

// Create mutable references
val boolRef = BooleanRef.create(true)
val intRef = IntRef.create(42)
val objRef = ObjectRef.create("hello")

// Modify values
boolRef.elem = false
intRef.elem = 100
objRef.elem = "world"

// Create zero-initialized references
val zeroBool = BooleanRef.zero()  // false
val zeroInt = IntRef.zero()       // 0
val zeroObj = ObjectRef.zero()    // null

// Volatile references for thread-safe access
val volatileInt = VolatileIntRef.create(10)
volatileInt.elem = 20  // Thread-safe assignment

// String representation
println(intRef.toString()) // "42"

Thread Safety

Regular reference types (BooleanRef, IntRef, etc.) provide basic mutable references without built-in thread safety. Volatile reference types (VolatileBooleanRef, VolatileIntRef, etc.) use the @volatile annotation to ensure that reads and writes are immediately visible across threads, providing memory visibility guarantees without full synchronization.

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