Skip to content

Commit

Permalink
Tidy up the public module level statics (#6032)
Browse files Browse the repository at this point in the history
Tidies up a lot of PUBLIC module statics - marked some as PRIVATE, made some methods of types.
  • Loading branch information
jdunkerley authored Mar 22, 2023
1 parent 1b30a52 commit dd009fd
Show file tree
Hide file tree
Showing 39 changed files with 353 additions and 334 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Cargo.toml
# GUI
/app/gui/ @MichaelMauderer @wdanilo @farmaazon @mwu-tow @kazcw
/app/gui/view/ @MichaelMauderer @wdanilo @farmaazon @kazcw
/app/gui/view/graph-editor/src/builtin/visualization/java_script/ @MichaelMauderer @wdanilo @farmaazon @kazcw @jdunkerley
/app/ide-desktop/ @MichaelMauderer @wdanilo @kazcw

# Engine (old)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class TableVisualization extends Visualization {
rowData = parsedData.json
dataTruncated = parsedData.all_rows_count !== parsedData.json.length
} else if (parsedData.json != null && isObjectMatrix(parsedData.json)) {
let firstKeys = Object.keys(data[0])
let firstKeys = Object.keys(parsedData.json[0])
columnDefs = firstKeys.map(field => ({ field }))
rowData = parsedData.json.map(obj =>
firstKeys.reduce((acc, key) => ({ ...acc, [key]: toRender(obj[key]) }), {})
Expand Down
14 changes: 14 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,37 @@ make_field_name_selector : JS_Object -> Display -> Single_Choice
make_field_name_selector js_object display=Display.Always =
Single_Choice display=display values=(js_object.field_names.map n->(Option n n.pretty))

## PRIVATE
Make a new JavaScript object.
foreign js new_object = """
return {}

## PRIVATE
Parse a text value into JavaScript object.
foreign js json_parse text = """
return JSON.parse(text)

## PRIVATE
Convert a JavaScript object to a text value.
foreign js json_stringify js_object = """
return JSON.stringify(js_object)

## PRIVATE
Check a JavaScript object has a given property.
foreign js has_property js_object key = """
return js_object.hasOwnProperty(key)

## PRIVATE
Get a value from a JavaScript object.
foreign js get_value object key = """
return object[key]

## PRIVATE
Set a value on a JavaScript object and return the new object.
foreign js set_value object key value = """
return {...object, [key]: value}

## PRIVATE
Gets all the property names of a JavaScript object.
foreign js get_property_names object = """
return Object.getOwnPropertyNames(object)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from project.Data.Boolean import True, False

polyglot java import org.enso.base.ObjectComparator

## ADVANCED
## PRIVATE
Creates a Java Comparator object which can call back to Enso for comparison
of non-primitive types.

Expand All @@ -26,7 +26,7 @@ new custom_comparator=Nothing =
Nothing -> ObjectComparator.getInstance (comparator_to_java Ordering.compare)
_ -> ObjectComparator.new (comparator_to_java custom_comparator)

## ADVANCED
## PRIVATE
Create a Java Comparator with the specified Text_Ordering

Arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import project.Error.Error
import project.Meta
import project.Nothing.Nothing
import project.Panic.Panic
import project.Polyglot
import project.Polyglot.Polyglot

from project.Data.Boolean import Boolean, True, False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import project.Math
import project.Meta
import project.Nothing.Nothing
import project.Panic.Panic
import project.Polyglot

from project.Data.Boolean import Boolean, True, False
from project.Data.Time.Date_Time import ensure_in_epoch
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import project.Math
import project.Meta
import project.Nothing.Nothing
import project.Panic.Panic
import project.Polyglot
import project.Polyglot.Java
import project.Polyglot.Polyglot
import project.Runtime
import project.System
import project.System.Environment
Expand Down Expand Up @@ -44,8 +44,8 @@ export project.Math
export project.Meta
export project.Nothing.Nothing
export project.Panic.Panic
export project.Polyglot
export project.Polyglot.Java
export project.Polyglot.Polyglot
export project.Runtime
export project.System
export project.System.Environment
Expand Down
1 change: 0 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import project.Nothing.Nothing
import project.Polyglot.Java

import project.Error.Error as Base_Error
import project.Polyglot as Base_Polyglot

from project.Data.Boolean import Boolean, True, False

Expand Down
197 changes: 120 additions & 77 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Polyglot.enso
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
Loading

0 comments on commit dd009fd

Please sign in to comment.