public class Box<T> extends Val
Container for arbitrary java reference values.
Used by the compiler to encode native reference types.
A declaration
data X = native "some.reference.type" where // member function declarations ...
creates a noninstantiable class TX that serves as namepsace for the member functions. Yet, the java type for frege type X is always Box<some.reference.type>
In addition, for each primitive type supported by frege, there is
a nested class Box.type where type is the
name given that type in frege.
Hence, Box.Int
is a boxed primitive int.
Modifier and Type | Class and Description |
---|---|
static class |
Box.Bool
Box primitive boolean
|
static class |
Box.Byte
Box primitive byte
|
static class |
Box.Char
Box primitive char
|
static class |
Box.Double
Box primitive double
|
static class |
Box.Float
Box primitive float
|
static class |
Box.Int
Box primitive int
|
static class |
Box.Long
Box primitive long
|
static class |
Box.Short
Box primitive short
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
arrayGet(T[] arr,
int i)
Get array element.
|
static <T> int |
arrayLen(T[] arr)
Get array length.
|
static <T extends Lazy<T>> |
arrayNew(int size)
Create an array with T elements.
|
static <T> void |
arraySet(T[] arr,
int i,
T v)
Update array destructively.
|
static <T> T[] |
arrayUpd(T[] arr,
int i,
T v)
Update array nondestructively.
|
static <V> Lazy<V> |
as(Lazy<FV> val)
coerce a lazy FV to another type
|
static <V> Box<V> |
box(FV value)
evaluate a
FV to Boxed form |
static <T> Box<T> |
mk(T ref)
public constructor for boxed values
|
java.lang.String |
toString() |
_e, _u, _v, constructor
public final T j
Reference to the java object.
This is used in calls to native methods, which could be member functions of the type T.
Frege assumes that this field is never null. Null values could be introduced by native functions whose return type is incorrectly specified or by array accesses.
protected Box(T a)
public static final <T> Box<T> mk(T ref)
ref
- a non null reference of type Tpublic java.lang.String toString()
toString
in class java.lang.Object
public static final <T extends Lazy<T>> T[] arrayNew(int size)
Create an array with T elements.
This works so long as we never try to cast the array implicitely or explicitely to its supposed type. Therefore, native arry types like StringArray need their own special array creation routines.
size
- the size of the arraypublic static final <T> T[] arrayUpd(T[] arr, int i, T v)
Update array nondestructively.
arr
- the arrayi
- index into arrv
- new value to set at index ipublic static final <T> void arraySet(T[] arr, int i, T v)
Update array destructively. This method is not pure!
arr
- the arrayi
- index into arrv
- new value to set at index i
Changes the passed array, therefore it is not pure. Because the return type
is void
there is no way to make the frege compiler believe it is pure.
public static final <T> T arrayGet(T[] arr, int i)
Get array element.
arr
- the arrayi
- index into arrnull
public static final <T> int arrayLen(T[] arr)
Get array length.
arr
- the arrayarr.length