Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM (WIP, broken) #434

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion storeys/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ dependencies {
api project(':api-jvm-impl')
api 'ch.vorburger.minecraft.osgi:api:1.0.0'
implementation 'ch.vorburger:fswatch:1.3.0'

implementation files('libs/graal-sdk.jar')
implementation files('libs/graaljs.jar')
implementation files('libs/tregex.jar')
implementation files('libs/truffle-api.jar')
implementation project(':example')
testImplementation project(':test-utils')
}
Binary file added storeys/libs/graal-sdk.jar
Binary file not shown.
Binary file added storeys/libs/graaljs.jar
Binary file not shown.
Binary file added storeys/libs/tregex.jar
Binary file not shown.
Binary file added storeys/libs/truffle-api.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
LOG.info("(Re-)loaded {}", path);
} catch (NoSuchFileException e) {
// Ignore (happens frequently for temporary files with Git)
} catch (jdk.nashorn.api.scripting.NashornException n) {
LOG.warn("Invalid JS: {}:{}:{} {}", path, n.getLineNumber(), n.getColumnNumber(), n.getMessage());
} catch (RuntimeException e) {
LOG.error("Failed to register due to an unknown cause {}", path, e);
}
Expand Down Expand Up @@ -93,7 +91,7 @@ private Script load(Path file) throws IOException, ScriptException {
final String result = template.replace("//SCRIPT", scriptFile);

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
ScriptEngine engine = manager.getEngineByName("graal.js");

return (Script) engine.eval(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class DynamicAction implements Action<Void> {
CompletableFuture<Void> future = new CompletableFuture<>();

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
ScriptEngine engine = manager.getEngineByName("graal.js");
engine.put("player", context.getCommandSource());

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ch.vorburger.minecraft.storeys
*
* Copyright (C) 2016 - 2018 Michael Vorburger.ch <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.vorburger.minecraft.storeys.tests;

import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.junit.Test;

public class GraalTest {

@Test public void testJsEngine() throws ScriptException {
List<ScriptEngineFactory> engines = (new ScriptEngineManager()).getEngineFactories();
for (ScriptEngineFactory f : engines) {
System.out.println(f.getLanguageName() + " " + f.getEngineName() + " " + f.getNames().toString());
}

final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("graal.js");
System.out.println(scriptEngine.eval("1+1"));
}
}