Skip to content

Commit 4c222a7

Browse files
committed
cleanup
1 parent 936d081 commit 4c222a7

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,7 @@ private void handleSetOperator(BinaryOperatorNode node) throws Exception {
921921
nodeRight.accept(this.with(RuntimeContextType.LIST)); // emit the value
922922
node.left.accept(this.with(RuntimeContextType.LIST)); // emit the variable
923923
mv.visitInsn(Opcodes.SWAP); // move the target first
924-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "set", "(Lorg/perlonjava/runtime/RuntimeList;)Lorg/perlonjava/runtime/RuntimeList;", true);
925-
if (ctx.contextType == RuntimeContextType.SCALAR) {
926-
// Transform the value in the stack to Scalar
927-
// XXX HERE
928-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "count", "()Lorg/perlonjava/runtime/RuntimeScalar;", true);
929-
}
924+
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "set", "(Lorg/perlonjava/runtime/RuntimeList;)Lorg/perlonjava/runtime/RuntimeArray;", true);
930925
break;
931926
default:
932927
throw new IllegalArgumentException("Unsupported assignment context: " + lvalueContext);

src/main/java/org/perlonjava/runtime/RuntimeArray.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public RuntimeArray set(RuntimeScalar value) {
112112
}
113113

114114
// Replace the whole array with the elements of a list
115-
public RuntimeList set(RuntimeList value) {
115+
public RuntimeArray set(RuntimeList value) {
116116
this.elements.clear();
117117
value.addToArray(this);
118-
return new RuntimeList(this);
118+
return this;
119119
}
120120

121121
// Set a value at a specific index

src/main/java/org/perlonjava/runtime/RuntimeDataProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public interface RuntimeDataProvider {
7575
* @param list The RuntimeList object
7676
* @return list
7777
*/
78-
RuntimeList set(RuntimeList list);
78+
RuntimeArray set(RuntimeList list);
7979

8080
/**
8181
* Retrives the result of keys() as a RuntimeArray instance.

src/main/java/org/perlonjava/runtime/RuntimeGlob.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public RuntimeScalar addToScalar(RuntimeScalar scalar) {
107107
return scalar.set(this);
108108
}
109109

110-
public RuntimeList set(RuntimeList value) {
111-
return new RuntimeList(this.set(value.scalar()));
110+
public RuntimeArray set(RuntimeList value) {
111+
return new RuntimeArray(this.set(value.scalar()));
112112
}
113113

114114
// keys() operator

src/main/java/org/perlonjava/runtime/RuntimeHash.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public RuntimeScalar addToScalar(RuntimeScalar scalar) {
6767
}
6868

6969
// Replace the whole hash with the elements of a list
70-
public RuntimeList set(RuntimeList value) {
70+
public RuntimeArray set(RuntimeList value) {
7171
RuntimeArray arr = new RuntimeArray();
7272
value.addToArray(arr);
7373
if (arr.size() % 2 != 0) { // add an undef if the array size is odd
7474
arr.push(new RuntimeScalar());
7575
}
7676
RuntimeHash hash = fromArray(arr);
7777
this.elements = hash.elements;
78-
return new RuntimeList(this);
78+
return new RuntimeArray(new RuntimeList(this));
7979
}
8080

8181
// Add a key-value pair to the hash

src/main/java/org/perlonjava/runtime/RuntimeList.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,15 @@ public RuntimeScalar scalar() {
133133
// In LIST context returns the ARG LIST
134134
// In SCALAR context returns the number of elements in ARG LIST
135135
//
136-
public RuntimeList set(RuntimeList value) {
137-
138-
// preserve the right side as return value from the method
139-
RuntimeList original = new RuntimeList();
140-
for (RuntimeBaseEntity elem : value.elements) {
141-
original.add(elem);
142-
}
136+
public RuntimeArray set(RuntimeList value) {
143137

144138
// flatten the right side
139+
RuntimeArray original = new RuntimeArray();
140+
value.addToArray(original);
141+
142+
// retrieve the list
145143
RuntimeArray arr = new RuntimeArray();
146-
value.addToArray(arr);
144+
original.addToArray(arr);
147145

148146
for (RuntimeBaseEntity elem : elements) {
149147
if (elem instanceof RuntimeScalar) {
@@ -157,7 +155,7 @@ public RuntimeList set(RuntimeList value) {
157155
arr.elements = new ArrayList<>();
158156
}
159157
}
160-
return new RuntimeList(original);
158+
return original;
161159
}
162160

163161
// Convert the list to a string

src/main/java/org/perlonjava/runtime/RuntimeScalar.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ public RuntimeScalar set(RuntimeGlob value) {
347347
return this;
348348
}
349349

350-
public RuntimeList set(RuntimeList value) {
351-
return new RuntimeList(this.set(value.scalar()));
350+
public RuntimeArray set(RuntimeList value) {
351+
return new RuntimeArray(this.set(value.scalar()));
352352
}
353353

354354
@Override

0 commit comments

Comments
 (0)