X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Fchr%2FExampleStore.java;h=d4c102204fe95e50f6bfa126c1868301ce5f7065;hp=197fefe2fbc3ee4e54bd0cd2dd804adc374f3987;hb=fad36d463b75c3a9944d875fc627c3533f6da74d;hpb=3448b94a8e90047c88eb62a0542c1596acb701b8 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/chr/ExampleStore.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/chr/ExampleStore.java index 197fefe2f..d4c102204 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/chr/ExampleStore.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/chr/ExampleStore.java @@ -1,93 +1,80 @@ -package org.simantics.scl.compiler.internal.codegen.chr; - -import org.simantics.scl.runtime.chr.CHRHashIndex; -import org.simantics.scl.runtime.chr.Fact; -import org.simantics.scl.runtime.chr.FactActivationQueue; - -public class ExampleStore { - /* - * constraint ExampleFact Integer Integer where - * index(bf) - * - * => - * - * data Store // class Module$123 - * data ExampleFact // class Module$123/ExampleFact - * - * add :: Store -> ExampleFact -> () - * remove :: Store -> ExampleFact -> () - * get_bf :: Store -> Integer -> ExampleFact - * next_bf :: ExampleFact -> Maybe ExampleFact - * idOf :: ExampleFact -> Integer - * isAlive :: ExampleFact -> Boolean - */ - - CHRHashIndex ExampleFact_bfIndex = new CHRHashIndex() { - @Override - protected boolean keyEquals(Object a, Object b) { - return ((ExampleFact)a).c0 == ((ExampleFact)b).c0; - } - @Override - protected int keyHashCode(Object key) { - return ((ExampleFact)key).c0; - } - }; - - public FactActivationQueue queue = new FactActivationQueue(2); - - private ExampleFact ExampleFact_temp = new ExampleFact(); - - public ExampleFact getExampleFact_bf(int c0) { - ExampleFact_temp.c0 = c0; - return (ExampleFact)ExampleFact_bfIndex.getEqual(ExampleFact_temp); - } - - public static class ExampleFact implements Fact { - public int id; - public int c0; // key - public int c1; - public ExampleFact bfPrev; - public ExampleFact bfNext; - - public ExampleFact() { - } - - public ExampleFact(int c0, int c1) { - this.c0 = c0; - this.c1 = c1; - } - - public void add(ExampleStore store) { - bfNext = (ExampleFact)store.ExampleFact_bfIndex.addFreshAndReturnOld(this); - if(bfNext != null) - bfNext.bfPrev = this; - } - - public void remove(ExampleStore store) { - if(bfPrev == null) { - if(bfNext == null) - store.ExampleFact_bfIndex.removeKnownToExistKey(this); - else { - bfNext.bfPrev = null; - store.ExampleFact_bfIndex.replaceKnownToExistKey(this, bfNext); - } - } - else { - bfPrev.bfNext = bfNext; - if(bfNext != null) - bfNext.bfPrev = bfPrev; - } - } - - @Override - public int activate(Object context, int priority) { - return -1; - } - - @Override - public boolean isAlive() { - return id >= 0; - } - } - -} +package org.simantics.scl.compiler.internal.codegen.chr; + +import org.simantics.scl.runtime.chr.CHRFact; +import org.simantics.scl.runtime.chr.CHRHashIndex; +import org.simantics.scl.runtime.chr.CHRRuntimeRuleset; + +public class ExampleStore extends CHRRuntimeRuleset { + /* + * constraint ExampleFact Integer Integer where + * index(bf) + * + * => + * + * data Store // class Module$123 + * data ExampleFact // class Module$123/ExampleFact + * + * add :: Store -> ExampleFact -> () + * remove :: Store -> ExampleFact -> () + * get_bf :: Store -> Integer -> ExampleFact + * next_bf :: ExampleFact -> Maybe ExampleFact + * idOf :: ExampleFact -> Integer + * isAlive :: ExampleFact -> Boolean + */ + + CHRHashIndex ExampleFact_bfIndex = new CHRHashIndex() { + @Override + protected boolean keyEquals(Object a, Object b) { + return ((ExampleFact)a).c0 == ((ExampleFact)b).c0; + } + @Override + protected int keyHashCode(Object key) { + return ((ExampleFact)key).c0; + } + }; + + private ExampleFact ExampleFact_temp = new ExampleFact(); + + public ExampleFact getExampleFact_bf(int c0) { + ExampleFact_temp.c0 = c0; + return (ExampleFact)ExampleFact_bfIndex.getEqual(ExampleFact_temp); + } + + public static class ExampleFact extends CHRFact { + public int c0; // key + public int c1; + public ExampleFact bfPrev; + public ExampleFact bfNext; + + public ExampleFact() { + } + + public ExampleFact(int c0, int c1) { + this.c0 = c0; + this.c1 = c1; + } + + public void add(ExampleStore store) { + bfNext = (ExampleFact)store.ExampleFact_bfIndex.addFreshAndReturnOld(this); + if(bfNext != null) + bfNext.bfPrev = this; + } + + public void remove(ExampleStore store) { + if(bfPrev == null) { + if(bfNext == null) + store.ExampleFact_bfIndex.removeKnownToExistKey(this); + else { + bfNext.bfPrev = null; + store.ExampleFact_bfIndex.replaceKnownToExistKey(this, bfNext); + } + } + else { + bfPrev.bfNext = bfNext; + if(bfNext != null) + bfNext.bfPrev = bfPrev; + } + } + } + +}