commit 52c4df14ae59ae0189c3c763f055781493b77325 Author: Fedor Isakov Date: Fri Nov 20 14:55:48 2015 +0100 Initial import. Kotlin libs 1.0 Beta 1103. Imported abstract constraints API from the Logic project diff --git a/reactor/.gitignore b/reactor/.gitignore new file mode 100644 index 00000000..d2c8ad3b --- /dev/null +++ b/reactor/.gitignore @@ -0,0 +1,2 @@ +.idea/workspace.xml +out diff --git a/reactor/.idea/.name b/reactor/.idea/.name new file mode 100644 index 00000000..6e1d9535 --- /dev/null +++ b/reactor/.idea/.name @@ -0,0 +1 @@ +Reactor \ No newline at end of file diff --git a/reactor/.idea/compiler.xml b/reactor/.idea/compiler.xml new file mode 100644 index 00000000..a8523149 --- /dev/null +++ b/reactor/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/reactor/.idea/copyright/profiles_settings.xml b/reactor/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/reactor/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/reactor/.idea/encodings.xml b/reactor/.idea/encodings.xml new file mode 100644 index 00000000..97626ba4 --- /dev/null +++ b/reactor/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/reactor/.idea/libraries/KotlinJavaRuntime.xml b/reactor/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 00000000..207fc74d --- /dev/null +++ b/reactor/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/reactor/.idea/libraries/lib.xml b/reactor/.idea/libraries/lib.xml new file mode 100644 index 00000000..72e3b2ee --- /dev/null +++ b/reactor/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/reactor/.idea/misc.xml b/reactor/.idea/misc.xml new file mode 100644 index 00000000..e0057c2d --- /dev/null +++ b/reactor/.idea/misc.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reactor/.idea/modules.xml b/reactor/.idea/modules.xml new file mode 100644 index 00000000..04f1eb91 --- /dev/null +++ b/reactor/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/reactor/.idea/vcs.xml b/reactor/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/reactor/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/reactor/API/API.iml b/reactor/API/API.iml new file mode 100644 index 00000000..c90834f2 --- /dev/null +++ b/reactor/API/API.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AbstractConstraint.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AbstractConstraint.java new file mode 100644 index 00000000..129bc8b2 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AbstractConstraint.java @@ -0,0 +1,90 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +/** + * Abstract superclass for use in implementations of Constraint and AutoConstraint. + */ +public abstract class AbstractConstraint implements ComputingItem { + + public AbstractConstraint(String symbol, int arity) { + this.symbol = symbol; + this.arity = arity; + } + + public String name() { + return symbol; + } + + public String symbol() { + return symbol; + } + + public int arity() { + return arity; + } + + public Instructible handler(ComputingSession session) { + return session.handler(asConstraint()); + } + + public Queryable solver(ComputingSession session) { + return session.solver(asAutoConstraint()); + } + + public abstract Class solverClass(); + + public Class handlerClass() { + return solverClass(); + } + + @Override + public String toString() { + return symbol; + } + + public Constraint asConstraint() { + return (Constraint) this; + } + + public AutoConstraint asAutoConstraint() { + return (AutoConstraint) this; + } + + protected void registerHandler(ComputingSession session, Instructible instructible) { + session.registerHandler(asConstraint(), instructible); + } + + protected void registerSolver(ComputingSession session, Queryable queryable) { + session.registerSolver(asAutoConstraint(), queryable); + session.registerHandler(asConstraint(), queryable); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || this.getClass() != o.getClass()) { + return false; + } + + AbstractConstraint that = (AbstractConstraint) o; + if ((symbol != null ? !(((Object) symbol).equals(that.symbol)) : that.symbol != null)) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + ((symbol != null ? String.valueOf(symbol).hashCode() : 37)); + return result; + } + + private String symbol; + private int arity; +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AutoConstraint.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AutoConstraint.java new file mode 100644 index 00000000..c6870020 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/AutoConstraint.java @@ -0,0 +1,19 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +/** + * A constraint that is provided by a solver. Can be either told or asked for a constraint. + */ +public interface AutoConstraint extends Constraint { + + public Queryable solver(ComputingSession session); + + public Class solverClass(); + + public String symbol(); + + public int arity(); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingItem.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingItem.java new file mode 100644 index 00000000..89a017b7 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingItem.java @@ -0,0 +1,15 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +/** + * A basic item of computation. + */ +public interface ComputingItem { + + public void init(ComputingSession session, ComputingTracer tracer); + + public void dispose(ComputingSession session); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingSession.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingSession.java new file mode 100644 index 00000000..40f1da6c --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingSession.java @@ -0,0 +1,111 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +/** + * Computing session is used to provide an interface for handlers and solvers working together in a single session. + */ +public class ComputingSession { + + public static ComputingSession.Builder with(ComputingItem... cst) { + return new ComputingSession.Builder(cst); + } + + private ComputingSession(ComputingTracer tracer) { + this.tracer = tracer; + } + + public static class Builder { + + private Builder(ComputingItem... item) { + items.addAll(Arrays.asList(item)); + } + + public ComputingSession.Builder withTracer(ComputingTracer tracer) { + this.tracer = tracer; + return this; + } + + public ComputingSession newSession() { + ComputingSession session = new ComputingSession(tracer); + for (ComputingItem ci : items) { + ci.init(session, tracer); + } + return session; + } + + private List items = new ArrayList(); + private ComputingTracer tracer; + } + + + public boolean ask(AutoConstraint autoConstraint, Object... arg) { + Queryable solver = solver(autoConstraint); + if (solver == null) { + throw new IllegalStateException("no solver for '" + autoConstraint.symbol() + "'"); + } + + return solver.ask(autoConstraint, arg); + } + + public void tell(Constraint constraint, Object... arg) { + Instructible handler = handler(constraint); + if (handler == null) { + throw new IllegalStateException("no handler for '" + constraint.name() + "'"); + } + + handler.tell(constraint, arg); + } + + public Constraint lookupConstraint(Class clazz) { + for (Map.Entry e : handlers.entrySet()) { + if (clazz.isAssignableFrom(e.getKey().handlerClass())) { + return e.getKey(); + } + } + return null; + } + + public AutoConstraint lookupAutoConstraint(Class clazz) { + for (Map.Entry e : solvers.entrySet()) { + if (clazz.isAssignableFrom(e.getKey().solverClass())) { + return e.getKey(); + } + } + return null; + } + + protected Instructible handler(Constraint constraint) { + if (!(handlers.containsKey(constraint))) { + throw new IllegalStateException("no handler: " + constraint); + } + return handlers.get(constraint); + } + + protected Queryable solver(AutoConstraint constraint) { + if (!(solvers.containsKey(constraint))) { + throw new IllegalStateException("no handler: " + constraint); + } + return solvers.get(constraint); + } + + protected void registerHandler(Constraint constraint, Instructible instructible) { + handlers.put(constraint, instructible); + } + + protected void registerSolver(AutoConstraint constraint, Queryable queryable) { + solvers.put(constraint, queryable); + } + + private Map handlers = new HashMap(); + + private Map solvers = new HashMap(); + + private final ComputingTracer tracer; +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingTracer.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingTracer.java new file mode 100644 index 00000000..f2ab9f53 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/ComputingTracer.java @@ -0,0 +1,12 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +public interface ComputingTracer { + + public void askSuccess(AutoConstraint autoConstraint, Object... args); + + public void askFailure(AutoConstraint autoConstraint, Object... args); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Constraint.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Constraint.java new file mode 100644 index 00000000..0ee21b24 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Constraint.java @@ -0,0 +1,19 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +/** + * A constraint provided by a handler. Can only be told. + */ +public interface Constraint extends ComputingItem { + + public Instructible handler(ComputingSession session); + + public Class handlerClass(); + + public String name(); + + public int arity(); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Instructible.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Instructible.java new file mode 100644 index 00000000..c780b5a9 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Instructible.java @@ -0,0 +1,10 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +public interface Instructible { + + public void tell(Constraint constraint, Object... arg); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Queryable.java b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Queryable.java new file mode 100644 index 00000000..aab792be --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/Queryable.java @@ -0,0 +1,10 @@ +package jetbrains.mps.logic.reactor.constraint; + +/*Generated by MPS */ + + +public interface Queryable extends Instructible { + + public boolean ask(AutoConstraint autoConstraint, Object... arg); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/constraint/trace.info b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/trace.info new file mode 100644 index 00000000..1a2d5b3f --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/constraint/trace.info @@ -0,0 +1,331 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogical.java b/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogical.java new file mode 100644 index 00000000..72bc7e5c --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogical.java @@ -0,0 +1,20 @@ +package jetbrains.mps.logic.reactor.logical; + +/*Generated by MPS */ + + +public interface ILogical { + + public String name(); + + public String name(NamingContext namingContext); + + public ILogical findRoot(); + + public T value(); + + public boolean isBound(); + + public boolean isWildcard(); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogicalVar.java b/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogicalVar.java new file mode 100644 index 00000000..907e48d4 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/logical/ILogicalVar.java @@ -0,0 +1,10 @@ +package jetbrains.mps.logic.reactor.logical; + +/*Generated by MPS */ + + +public interface ILogicalVar { + + public ILogical logical(); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/logical/NamingContext.java b/reactor/API/src/jetbrains/mps/logic/reactor/logical/NamingContext.java new file mode 100644 index 00000000..906831b9 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/logical/NamingContext.java @@ -0,0 +1,33 @@ +package jetbrains.mps.logic.reactor.logical; + +/*Generated by MPS */ + +import java.util.Map; +import java.util.HashMap; +import java.util.IdentityHashMap; + +public class NamingContext { + + public String uniqueName(ILogical logical) { + if (!(cachedUnique.containsKey(logical))) { + cachedUnique.put(logical, makeUnique(logical.name())); + } + return cachedUnique.get(logical); + } + + private String makeUnique(String name) { + int c = getAndIncrementCounter(name); + return (c == 0 ? name : name + c); + } + + private int getAndIncrementCounter(String name) { + Integer c = (uniqueCounters.containsKey(name) ? uniqueCounters.get(name) : 0); + uniqueCounters.put(name, c + 1); + return c; + } + + private Map uniqueCounters = new HashMap(); + + private Map cachedUnique = new IdentityHashMap(); + +} diff --git a/reactor/API/src/jetbrains/mps/logic/reactor/logical/trace.info b/reactor/API/src/jetbrains/mps/logic/reactor/logical/trace.info new file mode 100644 index 00000000..e4b5c5a6 --- /dev/null +++ b/reactor/API/src/jetbrains/mps/logic/reactor/logical/trace.info @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/reactor/Reactor.iml b/reactor/Reactor.iml new file mode 100644 index 00000000..245d3429 --- /dev/null +++ b/reactor/Reactor.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/reactor/lib/kotlin-reflect.jar b/reactor/lib/kotlin-reflect.jar new file mode 100644 index 00000000..a02d0dfb Binary files /dev/null and b/reactor/lib/kotlin-reflect.jar differ diff --git a/reactor/lib/kotlin-runtime-sources.jar b/reactor/lib/kotlin-runtime-sources.jar new file mode 100644 index 00000000..c7855729 Binary files /dev/null and b/reactor/lib/kotlin-runtime-sources.jar differ diff --git a/reactor/lib/kotlin-runtime.jar b/reactor/lib/kotlin-runtime.jar new file mode 100644 index 00000000..2f6fff9d Binary files /dev/null and b/reactor/lib/kotlin-runtime.jar differ