This file contains hidden or 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
| logHolder <- java.type("org.graalvm.demos.springr.LogHolder") | |
| logHolder$log(dataHolder$value, data[90:100]) |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <polyglot.h> | |
| int main() { | |
| void *bigInteger = polyglot_java_type("java.math.BigInteger"); | |
| void *(*BigInteger_valueOf)(long) = polyglot_get_member(bigInteger, "valueOf"); | |
| void *bi = BigInteger_valueOf(2); | |
| void *result = polyglot_invoke(bi, "pow", 256); | |
| char buffer[100]; |
This file contains hidden or 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
| # shelajev at shrimp.local in /tmp | |
| → clang -c -O1 -emit-llvm -I$GRAALVM_HOME/jre/languages/llvm big-integer-demo.c | |
| # shelajev at shrimp.local in /tmp | |
| → lli --jvm big-integer-demo.bc | |
| 115792089237316195423570985008687907853269984665640564039457584007913129639936 |
This file contains hidden or 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
| library(lattice) | |
| mtcars$cars <- rownames(mtcars) | |
| print(barchart(cars~mpg, data=mtcars)) |
This file contains hidden or 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
| public class PolyglotTest { | |
| public static void main(String[] args) { | |
| System.out.println("Hello World from Java!"); | |
| org.graalvm.polyglot.Context context = | |
| org.graalvm.polyglot.Context.newBuilder().allowAllAccess(true).build(); | |
| context.eval("js", "print('Hello World from JavaScript!');"); | |
| // context.eval("python", "print('Hello World from Python!')"); |
This file contains hidden or 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
| public class PolyglotTest { | |
| public static void main(String[] args) { | |
| System.out.println("Hello World from Java!"); | |
| org.graalvm.polyglot.Context context = org.graalvm.polyglot.Context.newBuilder().allowAllAccess(true).build(); | |
| context.eval("js", "print('Hello World from JavaScript!');"); | |
| // context.eval("python", "print('Hello World from Python!')"); | |
| // context.eval("R", "print('Hello World from R!')"); |
This file contains hidden or 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
| const http = require("http"); | |
| var BigDecimal = Java.type('java.math.BigDecimal'); | |
| http.createServer(function (request, response) { | |
| response.writeHead(200, {"Content-Type": "text/html"}); | |
| response.end("Hello Graal.js! " + BigDecimal.valueOf(2).pow(100).toString() ); | |
| }).listen(8000, function( ) { | |
| console.log("Graal.js server running at http://127.0.0.1:8000/"); | |
| }); |
This file contains hidden or 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
| const http = require("http"); | |
| http.createServer(function (request, response) { | |
| response.writeHead(200, {"Content-Type": "text/html"}); | |
| response.end("Hello Graal.js! " + Polyglot.eval('R', 'runif(100)')[0] ); | |
| }).listen(8000, function( ) { | |
| console.log("Graal.js server running at http://127.0.0.1:8000/"); | |
| }); |
This file contains hidden or 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
| package org.sample; | |
| import java.util.Arrays; | |
| import org.openjdk.jmh.annotations.*; | |
| @State(Scope.Benchmark) | |
| public class Streams { | |
| private double[] values = new double[2000000]; | |
| @Benchmark | |
| public double mapReduce() { | |
| return Arrays.stream(values) | |
| .map(x -> x + 1) |
This file contains hidden or 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
| return Arrays.stream(values).parallel() | |
| .map(x -> x + 1) | |
| .map(x -> x * 2) | |
| .map(x -> x + 5) | |
| .reduce(0, Double::sum); |