diff --git a/build.gradle b/build.gradle index 88bad52..18a1e3e 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ java { } configure([tasks.compileJava]) { - options.release = 11 + options.release = 8 } jar { diff --git a/src/main/java/me/topchetoeu/jscript/runtime/Engine.java b/src/main/java/me/topchetoeu/jscript/runtime/Engine.java index f9e80f9..244b4b9 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/Engine.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/Engine.java @@ -1,12 +1,11 @@ package me.topchetoeu.jscript.runtime; +import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; import java.util.concurrent.PriorityBlockingQueue; import java.util.function.Supplier; -import me.topchetoeu.jscript.runtime.exceptions.InterruptException; - public final class Engine implements EventLoop { private static class Task implements Comparable> { public final Supplier runnable; @@ -41,10 +40,10 @@ public final class Engine implements EventLoop { try { ((Task)task).notifier.complete(task.runnable.get()); } - catch (InterruptException e) { throw e; } + catch (CancellationException e) { throw e; } catch (RuntimeException e) { task.notifier.completeExceptionally(e); } } - catch (InterruptedException | InterruptException e) { + catch (InterruptedException | CancellationException e) { for (var msg : tasks) msg.notifier.cancel(false); break; } diff --git a/src/main/java/me/topchetoeu/jscript/runtime/Frame.java b/src/main/java/me/topchetoeu/jscript/runtime/Frame.java index 2725a7d..c6fb662 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/Frame.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/Frame.java @@ -2,13 +2,13 @@ package me.topchetoeu.jscript.runtime; import java.util.Arrays; import java.util.Stack; +import java.util.concurrent.CancellationException; import me.topchetoeu.jscript.common.Instruction; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Key; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; -import me.topchetoeu.jscript.runtime.exceptions.InterruptException; import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.functions.CodeFunction; import me.topchetoeu.jscript.runtime.values.objects.ArrayLikeValue; @@ -176,7 +176,7 @@ public final class Frame { if (returnValue == null && error == null) { try { - if (Thread.interrupted()) throw new InterruptException(); + if (Thread.interrupted()) throw new CancellationException(); if (instr == null) { if (stackPtr > 0) returnValue = stack[stackPtr - 1]; @@ -383,9 +383,9 @@ public final class Frame { public ObjectValue getValStackScope() { return new ArrayLikeValue() { @Override public Value get(int i) { return stack[i]; } - @Override public void set(int i, Value val) { stack[i] = val; } + @Override public boolean set(Environment env, int i, Value val) { return false; } @Override public boolean has(int i) { return i >= 0 && i < size(); } - @Override public void remove(int i) { } + @Override public boolean remove(int i) { return false; } @Override public int size() { return stackPtr; } @Override public boolean setSize(int val) { return false; } diff --git a/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java b/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java index daa0d1b..f4b81a8 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java @@ -1,8 +1,8 @@ package me.topchetoeu.jscript.runtime; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -13,7 +13,6 @@ import me.topchetoeu.jscript.common.json.JSON; import me.topchetoeu.jscript.common.parsing.Filename; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; -import me.topchetoeu.jscript.runtime.exceptions.InterruptException; import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; import me.topchetoeu.jscript.runtime.values.Member.FieldMember; import me.topchetoeu.jscript.runtime.values.Member.PropertyMember; @@ -45,13 +44,13 @@ public class SimpleRepl { for (var arg : args) { try { - var file = Path.of(arg); - var raw = Files.readString(file); + var file = new File(arg); + var raw = Reading.streamToString(new FileInputStream(file)); try { var res = engine.pushMsg( false, environment, - Filename.fromFile(file.toFile()), raw, null + Filename.fromFile(file), raw, null ).get(); System.err.println(res.toReadable(environment)); @@ -195,7 +194,7 @@ public class SimpleRepl { var val = new ArrayValue(); for (var key : args.get(0).getOwnMembers(env, args.get(1).toBoolean())) { - val.set(val.size(), new StringValue(key)); + val.set(args.env, val.size(), new StringValue(key)); } return val; @@ -375,7 +374,7 @@ public class SimpleRepl { glob.defineOwnMember(null, "exit", new NativeFunction("exit", args -> { Thread.currentThread().interrupt(); - throw new InterruptException(); + throw new CancellationException(); })); glob.defineOwnMember(null, "print", new NativeFunction("print", args -> { for (var el : args.args) { diff --git a/src/main/java/me/topchetoeu/jscript/runtime/exceptions/InterruptException.java b/src/main/java/me/topchetoeu/jscript/runtime/exceptions/InterruptException.java deleted file mode 100644 index ac7dc0e..0000000 --- a/src/main/java/me/topchetoeu/jscript/runtime/exceptions/InterruptException.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.topchetoeu.jscript.runtime.exceptions; - -public class InterruptException extends RuntimeException { - public InterruptException() { } - public InterruptException(Throwable e) { - super(e); - } -}