Skip to content

Commit cd0c077

Browse files
committed
refactoring
1 parent 9e7180c commit cd0c077

File tree

8 files changed

+31
-19
lines changed

8 files changed

+31
-19
lines changed

src/main/java/org/perlonjava/parser/StatementParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ public static Node parseUseDeclaration(Parser parser, LexerToken token) {
308308
// If the specified Perl version is 5.12 or higher,
309309
// strictures are enabled lexically.
310310
useStrict(new RuntimeArray(
311-
List.of(new RuntimeScalar("strict"))), RuntimeContextType.VOID);
311+
new RuntimeScalar("strict")), RuntimeContextType.VOID);
312312
}
313313
if (minorVersion >= 35) {
314314
// If the specified Perl version is 5.35.0 or higher,
315315
// warnings are enabled.
316316
useWarnings(new RuntimeArray(
317-
List.of(new RuntimeScalar("warnings"),
318-
new RuntimeScalar("all"))), RuntimeContextType.VOID);
317+
new RuntimeScalar("warnings"),
318+
new RuntimeScalar("all")), RuntimeContextType.VOID);
319319
}
320320
}
321321
}

src/main/java/org/perlonjava/perlmodule/FileSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static RuntimeList splitpath(RuntimeArray args, int ctx) {
274274
}
275275

276276
return new RuntimeList(
277-
List.of(new RuntimeScalar(volume), new RuntimeScalar(directory), new RuntimeScalar(file)));
277+
new RuntimeScalar(volume), new RuntimeScalar(directory), new RuntimeScalar(file));
278278
}
279279

280280
/**

src/main/java/org/perlonjava/perlmodule/Json.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static RuntimeList encode_json(RuntimeArray args, int ctx) {
115115
RuntimeContextType.SCALAR)
116116
.elements.getFirst();
117117
return encode(
118-
new RuntimeArray(List.of(jsonObject, perlData)),
118+
new RuntimeArray(jsonObject, perlData),
119119
RuntimeContextType.SCALAR);
120120
}
121121

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ public RuntimeArray(List<RuntimeScalar> list) {
3636
this.elements = new ArrayList<>(list);
3737
}
3838

39+
public RuntimeArray(RuntimeBaseEntity... values) {
40+
this.elements = new ArrayList<>();
41+
for (RuntimeBaseEntity value : values) {
42+
Iterator<RuntimeScalar> iterator = value.iterator();
43+
while (iterator.hasNext()) {
44+
this.elements.add(iterator.next());
45+
}
46+
}
47+
}
48+
3949
/**
4050
* Constructs a RuntimeArray from a RuntimeList.
4151
*

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public RuntimeScalar addToScalar(RuntimeScalar scalar) {
9494
public RuntimeArray setFromList(RuntimeList value) {
9595
RuntimeHash hash = createHash(value);
9696
this.elements = hash.elements;
97-
return new RuntimeArray(new RuntimeList(this));
97+
return new RuntimeArray(this);
9898
}
9999

100100
/**
@@ -291,10 +291,7 @@ public RuntimeList each() {
291291
hashIterator = iterator();
292292
}
293293
if (hashIterator.hasNext()) {
294-
RuntimeList list = new RuntimeList();
295-
list.elements.add(hashIterator.next());
296-
list.elements.add(hashIterator.next());
297-
return list;
294+
return new RuntimeList(hashIterator.next(), hashIterator.next());
298295
}
299296
hashIterator = null;
300297
return new RuntimeList();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public RuntimeList(List<RuntimeScalar> list) {
2222
this.elements = new ArrayList<>(list);
2323
}
2424

25+
public RuntimeList(RuntimeBaseEntity... values) {
26+
this.elements = new ArrayList<>();
27+
for (RuntimeBaseEntity value : values) {
28+
Iterator<RuntimeScalar> iterator = value.iterator();
29+
while (iterator.hasNext()) {
30+
this.elements.add(iterator.next());
31+
}
32+
}
33+
}
34+
2535
/**
2636
* Constructs a RuntimeList with a single scalar value.
2737
*

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,12 @@ public static RuntimeList caller(RuntimeList args, int ctx) {
163163
}
164164

165165
public static RuntimeList reset(RuntimeList args, int ctx) {
166-
RuntimeList res = new RuntimeList();
167166
if (args.elements.isEmpty()) {
168167
RuntimeRegex.reset();
169168
} else {
170169
throw new PerlCompilerException("not implemented: reset(args)");
171170
}
172-
res.add(getScalarInt(1));
173-
return res;
171+
return getScalarInt(1).getList();
174172
}
175173

176174
public RuntimeScalar exit() {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ public RuntimeScalar set(RuntimeScalar value) {
5656

5757
int newValue = value.getInt();
5858

59-
// Create arguments for Vec.set method
60-
RuntimeList args = new RuntimeList();
61-
args.elements.add(lvalue);
62-
args.elements.add(new RuntimeScalar(offset));
63-
args.elements.add(new RuntimeScalar(bits));
64-
6559
try {
60+
// Create arguments for Vec.set method
61+
RuntimeList args = new RuntimeList(
62+
lvalue, new RuntimeScalar(offset), new RuntimeScalar(bits));
6663
// Use Vec.set to update the parent string
6764
Vec.set(args, new RuntimeScalar(newValue));
6865
} catch (PerlCompilerException e) {

0 commit comments

Comments
 (0)