Skip to content

Commit 2f79634

Browse files
committed
chore: add all the files in scala
1 parent 25f67c5 commit 2f79634

File tree

117 files changed

+12777
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+12777
-0
lines changed

library/src/scala/AnyVal.scala

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
/** `AnyVal` is the root class of all ''value types'', which describe values
16+
* not implemented as objects in the underlying host system. Value classes
17+
* are specified in Scala Language Specification, section 12.2.
18+
*
19+
* The standard implementation includes nine `AnyVal` subtypes:
20+
*
21+
* [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
22+
* [[scala.Short]], and [[scala.Byte]] are the ''numeric value types''.
23+
*
24+
* [[scala.Unit]] and [[scala.Boolean]] are the ''non-numeric value types''.
25+
*
26+
* Other groupings:
27+
*
28+
* - The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
29+
* - The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
30+
* - The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
31+
*
32+
* A subclass of `AnyVal` is called a ''user-defined value class''
33+
* and is treated specially by the compiler. Properly-defined user value classes provide a way
34+
* to improve performance on user-defined types by avoiding object allocation at runtime, and by
35+
* replacing virtual method invocations with static method invocations.
36+
*
37+
* User-defined value classes which avoid object allocation...
38+
*
39+
* - must have a single `val` parameter that is the underlying runtime representation.
40+
* - can define `def`s, but no `val`s, `var`s, or nested `trait`s, `class`es or `object`s.
41+
* - typically extend no other trait apart from `AnyVal`.
42+
* - cannot be used in type tests or pattern matching.
43+
* - may not override `equals` or `hashCode` methods.
44+
*
45+
* A minimal example:
46+
* {{{
47+
* class Wrapper(val underlying: Int) extends AnyVal {
48+
* def foo: Wrapper = new Wrapper(underlying * 19)
49+
* }
50+
* }}}
51+
*
52+
* It's important to note that user-defined value classes are limited, and in some circumstances,
53+
* still must allocate a value class instance at runtime. These limitations and circumstances are
54+
* explained in greater detail in the [[https://docs.scala-lang.org/overviews/core/value-classes.html Value Classes and Universal Traits]].
55+
*/
56+
abstract class AnyVal extends Any {
57+
def getClass(): Class[_ <: AnyVal] = null
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
/** A common supertype for companion classes of primitive types.
16+
*
17+
* A common trait for /companion/ objects of primitive types comes handy
18+
* when parameterizing code on types. For instance, the specialized
19+
* annotation is passed a sequence of types on which to specialize:
20+
* {{{
21+
* class Tuple1[@specialized(Unit, Int, Double) T]
22+
* }}}
23+
*
24+
*/
25+
private[scala] trait AnyValCompanion extends Specializable { }

library/src/scala/App.scala

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
import java.lang.System.{currentTimeMillis => currentTime}
16+
17+
import scala.annotation.nowarn
18+
import scala.collection.mutable.ListBuffer
19+
20+
/** The `App` trait can be used to quickly turn objects
21+
* into executable programs. Here is an example:
22+
* {{{
23+
* object Main extends App {
24+
* Console.println("Hello World: " + (args mkString ", "))
25+
* }
26+
* }}}
27+
*
28+
* No explicit `main` method is needed. Instead,
29+
* the whole class body becomes the “main method”.
30+
*
31+
* `args` returns the current command line arguments as an array.
32+
*
33+
* ==Caveats==
34+
*
35+
* '''''It should be noted that this trait is implemented using the [[DelayedInit]]
36+
* functionality, which means that fields of the object will not have been initialized
37+
* before the main method has been executed.'''''
38+
*
39+
* Future versions of this trait will no longer extend `DelayedInit`.
40+
*
41+
* In Scala 3, the `DelayedInit` feature was dropped. `App` exists only in a limited form
42+
* that also does not support command line arguments and will be deprecated in the future.
43+
*
44+
* [[https://docs.scala-lang.org/scala3/book/methods-main-methods.html @main]] methods are the
45+
* recommended scheme to generate programs that can be invoked from the command line in Scala 3.
46+
*
47+
* {{{
48+
* @main def runMyProgram(args: String*): Unit = {
49+
* // your program here
50+
* }
51+
* }}}
52+
*
53+
* If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an
54+
* explicit `main` method:
55+
* {{{
56+
* object Main {
57+
* def main(args: Array[String]): Unit = {
58+
* // your program here
59+
* }
60+
* }
61+
* }}}
62+
*/
63+
@nowarn("""cat=deprecation&origin=scala\.DelayedInit""")
64+
trait App extends DelayedInit {
65+
66+
/** The time when the execution of this program started, in milliseconds since 1
67+
* January 1970 UTC. */
68+
final val executionStart: Long = currentTime
69+
70+
/** The command line arguments passed to the application's `main` method.
71+
*/
72+
protected final def args: Array[String] = _args
73+
74+
private[this] var _args: Array[String] = _
75+
76+
private[this] val initCode = new ListBuffer[() => Unit]
77+
78+
/** The init hook. This saves all initialization code for execution within `main`.
79+
* This method is normally never called directly from user code.
80+
* Instead it is called as compiler-generated code for those classes and objects
81+
* (but not traits) that inherit from the `DelayedInit` trait and that do not
82+
* themselves define a `delayedInit` method.
83+
* @param body the initialization code to be stored for later execution
84+
*/
85+
@deprecated("the delayedInit mechanism will disappear", "2.11.0")
86+
override def delayedInit(body: => Unit): Unit = {
87+
initCode += (() => body)
88+
}
89+
90+
/** The main method.
91+
* This stores all arguments so that they can be retrieved with `args`
92+
* and then executes all initialization code segments in the order in which
93+
* they were passed to `delayedInit`.
94+
* @param args the arguments passed to the main method
95+
*/
96+
final def main(args: Array[String]) = {
97+
this._args = args
98+
for (proc <- initCode) proc()
99+
if (util.Properties.propIsSet("scala.time")) {
100+
val total = currentTime - executionStart
101+
Console.println("[total " + total + "ms]")
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)