Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fill out MultiDimArray base class.
Has the storage-type-independent bits.
  • Loading branch information
jnthn committed Jul 10, 2015
1 parent a21ba08 commit 032f577
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -20,7 +20,17 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
}

public SixModelObject allocate(ThreadContext tc, STable st) {
throw ExceptionHandling.dieInternal(tc, "allocate NYI");
MultiDimArrayREPRData rd = (MultiDimArrayREPRData)st.REPRData;
if (rd != null) {
MultiDimArrayInstanceBase obj = new MultiDimArrayInstanceBase();
obj.dimensions = new long[rd.numDimensions];
obj.st = st;
return obj;
}
else {
throw ExceptionHandling.dieInternal(tc,
"Cannot allocate a multi-dim array type before it is composed");
}
}

public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
Expand Down
@@ -0,0 +1,27 @@
package org.perl6.nqp.sixmodel.reprs;

import java.lang.System;

import org.perl6.nqp.runtime.ExceptionHandling;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.SixModelObject;

public class MultiDimArrayInstanceBase extends SixModelObject {
public long[] dimensions;

public long[] dimensions(ThreadContext tc) {
return dimensions;
}

public void set_dimensions(ThreadContext tc, long[] dims) {
MultiDimArrayREPRData rd = (MultiDimArrayREPRData)this.st.REPRData;
if (rd.numDimensions == dims.length) {
System.arraycopy(dims, 0, this.dimensions, 0, dims.length);
}
else {
throw ExceptionHandling.dieInternal(tc, String.format(
"Array type of %d dimensions cannot be initialized with %d dimensions",
rd.numDimensions, dims.length));
}
}
}

0 comments on commit 032f577

Please sign in to comment.