-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up the public module level statics (#6032)
Tidies up a lot of PUBLIC module statics - marked some as PRIVATE, made some methods of types.
- Loading branch information
1 parent
1b30a52
commit dd009fd
Showing
39 changed files
with
353 additions
and
334 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 120 additions & 77 deletions
197
distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,160 @@ | ||
## A module representing interactions with polyglot languages. | ||
Polyglot is a term that refers to other languages (such as Java) that are | ||
running on the same JVM. | ||
|
||
import project.Any.Any | ||
import project.Data.Array.Array | ||
import project.Data.Boolean.Boolean | ||
import project.Data.Numbers.Integer | ||
import project.Data.Text.Text | ||
import project.Data.Vector.Vector | ||
import project.Nothing.Nothing | ||
import project.Runtime.Source_Location.Source_Location | ||
|
||
@Builtin_Type | ||
type Polyglot | ||
## Reads the number of elements in a given polyglot array object. | ||
|
||
Arguments: | ||
- array: a polyglot array object, originating in any supported language. | ||
get_array_size : Any -> Integer | ||
get_array_size array = @Builtin_Method "Polyglot.get_array_size" | ||
|
||
## Reads the element in a given polyglot array object. | ||
|
||
Arguments: | ||
- index: The index to get the element from. | ||
read_array_element : Any -> Integer -> Any | ||
read_array_element array index = @Builtin_Method "Polyglot.read_array_element" | ||
|
||
## Executes a polyglot function object (e.g. a lambda). | ||
|
||
Arguments: | ||
- callable: The polyglot function object to execute. | ||
- arguments: A vector of arguments to callable. | ||
execute : Any -> Vector -> Any | ||
execute callable arguments = @Builtin_Method "Polyglot.execute" | ||
|
||
## Performs a by-name lookup for a member in a polyglot object. | ||
|
||
Arguments: | ||
- object: The polyglot object on which to perform the member lookup. | ||
- member_name: The textual name of the member to lookup. | ||
|
||
> Example | ||
Look up the field a on an object o. | ||
Polyglot.get_member o "a" | ||
get_member : Any -> Text -> Any | ||
get_member object member_name = @Builtin_Method "Polyglot.get_member" | ||
|
||
## Returns a polyglot array of all of the members of the provided object. | ||
|
||
Arguments: | ||
- object: The object from which to get a list of member names. | ||
|
||
> Example | ||
Get a list of the fields for an object o. | ||
Polyglot.get_members o | ||
get_members : Any -> Array | ||
get_members object = @Builtin_Method "Polyglot.get_members" | ||
|
||
## Instantiates a polyglot object using the provided constructor. | ||
|
||
## Reads the number of elements in a given polyglot array object. | ||
Arguments: | ||
- constructor: The constructor with which to instantiate the object. | ||
- arguments: A vector of the arguments to pass to the polyglot | ||
constructor. | ||
|
||
Arguments: | ||
- array: a polyglot array object, originating in any supported language. | ||
get_array_size : Any -> Integer | ||
get_array_size array = @Builtin_Method "Polyglot.get_array_size" | ||
> Example | ||
Instantiate a new Java Integer with the value 1. | ||
Polyglot.new Integer [1] | ||
new : Any -> Vector -> Any | ||
new constructor arguments = @Builtin_Method "Polyglot.new" | ||
|
||
## Reads the element in a given polyglot array object. | ||
## Invokes a method on a polyglot object by name. | ||
|
||
Arguments: | ||
- index: The index to get the element from. | ||
read_array_element : Any -> Integer -> Any | ||
read_array_element array index = @Builtin_Method "Polyglot.read_array_element" | ||
Arguments: | ||
- target: The polyglot object on which to call the method. | ||
- name: The name of the method. | ||
- arguments: The arguments to pass to the method given by name. | ||
invoke : Any -> Text -> Vector -> Any | ||
invoke target name arguments = @Builtin_Method "Polyglot.invoke" | ||
|
||
## Executes a polyglot function object (e.g. a lambda). | ||
## ADVANCED | ||
UNSTABLE | ||
|
||
Arguments: | ||
- callable: The polyglot function object to execute. | ||
- arguments: A vector of arguments to callable. | ||
execute : Any -> Vector -> Any | ||
execute callable arguments = @Builtin_Method "Polyglot.execute" | ||
Checks if `value` defines a source location. | ||
|
||
## Performs a by-name lookup for a member in a polyglot object. | ||
Source locations are typically exposed by functions, classes, sometimes | ||
also other objects to specify their allocation sites. | ||
has_source_location : Any -> Boolean | ||
has_source_location value = @Builtin_Method "Polyglot.has_source_location" | ||
|
||
Arguments: | ||
- object: The polyglot object on which to perform the member lookup. | ||
- member_name: The textual name of the member to lookup. | ||
## ADVANCED | ||
UNSTABLE | ||
|
||
> Example | ||
Look up the field a on an object o. | ||
Polyglot.get_member o "a" | ||
get_member : Any -> Text -> Any | ||
get_member object member_name = @Builtin_Method "Polyglot.get_member" | ||
Gets the source location of `value`. | ||
|
||
## Returns a polyglot array of all of the members of the provided object. | ||
Source locations are typically exposed by functions, classes, sometimes | ||
also other objects to specify their allocation sites. | ||
This method will throw a polyglot exception if | ||
`Polyglot.has_source_location value` returns `False`. | ||
get_source_location : Any -> Source_Location | ||
get_source_location value = @Builtin_Method "Polyglot.get_source_location" | ||
|
||
Arguments: | ||
- object: The object from which to get a list of member names. | ||
## Checks if a polyglot language is installed in the runtime environment. | ||
|
||
> Example | ||
Get a list of the fields for an object o. | ||
Polyglot.get_members o | ||
get_members : Any -> Array | ||
get_members object = @Builtin_Method "Polyglot.get_members" | ||
Arguments: | ||
- langauge_name: The name of the language to test | ||
is_language_installed : Text -> Boolean | ||
is_language_installed language_name = @Builtin_Method "Polyglot.is_language_installed" | ||
|
||
## Instantiates a polyglot object using the provided constructor. | ||
## ADVANCED | ||
UNSTABLE | ||
|
||
Arguments: | ||
- constructor: The constructor with which to instantiate the object. | ||
- arguments: A vector of the arguments to pass to the polyglot | ||
constructor. | ||
Returns the executable name of a polyglot object. | ||
get_executable_name : Any -> Text | ||
get_executable_name value = @Builtin_Method "Polyglot.get_executable_name" | ||
|
||
> Example | ||
Instantiate a new Java Integer with the value 1. | ||
Polyglot.new Integer [1] | ||
new : Any -> Vector -> Any | ||
new constructor arguments = @Builtin_Method "Polyglot.new" | ||
## Utilities for working with Java polyglot objects. | ||
type Java | ||
## Adds the provided entry to the host class path. | ||
|
||
## Invokes a method on a polyglot object by name. | ||
Arguments: | ||
- path: The java classpath entry to add. | ||
|
||
Arguments: | ||
- target: The polyglot object on which to call the method. | ||
- name: The name of the method. | ||
- arguments: The arguments to pass to the method given by name. | ||
invoke : Any -> Text -> Vector -> Any | ||
invoke target name arguments = @Builtin_Method "Polyglot.invoke" | ||
Use of the actual polyglot imports system should be preferred to use of | ||
this method. | ||
|
||
## ADVANCED | ||
UNSTABLE | ||
> Example | ||
Adding Random to the classpath. | ||
|
||
Checks if `value` defines a source location. | ||
Java.add_to_class_path "java.util.Random" | ||
add_to_class_path : Text -> Nothing | ||
add_to_class_path path = @Builtin_Method "Java.add_to_class_path" | ||
|
||
Source locations are typically exposed by functions, classes, sometimes | ||
also other objects to specify their allocation sites. | ||
has_source_location : Any -> Boolean | ||
has_source_location value = @Builtin_Method "Polyglot.has_source_location" | ||
## Looks up a java symbol on the classpath by name. | ||
|
||
## ADVANCED | ||
UNSTABLE | ||
Arguments: | ||
- name: The name of the java symbol to look up. | ||
|
||
Gets the source location of `value`. | ||
Use of the actual polyglot imports system should be preferred to use of | ||
this method. | ||
|
||
Source locations are typically exposed by functions, classes, sometimes | ||
also other objects to specify their allocation sites. | ||
This method will throw a polyglot exception if | ||
`Polyglot.has_source_location value` returns `False`. | ||
get_source_location : Any -> Source_Location | ||
get_source_location value = @Builtin_Method "Polyglot.get_source_location" | ||
> Example | ||
Look up java's Random class. | ||
|
||
## Checks if a polyglot language is installed in the runtime environment. | ||
Java.lookup_class "java.util.Random" | ||
lookup_class : Text -> Any | ||
lookup_class name = @Builtin_Method "Java.lookup_class" | ||
|
||
Arguments: | ||
- langauge_name: The name of the language to test | ||
is_language_installed : Text -> Boolean | ||
is_language_installed language_name = @Builtin_Method "Polyglot.is_language_installed" | ||
## PRIVATE | ||
|
||
## ADVANCED | ||
UNSTABLE | ||
Checks whether an object is an instance of a given class. | ||
|
||
Returns the executable name of a polyglot object. | ||
get_executable_name : Any -> Text | ||
get_executable_name value = @Builtin_Method "Polyglot.get_executable_name" | ||
Arguments: | ||
- object: The object to check for class membership. | ||
- class: The java class to check for membership in. | ||
is_instance : Any -> Any -> Boolean | ||
is_instance object class = | ||
class_object = class.class | ||
class_object.isInstance object |
Oops, something went wrong.