Skip to content

Commit

Permalink
Get storage_spec REPR function in place.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Dec 23, 2012
1 parent 5b333e2 commit bc84245
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/org/perl6/nqp/sixmodel/REPR.java
Expand Up @@ -42,6 +42,14 @@ public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
public long hint_for(ThreadContext tc, STable st, SixModelObject class_handle, String name) {
return STable.NO_HINT;
}

/**
* Gets information on how objects of this representation like to be
* stored (inlined into the body of another object, or referencey).
*/
public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
return new StorageSpec();
}

/**
* For aggregate types, gets the storage type of values in the aggregate.
Expand Down
8 changes: 4 additions & 4 deletions src/org/perl6/nqp/sixmodel/StorageSpec.java
Expand Up @@ -23,17 +23,17 @@ public class StorageSpec {
public static final short CAN_BOX_STR = 4;

/* 0 if this is to be referenced, anything else otherwise. */
short inlineable;
public short inlineable;

/* For things that want to be inlined, the number of bits of
* storage they need. Ignored otherwise. */
short bits;
public short bits;

/* For things that are inlined, if they are just storage of a
* primitive type and can unbox, this says what primitive type
* that they unbox to. */
short boxed_primitive;
public short boxed_primitive;

/* The types that this one can box/unbox to. */
short can_box;
public short can_box;
}
10 changes: 10 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6int.java
Expand Up @@ -4,6 +4,7 @@
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;

public class P6int extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
Expand All @@ -19,4 +20,13 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.st = st;
return obj;
}

public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
StorageSpec ss = new StorageSpec();
ss.inlineable = StorageSpec.INLINED;
ss.boxed_primitive = StorageSpec.BP_INT;
ss.bits = 64;
ss.can_box = StorageSpec.CAN_BOX_INT;
return ss;
}
}
11 changes: 10 additions & 1 deletion src/org/perl6/nqp/sixmodel/reprs/P6num.java
Expand Up @@ -4,6 +4,7 @@
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;

public class P6num extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
Expand All @@ -20,5 +21,13 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.value = Double.NaN;
return obj;
}


public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
StorageSpec ss = new StorageSpec();
ss.inlineable = StorageSpec.INLINED;
ss.boxed_primitive = StorageSpec.BP_NUM;
ss.bits = 64;
ss.can_box = StorageSpec.CAN_BOX_NUM;
return ss;
}
}
9 changes: 9 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/P6str.java
Expand Up @@ -4,6 +4,7 @@
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;

public class P6str extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
Expand All @@ -20,4 +21,12 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
obj.value = "";
return obj;
}

public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
StorageSpec ss = new StorageSpec();
ss.inlineable = StorageSpec.INLINED;
ss.boxed_primitive = StorageSpec.BP_STR;
ss.can_box = StorageSpec.CAN_BOX_STR;
return ss;
}
}

0 comments on commit bc84245

Please sign in to comment.