Skip to content

Commit f1e2ae0

Browse files
committed
lvalue subroutines
1 parent 67f0f00 commit f1e2ae0

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

FEATURE_MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
-**Subroutine signatures**: Formal parameters are not implemented.
145145
-**Inline "constant" subroutines optimization**: Optimization for inline constants is not yet implemented.
146146
-**Subroutine attributes**: Subroutine attributes are not yet supported.
147-
- **`lvalue` subroutines**: Subroutines with attribute `:lvalue` are not yet supported.
147+
- ✔️ **`lvalue` subroutines**: Subroutines with attribute `:lvalue` are supported.
148148
-**Lexical subroutines**: Subroutines declared `my`, `state`, or `our` are not yet supported.
149149
- ✔️ **CORE namespace**: `CORE` is implemented.
150150
-**CORE::GLOBAL namespace**: `CORE::GLOBAL` is not implemented.

MILESTONES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
- Added v-strings.
8686
- Added Infinity, -Infinity, NaN.
8787
- Added `\N{name}` operator for named characters in double quoted strings and in regex.
88+
- Added lvalue subroutines.
8889
- CI/CD runs in Ubuntu and Windows
8990
- Work in progress:
9091
- `state` variables.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public void visit(BinaryOperatorNode node) {
4848
case "substr":
4949
context = RuntimeContextType.SCALAR;
5050
break;
51+
case "(":
52+
// l-value subroutine call
53+
// XXX TODO - check for lvalue attribute
54+
context = RuntimeContextType.SCALAR;
55+
break;
5156
default:
5257
context = RuntimeContextType.VOID; // Not an L-value
5358
}

src/test/resources/subroutine.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,7 @@ package Other {
109109
$result = &$ref_to_sub;
110110
print "not " if $result ne "<reference test>"; say "ok # reference to subroutine with &$ref_to_sub reused @_ and returned '$result'";
111111

112+
# lvalue subroutine
113+
sub lv :lvalue { $result }
114+
lv = 13;
115+
print "not " if $result ne "13"; say "ok # lvalue subroutine call is assignable";

0 commit comments

Comments
 (0)