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
Implement CStr REPR on JVM.
- Loading branch information
Showing
2 changed files
with
31 additions
and
3 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
17 changes: 16 additions & 1 deletion
17
src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStrInstance.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 |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| package org.perl6.nqp.sixmodel.reprs; | ||
|
|
||
| import com.sun.jna.Memory; | ||
| import com.sun.jna.Native; | ||
|
|
||
| import org.perl6.nqp.runtime.ThreadContext; | ||
| import org.perl6.nqp.sixmodel.SixModelObject; | ||
|
|
||
| public class CStrInstance extends SixModelObject { | ||
| /* Nothing here yet. */ | ||
| public Memory cstr; | ||
|
|
||
| public void set_str(ThreadContext tc, String value) { | ||
| /* TODO: Handle encodings. */ | ||
| byte[] bytes = Native.toByteArray(value); | ||
| cstr = new Memory(bytes.length); | ||
| cstr.write(0, bytes, 0, bytes.length); | ||
| } | ||
|
|
||
| public String get_str(ThreadContext tc) { | ||
| return cstr.getString(0, Native.getDefaultStringEncoding()); | ||
| } | ||
| } |