Skip to content

Commit

Permalink
implemented fingerprints for rascal specific values
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Oct 31, 2023
1 parent 73f413c commit 7a1044e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
4 changes: 3 additions & 1 deletion src/org/rascalmpl/library/vis/Charts.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ data ChartType
data ChartOptions
= chartOptions(
bool responsive=true,
bool animations=false,
ChartPlugins plugins = chartPlugins()
);

Expand Down Expand Up @@ -395,13 +396,14 @@ A chart has a typical default layout that we can reuse for all kinds of chart ty
provides the template and immediately instantiates the client and the server to start displaying the chart
in a browser.
}
Response(Request) chartServer(ChartData theData, ChartType \type=\bar(), str title="Chart", ChartAutoColorMode colorMode=\data(), bool legend=false)
Response(Request) chartServer(ChartData theData, ChartType \type=\bar(), str title="Chart", ChartAutoColorMode colorMode=\data(), bool legend=false, bool animations=false)
= chartServer(
chart(
\type=\type,
\data=theData,
options=chartOptions(
responsive=true,
animations=animations,
plugins=chartPlugins(
legend=chartLegend(
position=top(),
Expand Down
5 changes: 5 additions & 0 deletions src/org/rascalmpl/tasks/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ public synchronized void expire(Object key) {
map.remove(k);
removed.add(k);
}

@Override
public int getMatchFingerprint() {
return hashCode();

Check warning on line 423 in src/org/rascalmpl/tasks/Transaction.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/tasks/Transaction.java#L423

Added line #L423 was not covered by tests
}
}

class Key {
Expand Down
46 changes: 14 additions & 32 deletions src/org/rascalmpl/values/RascalValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import io.usethesource.capsule.util.collection.AbstractSpecialisedImmutableMap;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IExternalValue;
import io.usethesource.vallang.IInteger;
import io.usethesource.vallang.IList;
import io.usethesource.vallang.IListWriter;
Expand Down Expand Up @@ -385,8 +384,16 @@ else if (constructor == Type_Reified || constructor.getAbstractDataType() == ADT

@Override
public IConstructor reifiedType(IConstructor symbol, IMap definitions) {
// This is where the "reified type contract" is implemented.
// A few inocuous lines of code that have a lot riding on them.

// Contract: The dynamic type of a `type(symbol, definitionsMap)` constructor instance
// is `type[what the symbol value represents]`.
// So here the symbol value is "unlifted" to the {@see Type} representation (by `symbolToType`).
// Therefore you can count on that, for example, `type(int(), ())` has type `type[int]`.
java.util.Map<Type,Type> bindings =
Collections.singletonMap(RascalValueFactory.TypeParam, tr.symbolToType(symbol, definitions));

return super.constructor(RascalValueFactory.Type_Reified.instantiate(bindings), symbol, definitions);
}

Expand Down Expand Up @@ -505,9 +512,9 @@ public ITree amb(ISet alternatives) {
* and {@link AbstractArgumentList} abstract classes.
*/

static class CharInt implements ITree, IExternalValue {
static class CharInt implements ITree {
final int ch;

@Override
public boolean isChar() {
return true;
Expand All @@ -526,11 +533,6 @@ public <E extends Throwable> ITree accept(TreeVisitor<E> v) throws E {
public CharInt(int ch) {
this.ch = ch;
}

@Override
public IConstructor encodeAsConstructor() {
return this;
}

@Override
public IValue get(int i) throws IndexOutOfBoundsException {
Expand Down Expand Up @@ -675,7 +677,7 @@ protected ITree wrap(ITree content, io.usethesource.capsule.Map.Immutable<String
}
}

private static class CharByte implements ITree, IExternalValue {
private static class CharByte implements ITree {
final byte ch;

public CharByte(byte ch) {
Expand All @@ -696,11 +698,6 @@ public INode setChildren(IValue[] childArray) {
public <E extends Throwable> ITree accept(TreeVisitor<E> v) throws E {
return (ITree) v.visitTreeChar(this);
}

@Override
public IConstructor encodeAsConstructor() {
return this;
}

@Override
public IValue get(int i) throws IndexOutOfBoundsException {
Expand Down Expand Up @@ -850,7 +847,7 @@ protected ITree wrap(ITree content, io.usethesource.capsule.Map.Immutable<String
}
}

private static class Cycle implements ITree, IExternalValue {
private static class Cycle implements ITree {
protected final IConstructor symbol;
protected final int cycleLength;

Expand All @@ -869,11 +866,6 @@ public <E extends Throwable> ITree accept(TreeVisitor<E> v) throws E {
return (ITree) v.visitTreeCycle(this);
}

@Override
public IConstructor encodeAsConstructor() {
return this;
}

@Override
public String getName() {
return Tree_Cycle.getName();
Expand Down Expand Up @@ -1034,7 +1026,7 @@ public IValue get(int i) throws IndexOutOfBoundsException {
}
}

private static class Amb implements ITree, IExternalValue {
private static class Amb implements ITree {
protected final ISet alternatives;

public Amb(ISet alts) {
Expand All @@ -1051,11 +1043,6 @@ public <E extends Throwable> ITree accept(TreeVisitor<E> v) throws E {
return (ITree) v.visitTreeAmb(this);
}

@Override
public IConstructor encodeAsConstructor() {
return this;
}

@Override
public String getName() {
return Tree_Amb.getName();
Expand Down Expand Up @@ -1410,7 +1397,7 @@ public IInteger getCharacter() {
}
}

private static abstract class AbstractAppl implements ITree, IExternalValue {
private static abstract class AbstractAppl implements ITree {
protected final IConstructor production;
protected final boolean isMatchIgnorable;
protected Type type = null;
Expand Down Expand Up @@ -1439,11 +1426,6 @@ public boolean isAppl() {
return true;
}

@Override
public IConstructor encodeAsConstructor() {
return this;
}

@Override
public String getName() {
return Tree_Appl.getName();
Expand Down
5 changes: 5 additions & 0 deletions src/org/rascalmpl/values/functions/IFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

public interface IFunction extends IExternalValue {

@Override
default int getMatchFingerprint() {
return 3154628 /* "func".hashCode() */ + 89 * getType().hashCode();

Check warning on line 27 in src/org/rascalmpl/values/functions/IFunction.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/values/functions/IFunction.java#L27

Added line #L27 was not covered by tests
}

/**
* Invokes the receiver function.
*
Expand Down
21 changes: 19 additions & 2 deletions src/org/rascalmpl/values/parsetrees/ITree.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
import org.rascalmpl.values.parsetrees.visitors.TreeVisitor;

import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IExternalValue;
import io.usethesource.vallang.IInteger;
import io.usethesource.vallang.IList;
import io.usethesource.vallang.INode;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.visitors.IValueVisitor;

public interface ITree extends IConstructor {
public interface ITree extends IConstructor, IExternalValue {

@Override
default IConstructor encodeAsConstructor() {
return this;

Check warning on line 18 in src/org/rascalmpl/values/parsetrees/ITree.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/values/parsetrees/ITree.java#L18

Added line #L18 was not covered by tests
}

@Override
default <T, E extends Throwable> T accept(IValueVisitor<T, E> v) throws E {
return v.visitExternal(this);

Check warning on line 23 in src/org/rascalmpl/values/parsetrees/ITree.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/values/parsetrees/ITree.java#L23

Added line #L23 was not covered by tests
}

@Override
default int getMatchFingerprint() {
return 3568542 /* "tree".hashCode() */ + 41 * getProduction().hashCode();

Check warning on line 28 in src/org/rascalmpl/values/parsetrees/ITree.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/values/parsetrees/ITree.java#L28

Added line #L28 was not covered by tests
}

default boolean isAppl() {
return false;
}
Expand Down Expand Up @@ -55,4 +72,4 @@ default INode setChildren(IValue[] childArray) {

return result;
}
}
}

0 comments on commit 7a1044e

Please sign in to comment.