From f1aebb45b3f9a2dfc4c1f9345f38188930306f3e Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Wed, 29 Oct 2025 10:23:52 +0100 Subject: [PATCH 1/2] Add support for binary& binary| binary^ operators in bitwise feature When 'use feature "bitwise"' is enabled, the parser renames bitwise operators to binary& binary| binary^ to distinguish numeric bitwise ops from string bitwise ops (&. |. ^.). These renamed operators were already registered in OperatorHandler and have implementations in BitwiseOperators, but they were missing from the EmitBinaryOperatorNode case statement. This fixes the compilation error 'Not implemented operator: binary&' when using bitwise operators with the bitwise feature enabled. Progress on t/op/bop.t: Now runs 215 tests (was failing at parse/compile time) --- .../java/org/perlonjava/codegen/EmitBinaryOperatorNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/perlonjava/codegen/EmitBinaryOperatorNode.java b/src/main/java/org/perlonjava/codegen/EmitBinaryOperatorNode.java index aafaf1445..98f582018 100644 --- a/src/main/java/org/perlonjava/codegen/EmitBinaryOperatorNode.java +++ b/src/main/java/org/perlonjava/codegen/EmitBinaryOperatorNode.java @@ -81,8 +81,8 @@ public static void emitBinaryOperatorNode(EmitterVisitor emitterVisitor, BinaryO "==", "!=", "eq", "ne" -> EmitOperatorChained.emitChainedComparison(emitterVisitor, node); // Binary operators - case "%", "&", "&.", "*", "**", "+", "-", "/", "^^", "xor", - "<<", "<=>", ">>", "^", "^.", "|", "|.", + case "%", "&", "&.", "binary&", "*", "**", "+", "-", "/", "^^", "xor", + "<<", "<=>", ">>", "^", "^.", "binary^", "|", "|.", "binary|", "bless", "cmp", "isa" -> EmitBinaryOperator.handleBinaryOperator(emitterVisitor, node, OperatorHandler.get(node.operator)); From 6ce7273f9508dc965f7f5fcd19dc71ba118a3b6c Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Wed, 29 Oct 2025 10:26:25 +0100 Subject: [PATCH 2/2] Fix backslash operator to use SCALAR context for most operands The backslash operator (\) was evaluating all non-\& operands in LIST context, which caused issues when creating references to constant subs or other expressions that return scalars. For example, \PVBM where PVBM is a constant sub would evaluate PVBM() in LIST context, returning a RuntimeList, then call createReference() on it which throws 'create reference of list not implemented'. This fix changes the backslash operator to evaluate most operands in SCALAR context (the natural context for creating a reference to a value). LIST context is only used for actual list-producing operations like @ and % variables, or explicit ListNodes. This fixes the remaining failures in t/op/bop.t related to references. Progress on t/op/bop.t: Now passes 313 out of 522 tests (59%) --- src/main/java/org/perlonjava/codegen/EmitOperator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/perlonjava/codegen/EmitOperator.java b/src/main/java/org/perlonjava/codegen/EmitOperator.java index f76ad5a76..7d7f099ee 100644 --- a/src/main/java/org/perlonjava/codegen/EmitOperator.java +++ b/src/main/java/org/perlonjava/codegen/EmitOperator.java @@ -893,7 +893,15 @@ static void handleCreateReference(EmitterVisitor emitterVisitor, OperatorNode no node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST)); } } else { - node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST)); + // For most cases, evaluate in SCALAR context to get a reference to the value + // Only use LIST context for actual list-producing operations + int contextType = RuntimeContextType.SCALAR; + if (node.operand instanceof ListNode || + (node.operand instanceof OperatorNode op && + (op.operator.equals("@") || op.operator.equals("%")))) { + contextType = RuntimeContextType.LIST; + } + node.operand.accept(emitterVisitor.with(contextType)); emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBase", "createReference",