From 74fae96d46f8c845c5105948847193575e633e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Thu, 22 Mar 2018 17:36:15 +0100 Subject: [PATCH 01/18] SetPlugin: fix incorrect composition --- .../src/org/coreasm/engine/plugins/set/SetPlugin.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java index 009a179e..df5bfc06 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java @@ -835,13 +835,16 @@ private Update aggregateLocationForComposition(Location l, PluginCompositionAPI // value should be a set if (value instanceof SetElement) { Set resultSet = new HashSet(((SetElement)value).enumerate()); + Set removeFromSet = new HashSet(); for (Element e: resultSet) { Update removeUpdate = new Update(l, e, SETREMOVE_ACTION, (Element)null, null); - if (!uMset2.contains(removeUpdate)) - resultSet.add(e); + if (uMset2.contains(removeUpdate)) + removeFromSet.add(e); } + + resultSet.removeAll(removeFromSet); for (Update u: uMset2) { if (u.action.equals(SETADD_ACTION)) From 1facc8bedc452a250ac2d7ae4154057fc4c08c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sat, 14 Apr 2018 00:01:14 +0200 Subject: [PATCH 02/18] transport cause --- .../src/org/coreasm/engine/interpreter/InterpreterImp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java index 84e36f57..369a0829 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java +++ b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java @@ -390,7 +390,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { pos.setNode(l, null, storage.getValue(l)); } catch (InvalidLocationException e) { throw new EngineError("Location is invalid in 'interpretExpressions()'." + - "This cannot happen!"); + "This cannot happen!", e); } } else // if this 'x' is not defined before... @@ -426,7 +426,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { pos.setNode(l, null, storage.getValue(l)); } catch (InvalidLocationException e) { throw new EngineError("Location is invalid in 'interpretExpressions()'." + - "This cannot happen!"); + "This cannot happen!", e); } } else From 32d1a9c02b08dc0c0ee64d3b2e941b6e05a0f898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Fri, 23 Mar 2018 13:02:25 +0100 Subject: [PATCH 03/18] fix wrong error message (it was always null) --- .../src/org/coreasm/engine/absstorage/HashStorage.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java index ca1bb38b..22831c2c 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java @@ -232,15 +232,12 @@ public synchronized void fireUpdateSet(Set updateSet) throws InvalidLoca } public Element getChosenProgram(Element agent) { - Element p = null; - Element s = null; - try { - p = getValue(new Location(PROGRAM_FUNCTION_NAME, ElementList.create(agent))); + Element p = getValue(new Location(PROGRAM_FUNCTION_NAME, ElementList.create(agent))); if (p instanceof RuleElement) return p; else { - capi.error("Value of program(" + s + ") is not a Rule element."); + capi.error("Value of program(" + agent + ") is not a Rule element."); return Element.UNDEF; } } catch (InvalidLocationException e) { From e6540d8695c50a864956cc8e9600dec4b44d7a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Tue, 22 Aug 2017 08:32:48 +0200 Subject: [PATCH 04/18] SignaturePlugin: include note in message if update was not successful In case of `extend U with x do R` the value `x` will not be a member of `U` (as the UpdateSet wasn't consistent `x` wasn't added to `U`). Therefore any writes to a function with a signature `.. * U * .. -> ..` or `.. -> U` will report `x` not being a member of `U`, although there is nothing wrong with such an update. --- .../org/coreasm/engine/plugins/signature/SignaturePlugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java index 2b385c2b..6ccd4ebe 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java @@ -610,6 +610,7 @@ else if (typeCheckingMode == CheckMode.WARN) { "The " + Tools.getIth(i+1) + " argument in update '" + updateToString(u) + "' is not a member of " + domName + " and does not match the signature of " + "function '" + u.loc.name + ": " + func.getSignature() + "'." + + (!isUpdateSuccessful && domain instanceof UniverseElement ? " The update was not successful so it might not be added to the universe." : "") + getContextInfo(u); /* @@ -652,6 +653,7 @@ else if (typeCheckingMode == CheckMode.WARN) { "The value of update '" + updateToString(u) + "' is not a member of " + rangeName + " and does not match the signature of " + "function '" + u.loc.name + ": " + func.getSignature() + "'." + + (!isUpdateSuccessful && range instanceof UniverseElement ? " The update was not successful so it might not be added to the universe." : "") + getContextInfo(u); /* "There is an update for function '" + u.loc.name + From 58ca4b117ac004b7fa8f942d679a0f4b5b67b641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 1 Apr 2018 14:59:12 +0200 Subject: [PATCH 05/18] add @Override --- .../engine/absstorage/AbstractStorage.java | 2 +- .../engine/absstorage/HashStorage.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java index 8dce06f0..db93a3a4 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java @@ -173,7 +173,7 @@ public interface AbstractStorage extends State { * This method should only be called when there is a state in the stack. * * @param u the update multiset - * @see #pushState() + * @see #pushState(String pluginName) */ public void apply(Set u); diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java index 22831c2c..b6584571 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java @@ -140,7 +140,8 @@ private Stack getUpdateStackPluginNames() { private boolean isStateStacked() { return !getUpdateStack().isEmpty(); } - + + @Override public void initAbstractStorage() { clearState(); @@ -217,7 +218,8 @@ private void loadVocabularyExtender(VocabularyExtender ve) throws NameConflictEx addRule(name, veRules.get(name)); } } - + + @Override public synchronized void fireUpdateSet(Set updateSet) throws InvalidLocationException { // Cannot fire updates while state stack is not empty. // Doing this check will allow us to bypass calling setValue(...) @@ -231,6 +233,7 @@ public synchronized void fireUpdateSet(Set updateSet) throws InvalidLoca monitoredCache.clear(); } + @Override public Element getChosenProgram(Element agent) { try { Element p = getValue(new Location(PROGRAM_FUNCTION_NAME, ElementList.create(agent))); @@ -336,6 +339,7 @@ private Element getStackedValue(Location loc) { return null; } + @Override public void aggregateUpdates() { logger.debug("Aggregating updates."); UpdateMultiset updateInsts = capi.getScheduler().getUpdateInstructions(); @@ -356,6 +360,7 @@ public void aggregateUpdates() { /** * @see AbstractStorage#compose(UpdateMultiset, UpdateMultiset) */ + @Override public UpdateMultiset compose(UpdateMultiset updateSet1, UpdateMultiset updateSet2) { // instantiate engine composition API, and set update multiset CompositionAPIImp compAPI = new CompositionAPIImp(); @@ -376,6 +381,7 @@ public UpdateMultiset compose(UpdateMultiset updateSet1, UpdateMultiset updateSe /** * @see AbstractStorage#performAggregation(UpdateMultiset) */ + @Override public Set performAggregation(UpdateMultiset updateInsts) { // instantiate engine aggregation API, and set update multiset AggregationAPIImp aggAPI = new AggregationAPIImp(); @@ -402,7 +408,8 @@ public Set performAggregation(UpdateMultiset updateInsts) { // get resultant updates from agg API return aggAPI.getResultantUpdates(); } - + + @Override public synchronized boolean isConsistent(Collection updateSet) { Collection uSet = updateSet; lastInconsistentUpdates = null; @@ -427,6 +434,7 @@ public synchronized boolean isConsistent(Collection updateSet) { return true; } + @Override public Element getNewElement() { return new Element(); } @@ -478,8 +486,9 @@ public void popState(String pluginName) { * This method should only be called when there is a state in the stack. * * @param updates the update multiset - * @see #pushState() + * @see #pushState(String pluginName) */ + @Override public synchronized void apply(Set updates) { if (isStateStacked()) { Stack> updateStack = getUpdateStack(); @@ -538,6 +547,7 @@ public Set getLocations() { * Return true if the given name is the name * of a function in the state. */ + @Override public boolean isFunctionName(String token) { return getFunction(token) != null; } @@ -546,6 +556,7 @@ public boolean isFunctionName(String token) { * Return true if the given name is the name * of a function in the state. */ + @Override public boolean isUniverseName(String token) { return getUniverse(token) != null; } @@ -554,10 +565,12 @@ public boolean isUniverseName(String token) { * Return true if the given name is the name * of a rule in the state. */ + @Override public boolean isRuleName(String token) { return getRule(token) != null; } + @Override public synchronized void clearState() { state = new HashState(); /* @@ -581,6 +594,7 @@ public String toString() { return state.toString(); } + @Override public Set getLastInconsistentUpdate() { return lastInconsistentUpdates; } From a237ae279409c00e21a75bb4a568b759cd4da4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 1 Apr 2018 15:25:47 +0200 Subject: [PATCH 06/18] HashStorage: cleanup dead code.. .. add @Override, remove unnecessary casts, and re-order methods in HashState to match the State interface and HashStorage --- .../engine/absstorage/HashStorage.java | 142 +++++++----------- .../org/coreasm/engine/absstorage/State.java | 30 ---- 2 files changed, 53 insertions(+), 119 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java index b6584571..858e7dd9 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java @@ -250,23 +250,6 @@ public Element getChosenProgram(Element agent) { } } -// /** -// * @see org.coreasm.engine.absstorage.AbstractStorage#getState() -// */ -// public State getState() { -// return this; -// } -// -// /** -// * @see org.coreasm.engine.absstorage.AbstractStorage#setState(org.coreasm.engine.absstorage.State) -// */ -// public void setState(State newState) { -// if (!stateStacked) -// this.state = newState; -// else -// throw new EngineError("Cannot set state when the state stack is not empty."); -// } -// public Element getValue(Location l) throws InvalidLocationException { Element e = null; FunctionElement f = this.getFunction(l.name); @@ -366,9 +349,9 @@ public UpdateMultiset compose(UpdateMultiset updateSet1, UpdateMultiset updateSe CompositionAPIImp compAPI = new CompositionAPIImp(); compAPI.setUpdateInstructions(updateSet1, updateSet2); - for (Aggregator p: aggregatorPlugins) + for (Aggregator p : aggregatorPlugins) // synchronized (p) { - ((Aggregator)p).compose(compAPI); + p.compose(compAPI); // } // if (compAPI.isConsistent() == false) @@ -388,10 +371,10 @@ public Set performAggregation(UpdateMultiset updateInsts) { aggAPI.setUpdateInstructions(updateInsts); // for each plugin - for (Aggregator p: aggregatorPlugins) - ((Aggregator)p).aggregateUpdates(aggAPI); + for (Aggregator p : aggregatorPlugins) + p.aggregateUpdates(aggAPI); - if (aggAPI.isConsistent() == false) { + if (!aggAPI.isConsistent()) { String msg = "Inconsistent aggregated results."; if (aggAPI.getFailedInstructions().size() > 0) { @@ -573,17 +556,6 @@ public boolean isRuleName(String token) { @Override public synchronized void clearState() { state = new HashState(); - /* - * The following universe and functions are moved to Kernel - try { - state.addFunction(SELF_FUNCTION_NAME, new MapFunction(Element.UNDEF)); - state.addFunction(PROGRAM_FUNCTION_NAME, new MapFunction(Element.UNDEF)); - state.addUniverse(AGENTS_UNIVERSE_NAME, new UniverseElement()); - } catch (NameConflictException e) { - // This should not happen! - throw new EngineError(e); - } - /**/ } public String getFunctionName(FunctionElement function) { @@ -734,10 +706,17 @@ public HashState() { functionElements.setValue(FUNCTION_ELEMENT_FUNCTION_NAME, functionElements); } + @Override public Map getUniverses() { return universeElements.getTableClone(); } + @Override + public AbstractUniverse getUniverse(String name) { + return universeElements.getValue(name); + } + + @Override public synchronized void addUniverse(String name, AbstractUniverse universe) throws NameConflictException { if (universe == null) throw new NullPointerException(); @@ -746,10 +725,36 @@ public synchronized void addUniverse(String name, AbstractUniverse universe) thr universeElements.setValue(name, universe); } + @Override public Map getFunctions() { return functionElements.getTableClone(); } + @Override + public FunctionElement getFunction(String name) { + FunctionElement res = functionElements.getValue(name); + if (res == null) + res = universeElements.getValue(name); + return res; + } + + /* (non-Javadoc) + * @see org.coreasm.engine.absstorage.State#getFunctionName(org.coreasm.engine.absstorage.FunctionElement) + */ + @Override + public String getFunctionName(FunctionElement function) { + for (Entry f: functionElements.table.entrySet()) { + if (f.getValue().equals(function)) + return f.getKey(); + } + for (Entry u : universeElements.table.entrySet()) { + if (u.getValue().equals(function)) + return u.getKey(); + } + return null; + } + + @Override public synchronized void addFunction(String name, FunctionElement function) throws NameConflictException { if (function instanceof AbstractUniverse) addUniverse(name, (AbstractUniverse)function); @@ -760,10 +765,17 @@ public synchronized void addFunction(String name, FunctionElement function) thro functionElements.setValue(name, function); } + @Override public Map getRules() { return ruleElements.getTableClone(); } + @Override + public RuleElement getRule(String name) { + return ruleElements.getValue(name); + } + + @Override public synchronized void addRule(String name, RuleElement rule) throws NameConflictException { if (rule == null) throw new NullPointerException(); @@ -772,6 +784,7 @@ public synchronized void addRule(String name, RuleElement rule) throws NameConfl ruleElements.setValue(name, rule); } + @Override public Set getLocations() { HashSet locations = new HashSet(); Map funcs = getFunctions(); @@ -781,6 +794,7 @@ public Set getLocations() { return locations; } + @Override public Element getValue(Location loc) throws InvalidLocationException { if (nameExists(loc.name)) { Element id; @@ -819,6 +833,7 @@ public Element getValue(Location loc) throws InvalidLocationException { * @throws InvalidLocationException if the location is not modifiable. * @see State#setValue(Location, Element) */ + @Override public synchronized void setValue(Location l, Element v) throws InvalidLocationException { if (!nameExists(l.name)) { FunctionElement f = new MapFunction(Element.UNDEF); @@ -847,30 +862,6 @@ public synchronized void setValue(Location l, Element v) throws InvalidLocationE throw new InvalidLocationException(l + " is not a valid location."); } - /* - public synchronized void setValue(Location l, Element v) throws InvalidLocationException { - if (nameExists(l.name)) { - Element id; - try { - id = getIdentifier(l.name); - } catch (IdentifierNotFoundException e) { - throw new InvalidLocationException(e); - } - if (id instanceof FunctionElement && ((FunctionElement)id).isModifiable()) - try { - ((FunctionElement) id).setValue(l.args, v); - } catch (UnmodifiableFunctionException e) { - throw new InvalidLocationException(e); - } - else - throw new InvalidLocationException("Not a valid location."); - } else { - FunctionElement f = new MapFunction(Element.UNDEF); - addFunction(id, f); - throw new InvalidLocationException("There is no such function in the state."); - } - } - */ /** * Returns the rule/function/universe in the state @@ -881,7 +872,7 @@ public synchronized void setValue(Location l, Element v) throws InvalidLocationE * @throws IdentifierNotFoundException if there * is no such rule/function/universe in the state */ - public Element getIdentifier(String name) + private Element getIdentifier(String name) throws IdentifierNotFoundException { Element id = null; id = (Element)universeElements.getValue(name); @@ -912,21 +903,6 @@ private boolean nameExists(String name) { || ruleElements.containsName(name); } - public FunctionElement getFunction(String name) { - FunctionElement res = functionElements.getValue(name); - if (res == null) - res = universeElements.getValue(name); - return res; - } - - public AbstractUniverse getUniverse(String name) { - return universeElements.getValue(name); - } - - public RuleElement getRule(String name) { - return ruleElements.getValue(name); - } - public String toString() { StringWriter strWriter = new StringWriter(); PrintWriter writer = new PrintWriter(strWriter); @@ -988,21 +964,6 @@ public String toString() { return strWriter.toString(); } - /* (non-Javadoc) - * @see org.coreasm.engine.absstorage.State#getFunctionName(org.coreasm.engine.absstorage.FunctionElement) - */ - public String getFunctionName(FunctionElement function) { - for (Entry f: functionElements.table.entrySet()) { - if (f.getValue().equals(function)) - return f.getKey(); - } - for (Entry u : universeElements.table.entrySet()) { - if (u.getValue().equals(function)) - return u.getKey(); - } - return null; - } - /* * Cut the string to a specific length */ @@ -1017,15 +978,18 @@ private String reformatFunctionValue(String value) { return result.toString(); } - + + @Override public FunctionElement getFunctionElementFunction() { return functionElements; } + @Override public FunctionElement getRuleElementFunction() { return ruleElements; } + @Override public FunctionElement getUniverseElementFunction() { return universeElements; } diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java index 66919d06..f2e00e3d 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java @@ -52,16 +52,6 @@ public interface State { public void addUniverse(String name, AbstractUniverse universe) throws NameConflictException; -// /** -// * Removes a universe from the state. -// * -// * @param universe universe to be removed -// * @throws IdentifierNotFoundException if no such universe -// * is found in the state -// */ -// public void removeUniverse(UniverseElement universe) -// throws IdentifierNotFoundException; - /** * Set of all the functions (including universes) defined in the state. * @@ -95,16 +85,6 @@ public void addUniverse(String name, AbstractUniverse universe) */ public void addFunction(String name, FunctionElement function) throws NameConflictException; - -// /** -// * Removes a function from the state. -// * -// * @param function function to be removed. -// * @throws IdentifierNotFoundException if there is no -// * such function in the state. -// */ -// public void removeFunction(FunctionElement function) -// throws IdentifierNotFoundException; /** * Set of all the rules defined in @@ -133,16 +113,6 @@ public void addFunction(String name, FunctionElement function) public void addRule(String name, RuleElement rule) throws NameConflictException; -// /** -// * Removes a rule from the state. -// * -// * @param rule the rule to be removed -// * @throws IdentifierNotFoundException if there is no -// * such rule in the state. -// */ -// public void removeRule(RuleElement rule) -// throws IdentifierNotFoundException; - /** * Set of all the defined locations in the state * that have a value other than undef From 3a86a0e09d5266f99b63d6365809db9fcade6988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Thu, 19 Apr 2018 16:36:34 +0200 Subject: [PATCH 07/18] InterpreterImp.interpretExpressions: avoid expensive call to storage.getFunctionName The name is already known iff the FunctionElement is loaded from the storage --- .../engine/interpreter/InterpreterImp.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java index 369a0829..ef3c1108 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java +++ b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java @@ -362,7 +362,6 @@ else if (token.equals(Kernel.KW_SELF)) private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { final AbstractStorage storage = capi.getStorage(); final String gClass = pos.getGrammarClass(); - String x = pos.getToken(); // If the current node is a function/rule term if (gClass.equals(ASTNode.FUNCTION_RULE_CLASS)) { @@ -372,7 +371,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { // If the current node is of the form 'x' or 'x(...)' if (frNode.hasName()) { - x = frNode.getName(); + final String x = frNode.getName(); // If the current node is of the form 'x' with no arguments if (!frNode.hasArguments()) { @@ -383,7 +382,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { else { // If this 'x' refers to a function in the state... final FunctionElement f = storage.getFunction(x); -// if (storage.isFunctionName(x)) { + if (f != null) { final Location l = new Location(x, ElementList.NO_ARGUMENT, f.isModifiable()); try { @@ -399,11 +398,19 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { } } } else { // if current node is 'x(...)' (with arguments) - + // If this 'x' refers to a function in the state... FunctionElement f = storage.getFunction(x); - if (getEnv(x) instanceof FunctionElement) - f = (FunctionElement)getEnv(x); + String name = null; + if (f != null) { + name = x; + } + + if (getEnv(x) instanceof FunctionElement) { + f = (FunctionElement) getEnv(x); + name = null; + } + if (f == null) { try { Element value = storage.getValue(new Location(x, ElementList.NO_ARGUMENT)); @@ -412,6 +419,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { } catch (InvalidLocationException e) { } } + if (f != null) { final List args = frNode.getArguments(); // look for the parameter that needs to be evaluated @@ -419,7 +427,6 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { if (toBeEvaluated == null) { // if all nodes are evaluated... final ElementList vList = EngineTools.getValueList(args); - final String name = storage.getFunctionName(f); if (name != null) { final Location l = new Location(name, vList, f.isModifiable()); try { From 5ea706a7ca862190ca156d12d23680e576da4178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Mon, 26 Mar 2018 14:39:47 +0200 Subject: [PATCH 08/18] Plugin: calculate getName via getClass().getSimpleName() only once --- org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java index 077eda44..35d99a96 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java @@ -51,9 +51,10 @@ public Plugin() { super(); } + private final String pluginName = this.getClass().getSimpleName(); @Override public final String getName() { - return this.getClass().getSimpleName(); + return pluginName; } @Override From 0fff91be2f6b2edf235eb5a93889895b6ce2503c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sat, 3 Jun 2017 14:00:55 +0200 Subject: [PATCH 09/18] delete _.java --- org.coreasm.engine/src/org/coreasm/engine/parser/_.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 org.coreasm.engine/src/org/coreasm/engine/parser/_.java diff --git a/org.coreasm.engine/src/org/coreasm/engine/parser/_.java b/org.coreasm.engine/src/org/coreasm/engine/parser/_.java deleted file mode 100644 index 398f35c0..00000000 --- a/org.coreasm.engine/src/org/coreasm/engine/parser/_.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.coreasm.engine.parser; - -public class _ { - -} From 5d30990c35b865f0696e55f463b3272bb68641fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Thu, 19 Apr 2018 09:57:45 +0200 Subject: [PATCH 10/18] storage.getFunctionName: move search for key into NameTableFunction --- .../engine/absstorage/HashStorage.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java index 858e7dd9..71129f57 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java @@ -620,9 +620,17 @@ public void setValue(List args, Element value) throws Unmodif public E getValue(String name) { return table.get(name); } + + public String getKey(E value) { + for (Entry f: table.entrySet()) { + if (f.getValue().equals(value)) + return f.getKey(); + } + return null; + } public Collection values() { - return (Collection)table.values(); + return table.values(); } public Collection getNames() { @@ -743,15 +751,11 @@ public FunctionElement getFunction(String name) { */ @Override public String getFunctionName(FunctionElement function) { - for (Entry f: functionElements.table.entrySet()) { - if (f.getValue().equals(function)) - return f.getKey(); - } - for (Entry u : universeElements.table.entrySet()) { - if (u.getValue().equals(function)) - return u.getKey(); + String result = functionElements.getKey(function); + if (result == null && function instanceof AbstractUniverse) { + result = universeElements.getKey((AbstractUniverse)function); } - return null; + return result; } @Override From 4d42bac6d688c2d89ed761f54cda64c1c380dac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Fri, 20 Apr 2018 11:21:00 +0200 Subject: [PATCH 11/18] KernelExtensionsPlugin: avoid expensive call to getFunctionName in common case --- .../kernelextensions/KernelExtensionsPlugin.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java index 8a71a96d..ba03a105 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java @@ -243,10 +243,18 @@ public ASTNode interpret(Interpreter interpreter, ASTNode pos) if (toBeEvaluated == null) { // if all nodes are evaluated... ElementList vList = EngineTools.getValueList(args); - - //look for the function in the state - Element value = null; - String fname = capi.getStorage().getFunctionName(fe); + + Element value; + String fname; + if (fe.getFClass().equals(FunctionElement.FunctionClass.fcStatic)) { + // value can be returned directly + fname = null; + } + else { + // look for the function in the state + fname = capi.getStorage().getFunctionName(fe); + } + Location loc = null; if (fname != null) { try { From 8f81a5189475d090a1cad1cf91ac8100dd61aa65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Fri, 14 Dec 2018 15:19:46 +0100 Subject: [PATCH 12/18] OptionsPlugin: avoid reassignment --- .../src/org/coreasm/engine/plugins/options/OptionsPlugin.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java index ff70e169..bbc282dd 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java @@ -252,11 +252,10 @@ public void fireOnModeTransition(EngineMode source, EngineMode target) { private void loadProperties() { Set definedOptions = capi.getSpec().getOptions(); ASTNode currentNode = capi.getParser().getRootNode().getFirst(); - OptionNode optionNode = null; while (currentNode != null) { if (currentNode instanceof OptionNode) { - optionNode = (OptionNode)currentNode; + OptionNode optionNode = (OptionNode)currentNode; if (definedOptions.contains(optionNode.getOptionName())) { try { String pluginName = optionNode.getOptionName().substring(0, optionNode.getOptionName().indexOf('.')); From 2e19890c85f9e49268d49598bc78973fd105462b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Tue, 18 Dec 2018 08:48:03 +0100 Subject: [PATCH 13/18] ModularityPlugin: codestyle --- .../plugins/modularity/ModularityPlugin.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java index ec3b8b8d..3447233a 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java @@ -63,8 +63,8 @@ public class ModularityPlugin extends Plugin implements ParserPlugin, public static final String PLUGIN_NAME = ModularityPlugin.class.getSimpleName(); - private final String[] keywords = {"CoreModule", "include"}; - private final String[] operators = {}; + private static final String[] keywords = {"CoreModule", "include"}; + private static final String[] operators = {}; private Map parsers = null; @@ -230,21 +230,18 @@ public Node map(Object[] from) { private ArrayList injectModules(List lines, String relativePath) { // CHANGE: Includes inside included specifications will be looked up relative to the including specification now ArrayList newSpec = new ArrayList(); - String useRegex; - Pattern usePattern; - Matcher useMatcher; // compile pattern to find "include " directives using regular expression - useRegex = "^[\\s]*[i][n][c][l][u][d][e][\\s]+"; - usePattern = Pattern.compile(useRegex); + String useRegex = "^[\\s]*[i][n][c][l][u][d][e][\\s]+"; + Pattern usePattern = Pattern.compile(useRegex); - for (SpecLine line: lines) { + for (SpecLine line : lines) { // get an "include" directive matcher object for the line - useMatcher = usePattern.matcher(line.text); + Matcher useMatcher = usePattern.matcher(line.text); // if match found if (useMatcher.find()) { // are there inner include files? - + // get the include file name and load the file String fileName = useMatcher.replaceFirst("").trim(); // remove potential quotation marks @@ -252,28 +249,29 @@ private ArrayList injectModules(List lines, String relativeP fileName = fileName.substring(1, fileName.length()-1); // CHANGE: make sure that filenames have the same format to ensure that equal paths match, not only equal include statements try { - fileName = (new File(relativePath + File.separator + fileName)).getCanonicalPath(); + fileName = (new File(relativePath, fileName)).getCanonicalPath(); } catch (IOException e) { + logger.info("ModularityPlugin: unable to get canonical path for module '" + fileName + "'. Check " + line.fileName + ":" + line.line + "."); } + if (loadedModules.contains(fileName)) - logger.info( - "ModularityPlugin: Skipping module '" + fileName + "' since it's already loaded."); - else + logger.info("ModularityPlugin: Skipping module '" + fileName + "' since it's already loaded."); + else try { loadedModules.add(fileName); - logger.info( - "ModularityPlugin: Loading module '" + fileName + "'."); + logger.info("ModularityPlugin: Loading module '" + fileName + "'."); + List newLines = injectModules(Specification.loadSpec(fileName), fileName.substring(0, fileName.lastIndexOf(File.separator))); - for (SpecLine newLine: newLines) - newSpec.add(newLine); + newSpec.addAll(newLines); } catch (IOException e) { - capi.error("Modularity plugin cannot load module file '" + capi.error("Modularity plugin cannot load module file '" + fileName + "'. The error is:" + Tools.getEOL() + e.getMessage() + Tools.getEOL() + "Check " + line.fileName + ":" + line.line + "."); } - } else + } else { newSpec.add(line); + } } return newSpec; } From 4904b8f7d35f1f2dc205ba72bd7ee19e03298161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Tue, 18 Dec 2018 09:46:06 +0100 Subject: [PATCH 14/18] Specification: codestyle --- .../src/org/coreasm/engine/Specification.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/org.coreasm.engine/src/org/coreasm/engine/Specification.java b/org.coreasm.engine/src/org/coreasm/engine/Specification.java index 3666e54f..ba3f046c 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/Specification.java +++ b/org.coreasm.engine/src/org/coreasm/engine/Specification.java @@ -323,11 +323,12 @@ public Set getPluginNames() { * @see #loadSpec(String) */ public static ArrayList loadSpec(Specification mainSpec, String fileName) throws IOException { - String specRoot = ""; - if (mainSpec != null) - specRoot = mainSpec.getFileDir() + File.separator; - - return loadSpec(specRoot + fileName); + if (mainSpec == null) { + return loadSpec(new File(fileName)); + } + else { + return loadSpec(new File(mainSpec.getFileDir(), fileName)); + } } /** From fe9e93b471c7ddba2293d9e52a3f013cc6d96902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Thu, 10 Jan 2019 17:36:30 +0100 Subject: [PATCH 15/18] pom.xml: skipTests via property --- org.coreasm.engine/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.coreasm.engine/pom.xml b/org.coreasm.engine/pom.xml index 049f7cbd..42b936fc 100644 --- a/org.coreasm.engine/pom.xml +++ b/org.coreasm.engine/pom.xml @@ -11,6 +11,10 @@ ../org.coreasm.parent + + true + + @@ -60,7 +64,7 @@ maven-surefire-plugin 2.16 - true + ${skipTests} false 0 From 317ce1badf10fef7ad16639820cdca6b0d17b5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 18 Mar 2018 13:12:29 +0100 Subject: [PATCH 16/18] update maven-compiler-plugin - and useIncrementalCompilation=false --- org.coreasm.engine/pom.xml | 2 +- org.coreasm.parent/pom.xml | 3 ++- org.coreasm.ui.carma/pom.xml | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/org.coreasm.engine/pom.xml b/org.coreasm.engine/pom.xml index 42b936fc..d5f7da56 100644 --- a/org.coreasm.engine/pom.xml +++ b/org.coreasm.engine/pom.xml @@ -107,7 +107,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.0 + 3.8.0 1.7 1.7 diff --git a/org.coreasm.parent/pom.xml b/org.coreasm.parent/pom.xml index 68a81859..f70c2c45 100644 --- a/org.coreasm.parent/pom.xml +++ b/org.coreasm.parent/pom.xml @@ -98,10 +98,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.0 1.7 1.7 + false diff --git a/org.coreasm.ui.carma/pom.xml b/org.coreasm.ui.carma/pom.xml index 360c722b..cec3b479 100644 --- a/org.coreasm.ui.carma/pom.xml +++ b/org.coreasm.ui.carma/pom.xml @@ -60,9 +60,11 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.0 1.7 1.7 + false @@ -87,4 +89,4 @@ org.coreasm - \ No newline at end of file + From c150b044b7b97f896086405072c6376caea1b5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 3 Feb 2019 18:33:24 +0100 Subject: [PATCH 17/18] update to junit 4.12 --- org.coreasm.engine/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.coreasm.engine/pom.xml b/org.coreasm.engine/pom.xml index d5f7da56..00d989c2 100644 --- a/org.coreasm.engine/pom.xml +++ b/org.coreasm.engine/pom.xml @@ -142,7 +142,7 @@ junit junit - 4.8.2 + 4.12 org.coreasm From ec7e304803163fedf678204439ff71dbff59b4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Sun, 3 Feb 2019 18:34:53 +0100 Subject: [PATCH 18/18] add Set4_compose.casm test Tests all cases of SetPlugin.compose, especially aggregateLocationForComposition and eradicateConflictingIncrementalUpdates --- .../plugin-tests/set/Set4_compose.casm | 190 ++++++++++++++++++ .../engine/test/plugins/set/Set4_compose.java | 25 +++ 2 files changed, 215 insertions(+) create mode 100644 org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm create mode 100644 org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java diff --git a/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm b/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm new file mode 100644 index 00000000..23504059 --- /dev/null +++ b/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm @@ -0,0 +1,190 @@ +CoreASM Set4_compose + +use Standard + +init Start + +/* + * @minsteps 1 + * @maxsteps 1 + */ + +function foo : -> SET +rule Start = seqblock + Case1a() + + Case1b() + + Case2() + + Case3a_add() + + Case3a_remove() + + Case3a_mixed() + + Case3b_i() + + Case3b_ii_1() + + Case3b_ii_2() + + Case3b_iii() +endseqblock + + +rule Case1a = { + seq + foo := {} + next { + seq + add 1 to foo + next + skip + } + next { + // @require "Case1a: {1}" + print "Case1a: " + foo + } +} + +rule Case1b = { + seq + foo := {} + next { + seq + skip + next + add 1 to foo + } + next { + // @require "Case1b: {1}" + print "Case1b: " + foo + } +} + +rule Case2 = { + seq + foo := {3} + next { + seq + skip + next { + remove 1 from foo + foo := {2} + add 2 to foo + } + } + next { + // @require "Case2: {2}" + print "Case2: " + foo + } +} + +rule Case3a_add = { + seq + foo := {} + next { + seq + foo := {1} + next + add 2 to foo + } + next { + // @require "Case3a_add: {1, 2}" + print "Case3a_add: " + foo + } +} + +rule Case3a_remove = { + seq + foo := {} + next { + seq + foo := {1, 2} + next + remove 2 from foo + } + next { + // @require "Case3a_remove: {1}" + print "Case3a_remove: " + foo + } +} + + +rule Case3a_mixed = { + seq + foo := {} + next { + seq + foo := {1, 2} + next { + remove 2 from foo + add 3 to foo + } + } + next { + // @require "Case3a_mixed: {1, 3}" + print "Case3a_mixed: " + foo + } +} + +rule Case3b_i = { + seq + foo := {3} + next { + seq + add 1 to foo + next + remove 1 from foo + } + next { + // @require "Case3b_i: {3}" + print "Case3b_i: " + foo + } +} + +rule Case3b_ii_1 = { + seq + foo := {3} + next { + seq + remove 3 from foo + next + add 3 to foo + } + next { + // @require "Case3b_ii_1: {3}" + print "Case3b_ii_1: " + foo + } +} + +rule Case3b_ii_2 = { + seq + foo := {3} + next { + seq + remove 1 from foo + next + add 1 to foo + } + next { + // @require "Case3b_ii_2: {1, 3}" + print "Case3b_ii_2: " + foo + } +} + +rule Case3b_iii = { + seq + foo := {3} + next { + seq + add 1 to foo + next + remove 2 from foo + } + next { + // @require "Case3b_iii: {1, 3}" + print "Case3b_iii: " + foo + } +} \ No newline at end of file diff --git a/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java b/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java new file mode 100644 index 00000000..5159f938 --- /dev/null +++ b/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java @@ -0,0 +1,25 @@ +package org.coreasm.engine.test.plugins.set; + +import org.coreasm.engine.test.TestAllCasm; +import org.junit.BeforeClass; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.LinkedList; + +public class Set4_compose extends TestAllCasm { + + @BeforeClass + public static void onlyOnce() { + URL url = Set4_compose.class.getClassLoader().getResource("."); + + try { + testFiles = new LinkedList(); + getTestFile(testFiles, new File(url.toURI()).getParentFile(), Set4_compose.class); + } + catch (URISyntaxException e) { + e.printStackTrace(); + } + } +}