Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Extend NativeRef REPR to include attribute refs.
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/NativeRefInstanceAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |