refactor: move function pushMsg signatures in EventLoop
This commit is contained in:
parent
47b4dd3c15
commit
b30f94de8f
@ -1,4 +1,4 @@
|
|||||||
project_group = me.topchetoeu
|
project_group = me.topchetoeu
|
||||||
project_name = jscript
|
project_name = jscript
|
||||||
project_version = 0.9.7-beta
|
project_version = 0.9.8-beta
|
||||||
main_class = me.topchetoeu.jscript.utils.JScriptRepl
|
main_class = me.topchetoeu.jscript.utils.JScriptRepl
|
||||||
|
@ -2,11 +2,9 @@ package me.topchetoeu.jscript.runtime;
|
|||||||
|
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.common.Filename;
|
|
||||||
import me.topchetoeu.jscript.common.ResultRunnable;
|
import me.topchetoeu.jscript.common.ResultRunnable;
|
||||||
import me.topchetoeu.jscript.common.events.DataNotifier;
|
import me.topchetoeu.jscript.common.events.DataNotifier;
|
||||||
import me.topchetoeu.jscript.runtime.exceptions.InterruptException;
|
import me.topchetoeu.jscript.runtime.exceptions.InterruptException;
|
||||||
import me.topchetoeu.jscript.runtime.values.FunctionValue;
|
|
||||||
|
|
||||||
public class Engine implements EventLoop {
|
public class Engine implements EventLoop {
|
||||||
private static class Task<T> implements Comparable<Task<?>> {
|
private static class Task<T> implements Comparable<Task<?>> {
|
||||||
@ -78,18 +76,6 @@ public class Engine implements EventLoop {
|
|||||||
return this.thread != null;
|
return this.thread != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataNotifier<Object> pushMsg(boolean micro, Environment env, FunctionValue func, Object thisArg, Object ...args) {
|
|
||||||
return pushMsg(() -> {
|
|
||||||
return func.call(new Context(env), thisArg, args);
|
|
||||||
}, micro);
|
|
||||||
}
|
|
||||||
public DataNotifier<Object> pushMsg(boolean micro, Environment env, Filename filename, String raw, Object thisArg, Object ...args) {
|
|
||||||
return pushMsg(() -> {
|
|
||||||
var ctx = new Context(env);
|
|
||||||
return ctx.compile(filename, raw).call(new Context(env), thisArg, args);
|
|
||||||
}, micro);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Engine() {
|
public Engine() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.topchetoeu.jscript.runtime;
|
package me.topchetoeu.jscript.runtime;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.common.Filename;
|
||||||
import me.topchetoeu.jscript.common.ResultRunnable;
|
import me.topchetoeu.jscript.common.ResultRunnable;
|
||||||
import me.topchetoeu.jscript.common.events.DataNotifier;
|
import me.topchetoeu.jscript.common.events.DataNotifier;
|
||||||
import me.topchetoeu.jscript.runtime.exceptions.EngineException;
|
import me.topchetoeu.jscript.runtime.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.runtime.values.FunctionValue;
|
||||||
|
|
||||||
public interface EventLoop {
|
public interface EventLoop {
|
||||||
public static final Key<EventLoop> KEY = new Key<>();
|
public static final Key<EventLoop> KEY = new Key<>();
|
||||||
@ -20,4 +22,16 @@ public interface EventLoop {
|
|||||||
public default DataNotifier<Void> pushMsg(Runnable runnable, boolean micro) {
|
public default DataNotifier<Void> pushMsg(Runnable runnable, boolean micro) {
|
||||||
return pushMsg(() -> { runnable.run(); return null; }, micro);
|
return pushMsg(() -> { runnable.run(); return null; }, micro);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public default DataNotifier<Object> pushMsg(boolean micro, Environment env, FunctionValue func, Object thisArg, Object ...args) {
|
||||||
|
return pushMsg(() -> {
|
||||||
|
return func.call(new Context(env), thisArg, args);
|
||||||
|
}, micro);
|
||||||
|
}
|
||||||
|
public default DataNotifier<Object> pushMsg(boolean micro, Environment env, Filename filename, String raw, Object thisArg, Object ...args) {
|
||||||
|
return pushMsg(() -> {
|
||||||
|
var ctx = new Context(env);
|
||||||
|
return ctx.compile(filename, raw).call(new Context(env), thisArg, args);
|
||||||
|
}, micro);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
package me.topchetoeu.jscript.runtime;
|
package me.topchetoeu.jscript.runtime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface Extensions {
|
public interface Extensions {
|
||||||
|
public static Extensions EMPTY = new Extensions() {
|
||||||
|
@Override public <T> void add(Key<T> key, T obj) { }
|
||||||
|
@Override public boolean remove(Key<?> key) { return false; }
|
||||||
|
|
||||||
|
@Override public <T> T get(Key<T> key) { return null; }
|
||||||
|
@Override public boolean has(Key<?> key) { return false; }
|
||||||
|
@Override public Iterable<Key<?>> keys() { return List.of(); }
|
||||||
|
};
|
||||||
|
|
||||||
<T> T get(Key<T> key);
|
<T> T get(Key<T> key);
|
||||||
<T> void add(Key<T> key, T obj);
|
<T> void add(Key<T> key, T obj);
|
||||||
Iterable<Key<?>> keys();
|
Iterable<Key<?>> keys();
|
||||||
@ -35,4 +46,9 @@ public interface Extensions {
|
|||||||
add((Key<Object>)key, (Object)source.get(key));
|
add((Key<Object>)key, (Object)source.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Extensions wrap(Extensions ext) {
|
||||||
|
if (ext == null) return EMPTY;
|
||||||
|
else return ext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user