Native-specific overrides for Scala standard library components, providing VM memory management and enhanced Enumeration implementation
—
Platform-specific implementations that replace or enhance standard Scala library components with native-optimized versions. These overrides provide better performance, memory management, and compatibility with the Scala Native runtime environment.
Native-optimized memory management utilities for collection operations, providing atomic memory fence operations using platform-specific implementations.
package scala.collection.immutable
/* private[immutable] */ object VM {
/**
* Performs a release memory fence operation using native atomic operations.
* Ensures that all memory operations before this fence are visible to other threads
* before any memory operations after the fence.
*
* Used internally by immutable collections for thread-safe operations.
* Implementation: atomic_thread_fence(memory_order_release)
*/
def releaseFence(): Unit
}Usage Example:
import scala.collection.immutable.VM
// Used internally by collections, but can be called directly for custom thread-safe operations
class ThreadSafeCounter {
@volatile private var count = 0
def increment(): Unit = {
count += 1
VM.releaseFence() // Ensure visibility to other threads
}
def get(): Int = count
}Native-specific implementation of Scala enumerations with improved performance and Scala.js compatibility. Provides the complete enumeration API with native-optimized value storage and retrieval.
abstract class Enumeration(initial: Int) extends Serializable {
/**
* Creates an enumeration starting from id 0.
*/
def this(): Enumeration
/**
* The values of this enumeration as a set.
* @return ValueSet containing all defined enumeration values
*/
def values: ValueSet
/**
* Returns the enumeration value with the given id.
* @param x the id of the value
* @return the enumeration value
* @throws NoSuchElementException if no value with given id exists
*/
def apply(x: Int): Value
/**
* Returns the enumeration value with the given name.
* @param s the name of the value
* @return the enumeration value
* @throws NoSuchElementException if no value with given name exists
*/
def withName(s: String): Value
/**
* The highest integer amongst those used to identify values in this enumeration.
* @return the maximum id used
*/
def maxId: Int
/**
* Returns the string representation of this enumeration (the class name).
* @return the class name without package and $ suffix
*/
override def toString: String
/**
* Creates a fresh value, part of this enumeration, with auto-generated id.
* @return new enumeration value
*/
protected def Value: Value
/**
* Creates a fresh value with specified id.
* @param i unique identifier for this value
* @return new enumeration value
*/
protected def Value(i: Int): Value
/**
* Creates a fresh value with specified name.
* @param name human-readable name for this value
* @return new enumeration value
*/
protected def Value(name: String): Value
/**
* Creates a fresh value with specified id and name.
* @param i unique identifier for this value
* @param name human-readable name for this value
* @return new enumeration value
*/
protected def Value(i: Int, name: String): Value
}abstract class Enumeration#Value extends Ordered[Value] with Serializable {
/**
* The unique identifier of this enumeration value.
* @return the id as an integer
*/
def id: Int
/**
* Compares this value with another enumeration value.
* @param that the value to compare with
* @return negative, zero, or positive integer as this value is less than, equal to, or greater than that
*/
def compare(that: Value): Int
/**
* Creates a ValueSet containing this value and another value.
* @param v the other value to include
* @return ValueSet containing both values
*/
def +(v: Value): ValueSet
}class Enumeration#ValueSet extends immutable.SortedSet[Value] with Serializable {
/**
* Tests whether this set contains the given value.
* @param v the value to test
* @return true if the value is in this set
*/
def contains(v: Value): Boolean
/**
* Creates a new set with an additional value.
* @param value the value to add
* @return new ValueSet containing the additional value
*/
def +(value: Value): ValueSet
/**
* Creates a new set with a value removed.
* @param value the value to remove
* @return new ValueSet without the specified value
*/
def -(value: Value): ValueSet
/**
* Creates an iterator over the values in this set in increasing order of their ids.
* @return iterator over the enumeration values
*/
def iterator: Iterator[Value]
/**
* Creates a bit mask for the zero-adjusted ids in this set.
* @return array of longs representing the bit mask
*/
def toBitMask: Array[Long]
}object Enumeration#ValueSet {
/**
* The empty value set.
*/
val empty: ValueSet
/**
* Creates a value set consisting of given elements.
* @param elems the values to include
* @return ValueSet containing the specified values
*/
def apply(elems: Value*): ValueSet
/**
* Creates a value set from a bit mask representation.
* @param elems array of longs representing the bit mask
* @return ValueSet corresponding to the bit mask
*/
def fromBitMask(elems: Array[Long]): ValueSet
/**
* Creates a builder for constructing ValueSets.
* @return mutable builder for ValueSet
*/
def newBuilder: mutable.Builder[Value, ValueSet]
}protected class Enumeration#Val(i: Int, name: String) extends Value with Serializable {
/**
* Creates a Val with specified id and auto-generated name.
* @param i the unique identifier
*/
def this(i: Int): Val
/**
* Creates a Val with auto-generated id and specified name.
* @param name the human-readable name
*/
def this(name: String): Val
/**
* Creates a Val with auto-generated id and name.
*/
def this(): Val
/**
* The unique identifier of this value.
* @return the id as an integer
*/
def id: Int
/**
* String representation of this value (name or placeholder).
* @return the name if provided, otherwise a placeholder with id and class
*/
override def toString(): String
}object Enumeration#ValueOrdering extends Ordering[Value] {
/**
* Compares two enumeration values by their ids.
* @param x first value
* @param y second value
* @return negative, zero, or positive integer comparison result
*/
def compare(x: Value, y: Value): Int
}Usage Example:
object Color extends Enumeration {
type Color = Value
val Red, Green, Blue, Yellow, Orange = Value
}
object Priority extends Enumeration {
val Low = Value(1, "low")
val Medium = Value(5, "medium")
val High = Value(10, "high")
}
// Usage
val color = Color.Red
val priority = Priority.withName("high")
// Create sets of values
val primaryColors = Color.ValueSet(Color.Red, Color.Green, Color.Blue)
val importantPriorities = Priority.High + Priority.Medium
// Iterate over all values
for (c <- Color.values) {
println(s"Color: $c (id: ${c.id})")
}Install with Tessl CLI
npx tessl i tessl/maven-org-scala-native--scalalib-native0-5-2-13