Skip to content

Commit

Permalink
chore: use boolean type for branch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie authored and Eddie committed Jun 19, 2024
1 parent b22e6c9 commit eb3a8c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/main/java/com/jungle/compiler/operand/OperandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ public enum OperandType {
FLOAT;

@NotNull
public static final Set<OperandType> INTEGER_OPERATION_TYPES = SetUtils.newSet(
public static final Set<OperandType> INTEGER_COMPUTATIONAL_TYPES = SetUtils.newSet(
OperandType.BOOLEAN,
OperandType.CHAR,
OperandType.BYTE,
OperandType.SHORT,
OperandType.INTEGER,
OperandType.LONG,
OperandType.FLOAT,
OperandType.DOUBLE
OperandType.INTEGER
);

public int getConvertOpcode(@NotNull OperandType that) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/jungle/compiler/visitor/AssertVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public void visit(

// if (![int expression]) throw new AssertionError("Detailed Message");

if (context.peek() != OperandType.INTEGER) {
throw new Error("assert condition/expression expected to be type integer");
OperandType conditionType = context.peek();
if (!OperandType.INTEGER_COMPUTATIONAL_TYPES.contains(conditionType)) {
throw new Error("assert condition/expression expected to be integer-like");
}

// if int value on operand stack is not-equal to zero then throw error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class BooleanOperatorVisitor extends AbstractVisitor {
private static final FileLogger logger = new FileLogger(BooleanOperatorVisitor.class.getName());

@NotNull
private static final INode PUSH_TRUE_NODE = new Node(NodeType.LITERAL_INTEGER).withRawValue("1");
private static final INode PUSH_TRUE_NODE = new Node(NodeType.LITERAL_BOOLEAN).withRawValue("true");

@NotNull
private static final INode PUSH_FALSE_NODE = new Node(NodeType.LITERAL_INTEGER).withRawValue("0");
private static final INode PUSH_FALSE_NODE = new Node(NodeType.LITERAL_BOOLEAN).withRawValue("false");

@NotNull
private static final Set<NodeType> BOOLEAN_OPERATORS = new HashSet<>(Arrays.asList(
Expand Down

0 comments on commit eb3a8c1

Please sign in to comment.