Skip to content

Commit

Permalink
Fixed #16 Print leading space before positive numbers (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral authored Dec 11, 2023
1 parent 6a59ad8 commit d66a0ed
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 278 deletions.
27 changes: 22 additions & 5 deletions src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import pSettle from "p-settle";
import { CoverageCollector } from "../coverage";
import { ManifestValue } from "../preprocessor/Manifest";
import { generateArgumentMismatchError } from "./ArgumentMismatch";
import Long from "long";

/** The set of options used to configure an interpreter's execution. */
export interface ExecutionOptions {
Expand Down Expand Up @@ -422,7 +423,9 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
);
}
} else {
this.stdout.write(this.evaluate(printable).toString());
const toPrint = this.evaluate(printable);
const str = isBrsNumber(toPrint) && this.isPositive(toPrint.getValue()) ? " " : "";
this.stdout.write(str + toPrint.toString());
}
});

Expand Down Expand Up @@ -575,8 +578,8 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
if (
isBrsNumber(left) &&
isBrsNumber(right) &&
right.getValue() >= 0 &&
right.getValue() < 32
this.isPositive(right.getValue()) &&
this.lessThan(right.getValue(), 32)
) {
return left.leftShift(right);
} else if (isBrsNumber(left) && isBrsNumber(right)) {
Expand Down Expand Up @@ -614,8 +617,8 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
if (
isBrsNumber(left) &&
isBrsNumber(right) &&
right.getValue() >= 0 &&
right.getValue() < 32
this.isPositive(right.getValue()) &&
this.lessThan(right.getValue(), 32)
) {
return left.rightShift(right);
} else if (isBrsNumber(left) && isBrsNumber(right)) {
Expand Down Expand Up @@ -1673,4 +1676,18 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
this.events.emit("err", err);
throw err;
}

private isPositive(value: number | Long): boolean {
if (value instanceof Long) {
return value.isPositive();
}
return value >= 0;
}

private lessThan(value: number | Long, compare: number): boolean {
if (value instanceof Long) {
return value.lessThan(compare);
}
return value < compare;
}
}
Loading

0 comments on commit d66a0ed

Please sign in to comment.