Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Teach P6int, P6num and P6str how to inline.
This means that native int, num and str attributes now work with
P6opaque.
  • Loading branch information
jnthn committed Jan 7, 2013
1 parent 1268e9d commit e5b4604
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6int.java
@@ -1,12 +1,21 @@
package org.perl6.nqp.sixmodel.reprs;

import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.FieldGen;
import org.apache.bcel.generic.Instruction;
import org.apache.bcel.generic.InstructionConstants;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.Type;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;

import com.sun.org.apache.bcel.internal.Constants;

public class P6int extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
STable st = new STable(this, HOW);
Expand All @@ -30,4 +39,37 @@ public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
ss.can_box = StorageSpec.CAN_BOX_INT;
return ss;
}

public void inlineStorage(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
FieldGen fg = new FieldGen(Constants.ACC_PRIVATE, Type.LONG, prefix, cp);
c.addField(fg.getField());
}

public Instruction[] inlineBind(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = f.createConstant(ThreadContext.NATIVE_INT);
ins[2] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[3] = InstructionConstants.ALOAD_0;
ins[4] = InstructionConstants.ALOAD_1;
ins[5] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_i", Type.LONG, Constants.GETFIELD);
ins[6] = f.createFieldAccess(c.getClassName(), prefix, Type.LONG, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}

public Instruction[] inlineGet(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = InstructionConstants.DUP;
ins[2] = f.createConstant(ThreadContext.NATIVE_INT);
ins[3] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[4] = InstructionConstants.ALOAD_0;
ins[5] = f.createFieldAccess(c.getClassName(), prefix, Type.LONG, Constants.GETFIELD);
ins[6] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_i", Type.LONG, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}
}
42 changes: 42 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6num.java
@@ -1,12 +1,21 @@
package org.perl6.nqp.sixmodel.reprs;

import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.FieldGen;
import org.apache.bcel.generic.Instruction;
import org.apache.bcel.generic.InstructionConstants;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.Type;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;

import com.sun.org.apache.bcel.internal.Constants;

public class P6num extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
STable st = new STable(this, HOW);
Expand All @@ -31,4 +40,37 @@ public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
ss.can_box = StorageSpec.CAN_BOX_NUM;
return ss;
}

public void inlineStorage(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
FieldGen fg = new FieldGen(Constants.ACC_PRIVATE, Type.DOUBLE, prefix, cp);
c.addField(fg.getField());
}

public Instruction[] inlineBind(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = f.createConstant(ThreadContext.NATIVE_NUM);
ins[2] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[3] = InstructionConstants.ALOAD_0;
ins[4] = InstructionConstants.ALOAD_1;
ins[5] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_n", Type.DOUBLE, Constants.GETFIELD);
ins[6] = f.createFieldAccess(c.getClassName(), prefix, Type.DOUBLE, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}

public Instruction[] inlineGet(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = InstructionConstants.DUP;
ins[2] = f.createConstant(ThreadContext.NATIVE_NUM);
ins[3] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[4] = InstructionConstants.ALOAD_0;
ins[5] = f.createFieldAccess(c.getClassName(), prefix, Type.DOUBLE, Constants.GETFIELD);
ins[6] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_n", Type.DOUBLE, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}
}
42 changes: 42 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6str.java
@@ -1,12 +1,21 @@
package org.perl6.nqp.sixmodel.reprs;

import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.FieldGen;
import org.apache.bcel.generic.Instruction;
import org.apache.bcel.generic.InstructionConstants;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.Type;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;

import com.sun.org.apache.bcel.internal.Constants;

public class P6str extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
STable st = new STable(this, HOW);
Expand All @@ -30,4 +39,37 @@ public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
ss.can_box = StorageSpec.CAN_BOX_STR;
return ss;
}

public void inlineStorage(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
FieldGen fg = new FieldGen(Constants.ACC_PRIVATE, Type.STRING, prefix, cp);
c.addField(fg.getField());
}

public Instruction[] inlineBind(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = f.createConstant(ThreadContext.NATIVE_STR);
ins[2] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[3] = InstructionConstants.ALOAD_0;
ins[4] = InstructionConstants.ALOAD_1;
ins[5] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_s", Type.STRING, Constants.GETFIELD);
ins[6] = f.createFieldAccess(c.getClassName(), prefix, Type.STRING, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}

public Instruction[] inlineGet(ThreadContext tc, STable st, ClassGen c, ConstantPoolGen cp, String prefix) {
InstructionFactory f = new InstructionFactory(cp);
Instruction[] ins = new Instruction[8];
ins[0] = InstructionConstants.ALOAD_1;
ins[1] = InstructionConstants.DUP;
ins[2] = f.createConstant(ThreadContext.NATIVE_STR);
ins[3] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_type", Type.INT, Constants.PUTFIELD);
ins[4] = InstructionConstants.ALOAD_0;
ins[5] = f.createFieldAccess(c.getClassName(), prefix, Type.STRING, Constants.GETFIELD);
ins[6] = f.createFieldAccess("org.perl6.nqp.runtime.ThreadContext", "native_s", Type.STRING, Constants.PUTFIELD);
ins[7] = InstructionConstants.RETURN;
return ins;
}
}

0 comments on commit e5b4604

Please sign in to comment.