Skip to content

adding syntax support for externally defined distributions and functions #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/hurricane-new.blog
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ distinct DamageLevel Severe, Mild;
obs Damage(First) = Severe;

query First;
query Damage(A);
query Damage(B);
//query Damage(A);
//query Damage(B);
27 changes: 8 additions & 19 deletions src/main/java/blog/absyn/DistributionDec.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,24 @@
import blog.symbol.Symbol;

/**
* Distribution declaration
*
* @author leili
* @date Apr 22, 2012
*
*/
public class DistributionDec extends Dec {
public Symbol name;
public Symbol classname;
public ExprList params;
public class DistributionDec extends FunctionDec {

public DistributionDec(int p, Symbol n, Symbol cn, ExprList a) {
this(0, p, n, cn, a);
public DistributionDec(int p, Symbol n, FieldList a, Ty r) {
this(0, p, n, a, r);
}

public DistributionDec(int line, int col, Symbol n, Symbol cn, ExprList a) {
super(line, col);
name = n;
classname = cn;
params = a;
public DistributionDec(int line, int pos, Symbol n, FieldList a, Ty r) {
super(line, pos, n, a, r, null);
}

@Override
public void printTree(Printer pr, int d) {
pr.indent(d);
pr.sayln("DistributionDec(");
pr.indent(d + 1);
pr.say(name.toString());
pr.sayln(",");
pr.say(classname.toString());
pr.sayln(",");
params.printTree(pr, d + 1);
// to be removed
}
}
38 changes: 38 additions & 0 deletions src/main/java/blog/model/BuiltInFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public class BuiltInFunctions {
*/
public static FixedFunction MINUS;

/**
* The unary function on integers <code>x<code> that returns - x.
*/
public static FixedFunction UMINUS;

/**
* The function on integers <code>x<code>, <code>y</code> that returns x * y.
*/
Expand Down Expand Up @@ -229,6 +234,11 @@ public class BuiltInFunctions {
*/
public static FixedFunction RMINUS;

/**
* The unary function on a real <code>x<code> that returns - x.
*/
public static FixedFunction RUMINUS;

/**
* The function on reals <code>x<code>, <code>y</code> that returns x * y.
*/
Expand Down Expand Up @@ -736,6 +746,34 @@ public Object getValue(List args) {
MOD = new FixedFunction(MOD_NAME, argTypes, retType, modInterp);
addFunction(MOD);

// Add non-random functions from integer to integer
argTypes.clear();
argTypes.add(BuiltInTypes.INTEGER);
retType = BuiltInTypes.INTEGER;

FunctionInterp uminusInterp = new AbstractFunctionInterp() {
public Object getValue(List args) {
Number arg1 = (Number) args.get(0);
return new Integer(-arg1.intValue());
}
};
UMINUS = new FixedFunction(MINUS_NAME, argTypes, retType, uminusInterp);
addFunction(UMINUS);

// Add non-random functions from integer to integer
argTypes.clear();
argTypes.add(BuiltInTypes.REAL);
retType = BuiltInTypes.REAL;

FunctionInterp ruminusInterp = new AbstractFunctionInterp() {
public Object getValue(List args) {
Number arg1 = (Number) args.get(0);
return new Double(-arg1.intValue());
}
};
RUMINUS = new FixedFunction(MINUS_NAME, argTypes, retType, ruminusInterp);
addFunction(RUMINUS);

// Add non-random functions from (real x real) to real
argTypes.clear();
argTypes.add(BuiltInTypes.REAL);
Expand Down
Loading