Skip to content

Commit 7f809b9

Browse files
committed
tie scalar WIP
1 parent b565925 commit 7f809b9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public int getInt() {
238238
case GLOB -> 1; // Assuming globs are truthy, so 1
239239
case REGEX -> 1; // Assuming regexes are truthy, so 1
240240
case JAVAOBJECT -> value != null ? 1 : 0;
241+
case TIED_SCALAR -> tiedFetch().getInt();
241242
default -> Overload.numify(this).getInt();
242243
};
243244
}
@@ -254,6 +255,7 @@ public long getLong() {
254255
case GLOB -> 1L;
255256
case REGEX -> 1L;
256257
case JAVAOBJECT -> value != null ? 1L : 0L;
258+
case TIED_SCALAR -> tiedFetch().getLong();
257259
default -> Overload.numify(this).getLong();
258260
};
259261
}
@@ -270,6 +272,7 @@ public double getDouble() {
270272
case GLOB -> 1.0;
271273
case REGEX -> 1.0;
272274
case JAVAOBJECT -> value != null ? 1.0 : 0.0;
275+
case TIED_SCALAR -> tiedFetch().getDouble();
273276
default -> Overload.numify(this).getDouble();
274277
};
275278
}
@@ -289,6 +292,7 @@ public boolean getBoolean() {
289292
case GLOB -> true;
290293
case REGEX -> true;
291294
case JAVAOBJECT -> value != null;
295+
case TIED_SCALAR -> tiedFetch().getBoolean();
292296
default -> Overload.boolify(this).getBoolean();
293297
};
294298
}
@@ -328,8 +332,19 @@ public RuntimeScalar addToScalar(RuntimeScalar scalar) {
328332
return scalar.set(this);
329333
}
330334

335+
public RuntimeScalar tiedFetch() {
336+
throw new PerlCompilerException("not implemented: tied FETCH on scalar");
337+
}
338+
339+
public RuntimeScalar tiedStore() {
340+
throw new PerlCompilerException("not implemented: tied STORE on scalar");
341+
}
342+
331343
// Setters
332344
public RuntimeScalar set(RuntimeScalar value) {
345+
if (this.type == TIED_SCALAR) {
346+
return tiedStore();
347+
}
333348
this.type = value.type;
334349
this.value = value.value;
335350
return this;
@@ -397,6 +412,7 @@ public String toString() {
397412
case GLOB -> value == null ? "" : value.toString();
398413
case REGEX -> value.toString();
399414
case JAVAOBJECT -> value.toString();
415+
case TIED_SCALAR -> tiedFetch().toString();
400416
default -> Overload.stringify(this).toString();
401417
};
402418
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public class RuntimeScalarType {
1414
public static final int GLOB = 6;
1515
public static final int REGEX = 7;
1616
public static final int JAVAOBJECT = 8;
17+
public static final int TIED_SCALAR = 9;
1718
// References with bit pattern
18-
public static final int CODE = 9 | REFERENCE_BIT;
19-
public static final int REFERENCE = 10 | REFERENCE_BIT;
20-
public static final int ARRAYREFERENCE = 11 | REFERENCE_BIT;
21-
public static final int HASHREFERENCE = 12 | REFERENCE_BIT;
22-
public static final int GLOBREFERENCE = 13 | REFERENCE_BIT;
19+
public static final int CODE = 100 | REFERENCE_BIT;
20+
public static final int REFERENCE = 101 | REFERENCE_BIT;
21+
public static final int ARRAYREFERENCE = 102 | REFERENCE_BIT;
22+
public static final int HASHREFERENCE = 103 | REFERENCE_BIT;
23+
public static final int GLOBREFERENCE = 104 | REFERENCE_BIT;
2324

2425
private RuntimeScalarType() {
2526
} // Prevent instantiation

0 commit comments

Comments
 (0)