Skip to content

Commit d444b85

Browse files
committed
Take out R code snippets from Embedding Languages guide
1 parent 2764c87 commit d444b85

File tree

1 file changed

+31
-49
lines changed

1 file changed

+31
-49
lines changed

docs/reference-manual/embedding/embed-languages.md

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ To use community-licensed versions instead, add the `-community` suffix to each
6969
To access [polyglot isolate](#polyglot-isolates) artifacts, use the `-isolate` suffix instead (for example, `js-isolate`).
7070

7171
The artifacts `languages` and `tools` include all available languages and tools as dependencies.
72-
This artifact might grow or shrink between major releases. We recommend selecting only the needed language(s) for a production deployment.
72+
This artifact might grow or shrink between major releases.
73+
We recommend selecting only the needed language(s) for a production deployment.
7374

7475
Additionally, your _module-info.java_ file should require `org.graalvm.polyglot` when using Java modules:
7576
```java
@@ -81,7 +82,7 @@ module com.mycompany.app {
8182
Whether your configuration can run with a Truffle runtime optimization depends on the GraalVM JDK you use.
8283
For further details, refer to the [Runtime Compilation section](#runtime-optimization-support).
8384

84-
We recommend configuring polyglot embeddings using modules and the module path whenever possible.
85+
We recommend configuring polyglot embeddings using modules and the module path whenever possible.
8586
Be aware that using `org.graalvm.polyglot` from the class path instead will enable access to unsafe APIs for all libraries on the class path.
8687
If the application is not yet modularized, hybrid use of the class path and module path is possible.
8788
For example:
@@ -124,17 +125,16 @@ You can use this application with other code examples to demonstrate more advanc
124125

125126
Polyglot applications let you take values from one programming language and use them with other languages.
126127

127-
Use the code example in this section with your polyglot application to show how the Polyglot API can return JavaScript, R, Ruby, or Python functions as Java values.
128+
Use the code example in this section with your polyglot application to show how the Polyglot API can return JavaScript, Python, or Ruby functions as Java values.
128129

129130
{%
130131
include snippet-tabs
131132
tab1type="java" tab1id="Function_JS" tab1name="JavaScript" tab1path="embed/function_js.java"
132-
tab2type="java" tab2id="Function_R" tab2name="R" tab2path="embed/function_R.java"
133+
tab2type="java" tab2id="Function_Python" tab2name="Python" tab2path="embed/function_python.java"
133134
tab3type="java" tab3id="Function_Ruby" tab3name="Ruby" tab3path="embed/function_ruby.java"
134-
tab4type="java" tab4id="Function_Python" tab4name="Python" tab4path="embed/function_python.java"
135135
%}
136136

137-
 In this code:
137+
In this code:
138138
- `Value function` is a Java value that refers to a function.
139139
- The `eval` call parses the script and returns the guest language function.
140140
- The first assertion checks that the value returned by the code snippet can be executed.
@@ -152,32 +152,21 @@ Use the code example in this section with your polyglot application to show how
152152
{%
153153
include snippet-tabs
154154
tab1type="java" tab1id="Access_JS" tab1name="JavaScript" tab1path="embed/access_js_from_java.java"
155-
tab2type="java" tab2id="Access_R" tab2name="R" tab2path="embed/access_R_from_java.java"
155+
tab2type="java" tab2id="Access_Python" tab2name="Python" tab2path="embed/access_python_from_java.java"
156156
tab3type="java" tab3id="Access_Ruby" tab3name="Ruby" tab3path="embed/access_ruby_from_java.java"
157-
tab4type="java" tab4id="Access_Python" tab4name="Python" tab4path="embed/access_python_from_java.java"
158157
%}
159158

160-
 In this code:
161-
- `Value result` is an Object that contains three members: a number named `id`,
162-
a string named `text`, and an array named `arr`.
163-
- The first assertion verifies that the return value can contain members, which
164-
indicates that the value is an object-like structure.
165-
- The `id` variable is initialized by reading the member with the name `id` from
166-
the resulting object. The result is then converted to a Java `int`
167-
using `asInt()`.
159+
In this code:
160+
- `Value result` is an Object that contains three members: a number named `id`, a string named `text`, and an array named `arr`.
161+
- The first assertion verifies that the return value can contain members, which indicates that the value is an object-like structure.
162+
- The `id` variable is initialized by reading the member with the name `id` from the resulting object. The result is then converted to a Java `int` using `asInt()`.
168163
- The next assert verifies that result has a value of `42`.
169-
- The `text` variable is initialized using the value of the member `text`,
170-
which is also converted to a Java `String` using `asString()`.
171-
- The following assertion verifies the result value is equal to the
172-
Java `String` `"42"`.
164+
- The `text` variable is initialized using the value of the member `text`, which is also converted to a Java `String` using `asString()`.
165+
- The following assertion verifies the result value is equal to the Java `String` `"42"`.
173166
- Next the `arr` member that holds an array is read.
174-
- Arrays return `true` for `hasArrayElements`. R array instances can have
175-
members and array elements at the same time.
176-
- The next assertion verifies that the size of the array equals three. The
177-
Polyglot API supports big arrays, so the array length is of type `long`.
178-
- Finally we verify that the array element at index `1` equals `42`. Array
179-
indexing with polyglot values is always zero-based, even for languages such as
180-
R where indices start with one.
167+
- Arrays return `true` for `hasArrayElements`.
168+
- The next assertion verifies that the size of the array equals three. The Polyglot API supports big arrays, so the array length is of type `long`.
169+
- Finally we verify that the array element at index `1` equals `42`. Array indexing with polyglot values is always zero-based, even for languages where indices start with one.
181170
182171
## Access Java from Guest Languages
183172
@@ -193,12 +182,11 @@ Use the code example in this section with your polyglot application to show how
193182
{%
194183
include snippet-tabs
195184
tab1type="java" tab1id="Access_Java_from_JS" tab1name="JavaScript" tab1path="embed/access_java_from_js.java"
196-
tab2type="java" tab2id="Access_Java_from_R" tab2name="R" tab2path="embed/access_java_from_R.java"
185+
tab4type="java" tab2id="Access_Java_from_Python" tab2name="Python" tab2path="embed/access_java_from_python.java"
197186
tab3type="java" tab3id="Access_Java_from_Ruby" tab3name="Ruby" tab3path="embed/access_java_from_ruby.java"
198-
tab4type="java" tab4id="Access_Java_from_Python" tab4name="Python" tab4path="embed/access_java_from_python.java"
199187
%}
200188
201-
 In this code:
189+
In this code:
202190
- The Java class `MyClass` has four public fields `id`, `text`, `arr`, and
203191
`ret42`. The fields are initialized with `42`, `"42"`, `new int[]{1, 42, 3}`, and
204192
lambda `() -> 42` that always returns an `int` value of `42`.
@@ -215,8 +203,7 @@ to the number `42` and the string `'42'`.
215203
to the number `42`. Whether arrays are accessed using 0-based or 1-based indices
216204
depends on the guest language. Independently of the language, the Java array
217205
stored in the `arr` field is always accessed using translated 0-based indices. For
218-
example, in the R language, arrays are 1-based so the second array element is
219-
accessible using index `2`. In the JavaScript and Ruby languages, the second
206+
example, in the JavaScript and Ruby languages, the second
220207
array element is at index `1`. In all language examples, the Java array is read
221208
from using the same index `1`.
222209
- The last line invokes the Java lambda that is contained in the field `ret42`
@@ -233,12 +220,11 @@ Use the code example in this section with your polyglot application to show how
233220
{%
234221
include snippet-tabs
235222
tab1type="java" tab1id="Lookup_Java_from_JS" tab1name="JavaScript" tab1path="embed/lookup_java_from_js.java"
236-
tab2type="java" tab2id="Lookup_Java_from_R" tab2name="R" tab2path="embed/lookup_java_from_R.java"
223+
tab2type="java" tab2id="Lookup_Java_from_Python" tab2name="Python" tab2path="embed/lookup_java_from_python.java"
237224
tab3type="java" tab3id="Lookup_Java_from_Ruby" tab3name="Ruby" tab3path="embed/lookup_java_from_ruby.java"
238-
tab4type="java" tab4id="Lookup_Java_from_Python" tab4name="Python" tab4path="embed/lookup_java_from_python.java"
239225
%}
240226
241-
 In this code:
227+
In this code:
242228
- A new context is created with all access enabled (`allowAllAccess(true)`).
243229
- A guest language script is evaluated.
244230
- The script looks up the Java type `java.math.BigDecimal` and stores it in a variable named `BigDecimal`.
@@ -261,12 +247,11 @@ Use the code example in this section with your polyglot application to see how y
261247
{%
262248
include snippet-tabs
263249
tab1type="java" tab1id="Proxy_JS" tab1name="JavaScript" tab1path="embed/proxy_js.java"
264-
tab2type="java" tab2id="Proxy_R" tab2name="R" tab2path="embed/proxy_R.java"
250+
tab2type="java" tab2id="Proxy_Python" tab2name="Python" tab2path="embed/proxy_python.java"
265251
tab3type="java" tab3id="Proxy_Ruby" tab3name="Ruby" tab3path="embed/proxy_ruby.java"
266-
tab4type="java" tab4id="Proxy_Python" tab4name="Python" tab4path="embed/proxy_python.java"
267252
%}
268253
269-
 In this code:
254+
In this code:
270255
- The Java class `ComputedArray` implements the proxy interface `ProxyArray` so
271256
that guest languages treat instances of the Java class-like arrays.
272257
- `ComputedArray` array overrides the method `get` and computes the value
@@ -279,7 +264,7 @@ an `UnsupportedOperationException` in the implementation of `set`.
279264
- The guest language script imports the `arr` symbol, which returns the
280265
exported proxy.
281266
- The second element and the `1000000000`th element is accessed, summed up, and
282-
then returned. Note that array indices from 1-based languages such as R are
267+
then returned. Note that array indices from 1-based languages are
283268
converted to 0-based indices for proxy arrays.
284269
- The result of the language script is returned as a long value and verified.
285270
@@ -295,15 +280,15 @@ These restrictions can be lifted entirely by setting `allowAllAccess` to `true`.
295280
### Controlling Access to Host Functions
296281
297282
It might be desirable to limit the access of guest applications to the host.
298-
For example, if a Java method is exposed that calls `System.exit` then the guest application will be able to exit the host process.
283+
For example, if a Java method is exposed that calls `System.exit`, then the guest application will be able to exit the host process.
299284
In order to avoid accidentally exposed methods, no host access is allowed by default and every public method or field needs to be annotated with `@HostAccess.Export` explicitly.
300285
301286
{%
302287
include snippet-tabs
303288
tab1type="java" tab1id="ExplicitHostAccess_js" tab1name="JavaScript" tab1path="embed/explicit_access_java_from_js.java"
304289
%}
305290
306-
 In this code:
291+
In this code:
307292
- The class `Employee` is declared with a field `name` of type `String`. Access to the `getName` method is explicitly allowed by annotating the method with `@HostAccess.Export`.
308293
- The `Services` class exposes two methods, `createEmployee` and `exitVM`. The `createEmployee` method takes the name of the employee as an argument and creates a new `Employee` instance. The `createEmployee` method is annotated with `@HostAccess.Export` and therefore accessible to the guest application. The `exitVM` method is not explicitly exported and therefore not accessible.
309294
- The `main` method first creates a new polyglot context in the default configuration, disallowing host access except for methods annotated with `@HostAccess.Export`.
@@ -708,9 +693,8 @@ For example, a dependency on isolated JavaScript can be configured by adding a M
708693
```
709694
710695
Starting from the Polyglot API version 24.1.0, the polyglot engine supports polyglot isolates for individual platforms.
711-
To download a polyglot isolate for a specific platform, append the operating system and
712-
CPU architecture classifiers to the polyglot isolate Maven `artifactId`. For example,
713-
to configure a dependency on isolated Python for Linux amd64, add the following Maven dependencies:
696+
To download a polyglot isolate for a specific platform, append the operating system and CPU architecture classifiers to the polyglot isolate Maven `artifactId`.
697+
For example, to configure a dependency on isolated Python for Linux amd64, add the following Maven dependencies:
714698
715699
```xml
716700
<dependency>
@@ -734,9 +718,7 @@ Supported platform classifiers are:
734718
* `darwin-aarch64`
735719
* `windows-amd64`
736720
737-
For a complete Maven POM file that adds the polyglot isolate Native Image dependency for the current platform,
738-
refer to the [Polyglot Embedding Demonstration](https://github.com/graalvm/polyglot-embedding-demo) on GitHub.
739-
721+
For a complete Maven POM file that adds the polyglot isolate Native Image dependency for the current platform, refer to the [Polyglot Embedding Demonstration](https://github.com/graalvm/polyglot-embedding-demo) on GitHub.
740722
741723
To enable isolate usage with the Polyglot API, the `--engine.SpawnIsolate=true` option must be passed to `Engine` or `Context` when constructed.
742724
The option `engine.SpawnIsolate` may not be available if used on any JDK other than Oracle GraalVM.
@@ -834,7 +816,7 @@ In Linux environments that support Memory Protection Keys, the `--engine.MemoryP
834816
If an engine is created with this option, a dedicated protection key will be allocated for the isolated engine's heap.
835817
GraalVM only enables access to the engine's heap when executing code of the Polyglot Isolate.
836818
837-
## Embed Guest Languages in Java
819+
## Embed a Guest Language in Java
838820
839821
The GraalVM Polyglot API can be used from within a guest language using Java interoperability.
840822
This can be useful if a script needs to run isolated from the parent context.
@@ -911,7 +893,7 @@ for (;;) {
911893
912894
## Step Through with Execution Listeners
913895
914-
The GraalVM Polyglot API allows users to instrument the execution of guest languages through [ExecutionListener class](http://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/management/ExecutionListener.html).
896+
The GraalVM Polyglot API allows users to instrument the execution of guest languages through the [ExecutionListener class](http://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/management/ExecutionListener.html).
915897
For example, it lets you attach an execution listener that is invoked for every statement of the guest language program.
916898
Execution listeners are designed as simple API for polyglot embedders and may become handy in, for example, single-stepping through the program.
917899

0 commit comments

Comments
 (0)