Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stub in MultiDimArray REPR on JVM.
  • Loading branch information
jnthn committed Jul 10, 2015
1 parent 404e842 commit a21ba08
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/REPRRegistry.java
Expand Up @@ -38,6 +38,7 @@
import org.perl6.nqp.sixmodel.reprs.ConditionVariable;
import org.perl6.nqp.sixmodel.reprs.AsyncTask;
import org.perl6.nqp.sixmodel.reprs.NativeRef;
import org.perl6.nqp.sixmodel.reprs.MultiDimArray;

public class REPRRegistry {
private static HashMap<String, Integer> reprIdMap = new HashMap<String, Integer>();
Expand Down Expand Up @@ -100,5 +101,6 @@ private static void addREPR(String name, REPR REPR) {
addREPR("ConditionVariable", new ConditionVariable());
addREPR("AsyncTask", new AsyncTask());
addREPR("NativeRef", new NativeRef());
addREPR("MultiDimArray", new MultiDimArray());
}
}
96 changes: 96 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/MultiDimArray.java
@@ -0,0 +1,96 @@
package org.perl6.nqp.sixmodel.reprs;

import org.perl6.nqp.runtime.ExceptionHandling;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.SerializationReader;
import org.perl6.nqp.sixmodel.SerializationWriter;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.TypeObject;

public class MultiDimArray extends REPR {
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
STable st = new STable(this, HOW);
SixModelObject obj = new TypeObject();
obj.st = st;
st.WHAT = obj;
return st.WHAT;
}

public SixModelObject allocate(ThreadContext tc, STable st) {
throw ExceptionHandling.dieInternal(tc, "allocate NYI");
}

public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
SixModelObject arrayInfo = repr_info.at_key_boxed(tc, "array");
if (arrayInfo != null) {
MultiDimArrayREPRData reprData = new MultiDimArrayREPRData();

SixModelObject dims = arrayInfo.at_key_boxed(tc, "dimensions");
if (dims == null)
throw ExceptionHandling.dieInternal(tc,
"MultiDimArray REPR must be composed with a number of dimensions");
int dimensions = (int)dims.get_int(tc);
if (dimensions < 1)
throw ExceptionHandling.dieInternal(tc,
"MultiDimArray REPR must be composed with at least 1 dimension");
reprData.numDimensions = dimensions;

SixModelObject type = arrayInfo.at_key_boxed(tc, "type");
StorageSpec ss = type != null ? type.st.REPR.get_storage_spec(tc, type.st) : null;
switch (ss != null ? ss.boxed_primitive : StorageSpec.REFERENCE) {
case StorageSpec.BP_INT:
case StorageSpec.BP_NUM:
case StorageSpec.BP_STR:
reprData.type = type;
reprData.ss = ss;
break;
default:
if (ss != null && ss.inlineable != StorageSpec.REFERENCE)
throw ExceptionHandling.dieInternal(tc, "MultiDimArray can only store native int/num/str or reference types");
}

st.REPRData = reprData;
}
else {
throw ExceptionHandling.dieInternal(tc, "MultiDimArray REPR must be composed with array information");
}
}

public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
throw ExceptionHandling.dieInternal(tc, "deserialize NYI");
}

public void deserialize_finish(ThreadContext tc, STable st,
SerializationReader reader, SixModelObject obj) {
throw ExceptionHandling.dieInternal(tc, "deserialize NYI");
}

public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObject obj) {
throw ExceptionHandling.dieInternal(tc, "serialize NYI");
}

public StorageSpec get_value_storage_spec(ThreadContext tc, STable st) {
return st.REPRData == null ? StorageSpec.BOXED : ((MultiDimArrayREPRData)st.REPRData).ss;
}

/**
* REPR data serialization. Serializes the per-type representation data that
* is attached to the supplied STable.
*/
public void serialize_repr_data(ThreadContext tc, STable st, SerializationWriter writer)
{
throw ExceptionHandling.dieInternal(tc, "repr serialize NYI");
}

/**
* REPR data deserialization. Deserializes the per-type representation data and
* attaches it to the supplied STable.
*/
public void deserialize_repr_data(ThreadContext tc, STable st, SerializationReader reader)
{
throw ExceptionHandling.dieInternal(tc, "repr deserialize NYI");
}
}
@@ -0,0 +1,10 @@
package org.perl6.nqp.sixmodel.reprs;

import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;

public class MultiDimArrayREPRData {
public StorageSpec ss;
public SixModelObject type;
public int numDimensions;
}

0 comments on commit a21ba08

Please sign in to comment.