Skip to content

Commit

Permalink
Fixed bug #52
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborsch committed Mar 21, 2024
1 parent 42e3a15 commit d4e14be
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 8 deletions.
Binary file modified rocky.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/rockstar/expression/NotExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Value evaluate(BlockContext ctx) {
ctx.beforeExpression(this);
Expression expr = this.getParameters().get(0);
Value v = expr.evaluate(ctx);
return ctx.afterExpression(this, v.negate());
return ctx.afterExpression(this, v.negateBoolean());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/rockstar/expression/UnaryMinusExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Value evaluate(BlockContext ctx) {
ctx.beforeExpression(this);
Expression expr1 = this.getParameters().get(0);
Value v1 = expr1.evaluate(ctx);
return ctx.afterExpression(this, Value.NULL.minus(v1));
return ctx.afterExpression(this, v1.negateNumeric());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/rockstar/runtime/RockNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ public static RockNumber getValueFromLong(long l) {
public abstract RockNumber floor();
public abstract RockNumber round();

protected abstract RockNumber negate();

}
1 change: 1 addition & 0 deletions src/rockstar/runtime/RockNumberBigDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public boolean isNegative() {
return value.compareTo(ZERO.value) < 0;
}

@Override
public RockNumberBigDecimal negate() {
return create(value.negate());
}
Expand Down
1 change: 1 addition & 0 deletions src/rockstar/runtime/RockNumberDec64.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public boolean isNegative() {
return mantissa>=0;
}

@Override
public RockNumberDec64 negate() {
return getFromCache(-mantissa, exponent);
}
Expand Down
9 changes: 8 additions & 1 deletion src/rockstar/runtime/RockNumberDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class RockNumberDouble extends RockNumber {
public final Double dblValue;

private RockNumberDouble(Double dblValue) {
if (dblValue != null && dblValue == -0.0) {
dblValue = 0.0;
}
this.dblValue = dblValue;
}

Expand Down Expand Up @@ -94,6 +97,11 @@ public RockNumberDouble multiply(RockNumber rn) {
public RockNumberDouble divide(RockNumber rn) {
return new RockNumberDouble(dblValue / convertToDbl(rn));
}

@Override
protected RockNumber negate() {
return new RockNumberDouble(-dblValue);
}

@Override
public int asInt() {
Expand Down Expand Up @@ -164,6 +172,5 @@ public RockNumber floor() {
public RockNumber round() {
return new RockNumberDouble((double)Math.round(dblValue));
}


}
14 changes: 11 additions & 3 deletions src/rockstar/runtime/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,17 @@ public String describe() {
return null;
}

public Value negate() {
// bool negation
return getBool() ? BOOLEAN_FALSE : BOOLEAN_TRUE;
public Value negateBoolean() {
return getBool() ? BOOLEAN_FALSE : BOOLEAN_TRUE;
}

public Value negateNumeric() {
switch (this.type) {
case NUMBER:
return Value.getValue(getNumeric().negate());
default:
throw new RockstarRuntimeException("Cannot negate "+this.getType()+" type");
}
}

public Value plus(Value other) {
Expand Down
2 changes: 1 addition & 1 deletion src/rockstar/statement/DecrementStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void execute(BlockContext ctx) {
v = v.asBoolean();
if (count % 2 == 1) {
// negate boolean
v = v.negate();
v = v.negateBoolean();
}
ctx.setVariable(variable, v);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/rockstar/statement/IncrementStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void execute(BlockContext ctx) {
v = v.asBoolean();
if (count % 2 == 1) {
// negate boolean
v = v.negate();
v = v.negateBoolean();
}
ctx.setVariable(variable, v);
return;
Expand Down

0 comments on commit d4e14be

Please sign in to comment.