Skip to content

Commit cd504ef

Browse files
authored
Merge pull request #55 from fglock/fix-bop-test
Fix bop test
2 parents 89e92dd + 6ce7273 commit cd504ef

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/java/org/perlonjava/codegen/EmitBinaryOperatorNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public static void emitBinaryOperatorNode(EmitterVisitor emitterVisitor, BinaryO
8181
"==", "!=", "eq", "ne" -> EmitOperatorChained.emitChainedComparison(emitterVisitor, node);
8282

8383
// Binary operators
84-
case "%", "&", "&.", "*", "**", "+", "-", "/", "^^", "xor",
85-
"<<", "<=>", ">>", "^", "^.", "|", "|.",
84+
case "%", "&", "&.", "binary&", "*", "**", "+", "-", "/", "^^", "xor",
85+
"<<", "<=>", ">>", "^", "^.", "binary^", "|", "|.", "binary|",
8686
"bless", "cmp", "isa" -> EmitBinaryOperator.handleBinaryOperator(emitterVisitor, node,
8787
OperatorHandler.get(node.operator));
8888

src/main/java/org/perlonjava/codegen/EmitOperator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,15 @@ static void handleCreateReference(EmitterVisitor emitterVisitor, OperatorNode no
893893
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
894894
}
895895
} else {
896-
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
896+
// For most cases, evaluate in SCALAR context to get a reference to the value
897+
// Only use LIST context for actual list-producing operations
898+
int contextType = RuntimeContextType.SCALAR;
899+
if (node.operand instanceof ListNode ||
900+
(node.operand instanceof OperatorNode op &&
901+
(op.operator.equals("@") || op.operator.equals("%")))) {
902+
contextType = RuntimeContextType.LIST;
903+
}
904+
node.operand.accept(emitterVisitor.with(contextType));
897905
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
898906
"org/perlonjava/runtime/RuntimeBase",
899907
"createReference",

0 commit comments

Comments
 (0)