Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Extend NativeRef REPR to include attribute refs.
  • Loading branch information
jnthn committed Feb 28, 2015
1 parent 75d83a9 commit 11b846e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Expand Up @@ -42,6 +42,9 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
"Unknown primtive type in native ref allocation");
}
break;
case NativeRefREPRData.REF_ATTRIBUTE:
obj = new NativeRefInstanceAttribute();
break;
default:
throw ExceptionHandling.dieInternal(tc,
"Unknown reference kind in native ref allocation");
Expand Down
@@ -0,0 +1,71 @@
package org.perl6.nqp.sixmodel.reprs;

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

/* Native attribute reference. */
public class NativeRefInstanceAttribute extends NativeRefInstance {
public SixModelObject obj;
public SixModelObject classHandle;
public String name;
public long hint;

public long fetch_i(ThreadContext tc) {
obj.get_attribute_native(tc, classHandle, name, hint);
if (tc.native_type == ThreadContext.NATIVE_INT)
return tc.native_i;
else
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native int");
}

public double fetch_n(ThreadContext tc) {
obj.get_attribute_native(tc, classHandle, name, hint);
if (tc.native_type == ThreadContext.NATIVE_NUM)
return tc.native_n;
else
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
}

public String fetch_s(ThreadContext tc) {
obj.get_attribute_native(tc, classHandle, name, hint);
if (tc.native_type == ThreadContext.NATIVE_STR)
return tc.native_s;
else
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
}

public void store_i(ThreadContext tc, long value) {
tc.native_i = value;
obj.bind_attribute_native(tc, classHandle, name, hint);
if (tc.native_type != ThreadContext.NATIVE_INT)
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native int");
if (obj.sc != null)
Ops.scwbObject(tc, obj);
}

public void store_n(ThreadContext tc, double value) {
tc.native_n = value;
obj.bind_attribute_native(tc, classHandle, name, hint);
if (tc.native_type != ThreadContext.NATIVE_NUM)
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native number");
if (obj.sc != null)
Ops.scwbObject(tc, obj);
}

public void store_s(ThreadContext tc, String value) {
tc.native_s = value;
obj.bind_attribute_native(tc, classHandle, name, hint);
if (tc.native_type != ThreadContext.NATIVE_STR)
throw ExceptionHandling.dieInternal(tc,
"This container does not reference a native string");
if (obj.sc != null)
Ops.scwbObject(tc, obj);
}
}

0 comments on commit 11b846e

Please sign in to comment.