Skip to content

Commit 3c4f0ff

Browse files
committed
Make getattr mostly work like it does on moar.
Well, mostly, hopefully. There might be a case where we have multiple Fields that could take the attr we got, and we wrongly assign to the first we find.
1 parent 618c6be commit 3c4f0ff

File tree

1 file changed

+16
-6
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+16
-6
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,12 +2732,22 @@ else if (tc.native_type == ThreadContext.NATIVE_STR) {
27322732
retval = box_s((String)tc.native_s, tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.strBoxType, tc);
27332733
}
27342734
else if (tc.native_type == ThreadContext.NATIVE_JVM_OBJ) {
2735-
/* XXX: there might be other cases and we have to figure out, what kind of
2736-
REPR we need to properly wrap around the NATIVE_JVM_OBJ we goet here,
2737-
but so far this seems to cover what's needed. */
2738-
retval = REPRRegistry.getByName("NativeCall").allocate(tc,
2739-
REPRRegistry.getByName("NativeCall").type_object_for(tc, tc.gc.KnowHOW).st);
2740-
((NativeCallInstance)retval).body = (NativeCallBody) tc.native_j;
2735+
int slot = ((P6OpaqueBaseInstance)obj).resolveAttribute(obj.st.WHAT, name);
2736+
STable attr_st = ((P6OpaqueREPRData) obj.st.REPRData).flattenedSTables[slot];
2737+
if (attr_st != null) {
2738+
retval = attr_st.REPR.allocate(tc, attr_st);
2739+
for (Field field : retval.getClass().getDeclaredFields()) {
2740+
try {
2741+
if (field.getType().isAssignableFrom(tc.native_j.getClass())) {
2742+
field.set(retval, tc.native_j);
2743+
break;
2744+
}
2745+
}
2746+
catch (IllegalAccessException iae) {
2747+
throw ExceptionHandling.dieInternal(tc, "Attribute '" + name + "' couldn't be boxed");
2748+
}
2749+
}
2750+
}
27412751
}
27422752
return retval;
27432753
}

0 commit comments

Comments
 (0)