Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fill out native lexical reference REPR bits.
  • Loading branch information
jnthn committed Feb 28, 2015
1 parent ceb047a commit 89d2119
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/NativeRef.java
Expand Up @@ -4,6 +4,7 @@
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.REPR;
import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.SerializationReader;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.TypeObject;
Expand All @@ -14,13 +15,36 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
SixModelObject obj = new TypeObject();
obj.st = st;
st.WHAT = obj;
st.REPRData = new NativeRefREPRData();
return st.WHAT;
}

public SixModelObject allocate(ThreadContext tc, STable st) {
throw ExceptionHandling.dieInternal(tc, "NYI");
/*obj.st = st;
return obj;*/
NativeRefREPRData rd = (NativeRefREPRData)st.REPRData;
SixModelObject obj;
switch (rd.ref_kind) {
case NativeRefREPRData.REF_LEXICAL:
switch (rd.primitive_type) {
case StorageSpec.BP_INT:
obj = new NativeRefInstanceIntLex();
break;
case StorageSpec.BP_NUM:
obj = new NativeRefInstanceIntLex();
break;
case StorageSpec.BP_STR:
obj = new NativeRefInstanceIntLex();
break;
default:
throw ExceptionHandling.dieInternal(tc,
"Unknown primtive type in native ref allocation");
}
break;
default:
throw ExceptionHandling.dieInternal(tc,
"Unknown reference kind in native ref allocation");
}
obj.st = st;
return obj;
}

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

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

/* Base for instances of native references. */
public abstract class NativeRefInstance extends SixModelObject {
public abstract long fetch_i(ThreadContext tc);
public abstract double fetch_n(ThreadContext tc);
public abstract String fetch_s(ThreadContext tc);
public abstract void store_i(ThreadContext tc, long value);
public abstract void store_n(ThreadContext tc, double value);
public abstract void store_s(ThreadContext tc, String value);
}
@@ -0,0 +1,39 @@
package org.perl6.nqp.sixmodel.reprs;

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

/* Integer native lexical reference. */
public class NativeRefInstanceIntLex extends SixModelObject {
public long[] lexicals;
public int idx;

public long fetch_i(ThreadContext tc) {
return lexicals[idx];
}

public double fetch_n(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
}

public String fetch_s(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
}

public void store_i(ThreadContext tc, long value) {
lexicals[idx] = value;
}

public void store_n(ThreadContext tc, double value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
}

public void store_s(ThreadContext tc, String value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
}
}
@@ -0,0 +1,39 @@
package org.perl6.nqp.sixmodel.reprs;

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

/* Integer native lexical reference. */
public class NativeRefInstanceNumLex extends SixModelObject {
public double[] lexicals;
public int idx;

public long fetch_i(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native integer");
}

public double fetch_n(ThreadContext tc) {
return lexicals[idx];
}

public String fetch_s(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
}

public void store_i(ThreadContext tc, long value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native integer");
}

public void store_n(ThreadContext tc, double value) {
lexicals[idx] = value;
}

public void store_s(ThreadContext tc, String value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
}
}
@@ -0,0 +1,39 @@
package org.perl6.nqp.sixmodel.reprs;

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

/* Integer native lexical reference. */
public class NativeRefInstanceStrLex extends SixModelObject {
public String[] lexicals;
public int idx;

public long fetch_i(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native integer");
}

public double fetch_n(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
}

public String fetch_s(ThreadContext tc) {
return lexicals[idx];
}

public void store_i(ThreadContext tc, long value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native integer");
}

public void store_n(ThreadContext tc, double value) {
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
}

public void store_s(ThreadContext tc, String value) {
lexicals[idx] = value;
}
}

0 comments on commit 89d2119

Please sign in to comment.