public abstract class RT
extends java.lang.Object
Utility functions for frege code.
Modifier and Type | Class and Description |
---|---|
static class |
RT.GuardFailed
Exception thrown when a guard on a pattern binding fails.
|
static class |
RT.NoMatch
Exception thrown when all matches of a case or lambda fail.
|
static class |
RT.Undefined
Exception thrown when the undefined value is evaluated.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
emptyString
The empty polymorphic value of type StringJ a
|
Constructor and Description |
---|
RT() |
Modifier and Type | Method and Description |
---|---|
static java.util.regex.Matcher |
clone(java.util.regex.Matcher m)
Copy a
Matcher object. |
static int |
constructor(java.lang.Object x)
Get the constructor
|
static <T extends java.io.Serializable> |
copySerializable(T o) |
static java.util.regex.Matcher |
find(java.util.regex.Matcher m)
Perform a matcher operation on a copy of the passed Matcher.
|
static <V> void |
fjMain(Lazy<V> val)
Start a program to run in a fork/join task
|
static boolean |
fork(Prod2 it)
fork execution of an Unknown
|
static Box.Char |
itemAt(java.lang.String value,
int offset)
Cheat with phantom types.
|
static java.util.regex.Matcher |
matches(java.util.regex.Matcher m)
Perform a matcher operation on a copy of the passed Matcher.
|
static <T> T |
our(T o) |
static java.lang.String |
quoteChr(char c)
Utility method used by Char.show to quote a character.
|
static java.lang.String |
quoteStr(java.lang.String a)
Utility method used by String.show to quote a string.
|
static java.lang.String |
replaceAll(java.util.regex.Matcher m,
java.lang.String r)
Perform a matcher operation on a copy of the passed Matcher.
|
static java.lang.String |
replaceFirst(java.util.regex.Matcher m,
java.lang.String r)
Perform a matcher operation on a copy of the passed Matcher.
|
static java.util.regex.Matcher |
useAnchoringBounds(java.util.regex.Matcher m,
boolean b)
Perform a matcher operation on a copy of the passed Matcher.
|
static java.util.regex.Matcher |
usePattern(java.util.regex.Matcher m,
java.util.regex.Pattern p)
Perform a matcher operation on a copy of the passed Matcher.
|
static java.util.regex.Matcher |
usePatternAndFind(java.util.regex.Matcher m,
java.util.regex.Pattern p)
Perform a matcher operation on a copy of the passed Matcher.
|
public static final java.lang.String emptyString
The empty polymorphic value of type StringJ a
Referenced in frege.prelude.List.ListLike_StringJ
public static final int constructor(java.lang.Object x)
public static java.util.regex.Matcher clone(java.util.regex.Matcher m)
Copy a Matcher
object.
Most matcher operations implemented in
Matcher
change the state of the
matcher instance.
Therefore we can't use them directly in frege code.
Instead, we provide here a re-implementation of the functionality
we need. The idea is to make a copy of the matcher before the
destructive operation, run the operation on the copy and return it
to frege code. This is safe because there is no reference to the
copy before the operation in frege code.
As a consequence, many matcher operations appear in frege as
function from Matcher to Matcher or Maybe Matcher.
This function relies on the fact that
Matcher.toMatchResult()
effectively makes a
copy (yet an incomplete one) of the current matcher. It completes the copy by invoking
Matcher.usePattern(java.util.regex.Pattern)
which sets up the internal arrays.
The copy can not be used to retrieve information about the last match operation of the original matcher.
public static java.util.regex.Matcher usePattern(java.util.regex.Matcher m, java.util.regex.Pattern p)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.usePattern(java.util.regex.Pattern)
public static java.util.regex.Matcher useAnchoringBounds(java.util.regex.Matcher m, boolean b)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.useAnchoringBounds(boolean)
public static java.util.regex.Matcher matches(java.util.regex.Matcher m)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.matches()
public static java.util.regex.Matcher find(java.util.regex.Matcher m)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.find()
public static java.util.regex.Matcher usePatternAndFind(java.util.regex.Matcher m, java.util.regex.Pattern p)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.usePattern(java.util.regex.Pattern)
,
Matcher.find()
public static java.lang.String replaceFirst(java.util.regex.Matcher m, java.lang.String r)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.replaceFirst(java.lang.String)
public static java.lang.String replaceAll(java.util.regex.Matcher m, java.lang.String r)
Perform a matcher operation on a copy of the passed Matcher.
Matcher.replaceAll(java.lang.String)
public static final java.lang.String quoteStr(java.lang.String a)
Utility method used by String.show to quote a string.
public static final java.lang.String quoteChr(char c)
Utility method used by Char.show to quote a character.
public static final <T> T our(T o)
public static final <T extends java.io.Serializable> T copySerializable(T o)
public static <V> void fjMain(Lazy<V> val)
Start a program to run in a fork/join task
Called from the java main method of a frege program.
This converts the argument String array to a list and passes this to
the compiled frege main function. The result is an IO action of type
IO () to which then IO.performUnsafe is applied.
The resulting Unknown
then actually executes the frege code
when evaluated.
This method checks first if the system property frege.parallel
is set to a value that does not represent true.
If so, it just evaluates the argument.
Otherwise it submits its argument to a ForkJoinPool
and waits for completion. This ensures that frege code sees itself executed
in a fork join pool and is able to fork further tasks.
In frege code that is not executed in a fork join pool all library functions for ad hoc parallelism shall perform semantically equivalent sequential functions with as little overhead as possible.
val
- a Lazy
value to be evaluated in a fork/join contextpublic static final boolean fork(Prod2 it)
fork execution of an Unknown
If we are in a fork/join pool and the argument contains an unevaluated value evaluation of this value is started in a new fork/join task.
it
- A product of arity 2 that contains the value that must be evaluated in member m1public static final Box.Char itemAt(java.lang.String value, int offset)
Cheat with phantom types.
This method is announced with type String a -> Int -> a but it always returns a (boxed) char.
This is fine as long as nobody is able to actually create a
value with type, say String Int.
This could be done only with another malicious native function, though.