Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Teach NativeCall REPR how to inline itself.
Note that there's not currently a way to get hold of the inlined thing
so NativeCall can use it; that will come next.
  • Loading branch information
jnthn committed Oct 12, 2013
1 parent ca138b9 commit 43567c3
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/NativeCall.java
@@ -1,9 +1,15 @@
package org.perl6.nqp.sixmodel.reprs;

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.SerializationReader;
import org.perl6.nqp.sixmodel.SerializationWriter;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;
import org.perl6.nqp.runtime.ExceptionHandling;
import org.perl6.nqp.runtime.ThreadContext;
Expand All @@ -25,15 +31,75 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.body = new NativeCallBody();
return obj;
}

public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
StorageSpec ss = new StorageSpec();
ss.inlineable = StorageSpec.INLINED;
ss.bits = 64;
return ss;
}

public void inlineStorage(ThreadContext tc, STable st, ClassWriter cw, String prefix) {
cw.visitField(Opcodes.ACC_PUBLIC, prefix, Type.getType(NativeCallBody.class).getDescriptor(), null, null);
}

public void inlineBind(ThreadContext tc, STable st, MethodVisitor mv, String className, String prefix) {
String nativeCallType = Type.getType(NativeCallBody.class).getDescriptor();
String nativeCallIN = Type.getType(NativeCallBody.class).getInternalName();

mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitInsn(Opcodes.ICONST_0 + ThreadContext.NATIVE_JVM_OBJ);
mv.visitFieldInsn(Opcodes.PUTFIELD, "org/perl6/nqp/runtime/ThreadContext", "native_type", "I");
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitFieldInsn(Opcodes.GETFIELD, "org/perl6/nqp/runtime/ThreadContext", "native_j",
Type.getType(Object.class).getDescriptor());
mv.visitTypeInsn(Opcodes.CHECKCAST, nativeCallIN);
mv.visitFieldInsn(Opcodes.PUTFIELD, className, prefix, nativeCallType);
mv.visitInsn(Opcodes.RETURN);
}

public void inlineGet(ThreadContext tc, STable st, MethodVisitor mv, String className, String prefix) {
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitInsn(Opcodes.DUP);
mv.visitInsn(Opcodes.ICONST_0 + ThreadContext.NATIVE_JVM_OBJ);
mv.visitFieldInsn(Opcodes.PUTFIELD, "org/perl6/nqp/runtime/ThreadContext", "native_type", "I");
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, className, prefix,
Type.getType(NativeCallBody.class).getDescriptor());
mv.visitFieldInsn(Opcodes.PUTFIELD, "org/perl6/nqp/runtime/ThreadContext", "native_j",
Type.getType(Object.class).getDescriptor());
mv.visitInsn(Opcodes.RETURN);
}

public void inlineDeserialize(ThreadContext tc, STable st, MethodVisitor mv, String className, String prefix) {
/* Not supported. */
}

public void generateBoxingMethods(ThreadContext tc, STable st, ClassWriter cw, String className, String prefix) {
/* We don't box/unbox as any of the native types. */
}

// We don't depend on any details of the STable, so no description is needed
@Override public boolean inline_description(ThreadContext tc, STable st, StringBuilder out) {
return true;
}
@Override public boolean box_description(ThreadContext tc, STable st, StringBuilder out) {
return true;
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
/* This REPR can't be serialized. */
ExceptionHandling.dieInternal(tc, "Can't deserialize_stub a NativeCall object.");

return null;
}

public void deserialize_finish(ThreadContext tc, STable st, SerializationReader reader, SixModelObject obj) {
ExceptionHandling.dieInternal(tc, "Can't deserialize_finish a NativeCall object.");
}

public void serialize_inlined(ThreadContext tc, STable st, SerializationWriter writer,
String prefix, SixModelObject obj) {
throw ExceptionHandling.dieInternal(tc, "Can't deserialize_stub a NativeCall object.");
}
}

0 comments on commit 43567c3

Please sign in to comment.