Skip to content

Commit

Permalink
further program reductions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Feb 11, 2025
1 parent 6f89473 commit 865651c
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 7 deletions.
Binary file modified AssertStatement.class
Binary file not shown.
Binary file modified AssignStatement.class
Binary file not shown.
Binary file modified BreakStatement.class
Binary file not shown.
Binary file modified CaseStatement.class
Binary file not shown.
Binary file modified CatchStatement.class
Binary file not shown.
Binary file modified ConditionalStatement.class
Binary file not shown.
Binary file modified ContinueStatement.class
Binary file not shown.
Binary file modified CreationStatement.class
Binary file not shown.
Binary file modified ErrorStatement.class
Binary file not shown.
Binary file modified FinalStatement.class
Binary file not shown.
Binary file modified IfCase.class
Binary file not shown.
Binary file modified IfStatement.class
Binary file not shown.
Binary file modified ImplicitInvocationStatement.class
Binary file not shown.
Binary file modified InvocationStatement.class
Binary file not shown.
Binary file modified ReturnStatement.class
Binary file not shown.
Binary file modified SequenceStatement.class
Binary file not shown.
Binary file modified Statement.class
Binary file not shown.
80 changes: 77 additions & 3 deletions Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,71 @@ else if (rhs instanceof BinaryExpression &&
new BinaryExpression("->pow", expr, sze));
return new AssignStatement(lhs, newrhs);
}
else if ((lhs + " & " + var).equals("" + rhs))
{ // lhs := lhs & loopRange->forAll(self)

Type elemt = rng.getElementType();
BasicExpression selfvar =
BasicExpression.newVariableBasicExpression(
"self",elemt);
Expression prd =
new BinaryExpression("->forAll", rng, selfvar);
Expression newrhs =
new BinaryExpression("&", lhs, prd);
return new AssignStatement(lhs, newrhs);
}
else if (rhs instanceof BinaryExpression &&
((BinaryExpression) rhs).getOperator().equals("&") &&
(((BinaryExpression) rhs).getLeft() + "").equals(lhs + ""))
{ // lhs := lhs & expr
Expression expr = ((BinaryExpression) rhs).getRight();
Vector vuses = expr.getVariableUses();

if (VectorUtil.containsEqualString(lhs+"", vuses))
{ return null; }

// lhs := lhs & rng->forAll(var|expr)

Expression coll =
new BinaryExpression("!",
new BinaryExpression(":", var, rng), expr);
Expression newrhs =
new BinaryExpression("&", lhs, coll);
return new AssignStatement(lhs, newrhs);
}
else if ((lhs + " or " + var).equals("" + rhs))
{ // lhs := lhs or loopRange->exists(self)

Type elemt = rng.getElementType();
BasicExpression selfvar =
BasicExpression.newVariableBasicExpression(
"self",elemt);
Expression prd =
new BinaryExpression("->exists", rng, selfvar);
Expression newrhs =
new BinaryExpression("or", lhs, prd);
return new AssignStatement(lhs, newrhs);
}
else if (rhs instanceof BinaryExpression &&
((BinaryExpression) rhs).getOperator().equals("or") &&
(((BinaryExpression) rhs).getLeft() + "").equals(lhs + ""))
{ // lhs := lhs or expr
Expression expr = ((BinaryExpression) rhs).getRight();
Vector vuses = expr.getVariableUses();

if (VectorUtil.containsEqualString(lhs+"", vuses))
{ return null; }

// lhs := lhs or rng->exists(var|expr)

Expression coll =
new BinaryExpression("#",
new BinaryExpression(":", var, rng), expr);
Expression newrhs =
new BinaryExpression("or", lhs, coll);
return new AssignStatement(lhs, newrhs);
}
/* else if (rhs instanceof BinaryExpression &&
(((BinaryExpression) rhs).getLeft() + "").equals(
lhs + ""))
{ BinaryExpression brhs = (BinaryExpression) rhs;
Expand Down Expand Up @@ -284,7 +348,7 @@ else if ("/".equals(oper))
new BinaryExpression("->pow", expr, smm));
return new AssignStatement(lhs, newrhs);
}
}
} */
}
else if (st instanceof SequenceStatement)
{ SequenceStatement sq = (SequenceStatement) st;
Expand Down Expand Up @@ -530,6 +594,14 @@ else if ((lhs + " / " + var).equals("" + rhs))
{ // lhs := lhs / loopRange->prd()
return true;
}
else if ((lhs + " & " + var).equals("" + rhs))
{ // lhs := lhs & loopRange->forAll(self)
return true;
}
else if ((lhs + " or " + var).equals("" + rhs))
{ // lhs := lhs or loopRange->exists(self)
return true;
}
else if (rhs instanceof BinaryExpression &&
(((BinaryExpression) rhs).getLeft() + "").equals(
lhs + ""))
Expand All @@ -544,8 +616,10 @@ else if (rhs instanceof BinaryExpression &&
{ return false; }

if ("+".equals(oper) || "-".equals(oper) ||
"*".equals(oper) || "/".equals(oper))
{ return true; }
"*".equals(oper) || "/".equals(oper) ||
"&".equals(oper) || "or".equals(oper))
{ return true; }

return false;
}
}
Expand Down
Binary file modified TryStatement.class
Binary file not shown.
Binary file modified WhileStatement.class
Binary file not shown.
9 changes: 5 additions & 4 deletions js2py3.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@ECHO OFF
SET TEST_CURRENT_DIR=%CLASSPATH:.;=%
if "%TEST_CURRENT_DIR%" == "%CLASSPATH%" ( SET CLASSPATH=.;%CLASSPATH% )
@ECHO ON
SET oldclasspath=%CLASSPATH%
SET CLASSPATH=.;.\antlr-4.8-complete.jar;%CLASSPATH%


type %1 | java org.antlr.v4.gui.TestRig JavaScript program -tree >output/ast.txt
java -jar umlrsds.jar -js2python

SET CLASSPATH=%oldclasspath%

0 comments on commit 865651c

Please sign in to comment.