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
Flesh out container ops and code_pair cont.
This gets 67-container.t passing on the JVM.
- Loading branch information
Showing
6 changed files
with
118 additions
and
18 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
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
30 changes: 30 additions & 0 deletions
30
src/vm/jvm/runtime/org/perl6/nqp/sixmodel/CodePairContainerConfigurer.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,30 @@ | ||
| package org.perl6.nqp.sixmodel; | ||
|
|
||
| import org.perl6.nqp.runtime.ExceptionHandling; | ||
| import org.perl6.nqp.runtime.ThreadContext; | ||
|
|
||
| /** | ||
| * A code_pair container uses a pair of methods (fetch/store) to provide the | ||
| * container semantics. | ||
| */ | ||
| public class CodePairContainerConfigurer extends ContainerConfigurer { | ||
| /* Sets this container spec in place for the specified STable. */ | ||
| public void setContainerSpec(ThreadContext tc, STable st) { | ||
| st.ContainerSpec = new CodePairContainerSpec(); | ||
| } | ||
|
|
||
| /* Configures the container spec with the specified info. */ | ||
| public void configureContainerSpec(ThreadContext tc, STable st, SixModelObject config) { | ||
| CodePairContainerSpec cs = (CodePairContainerSpec)st.ContainerSpec; | ||
| SixModelObject fetch = config.at_key_boxed(tc, "fetch"); | ||
| if (fetch == null) | ||
| throw ExceptionHandling.dieInternal(tc, | ||
| "Container spec 'code_pair' must be configured with a fetch"); | ||
| SixModelObject store = config.at_key_boxed(tc, "store"); | ||
| if (store == null) | ||
| throw ExceptionHandling.dieInternal(tc, | ||
| "Container spec 'code_pair' must be configured with a store"); | ||
| cs.fetchCode = fetch; | ||
| cs.storeCode = store; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/vm/jvm/runtime/org/perl6/nqp/sixmodel/CodePairContainerSpec.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,48 @@ | ||
| package org.perl6.nqp.sixmodel; | ||
|
|
||
| import org.perl6.nqp.runtime.Ops; | ||
| import org.perl6.nqp.runtime.ThreadContext; | ||
|
|
||
| /** | ||
| * A code_pair container uses a pair of methods (fetch/store) to provide the | ||
| * container semantics. | ||
| */ | ||
| public class CodePairContainerSpec extends ContainerSpec { | ||
| public SixModelObject fetchCode; | ||
| public SixModelObject storeCode; | ||
|
|
||
| /* Fetches a value out of a container. Used for decontainerization. */ | ||
| public SixModelObject fetch(ThreadContext tc, SixModelObject cont) { | ||
| Ops.invokeDirect(tc, fetchCode, Ops.invocantCallSite, new Object[] { cont }); | ||
| return Ops.result_o(tc.curFrame); | ||
| } | ||
|
|
||
| /* Stores a value in a container. Used for assignment. */ | ||
| public void store(ThreadContext tc, SixModelObject cont, SixModelObject obj) { | ||
| Ops.invokeDirect(tc, storeCode, Ops.storeCallSite, new Object[] { cont, obj }); | ||
| } | ||
|
|
||
| /* Stores a value in a container, without any checking of it (this | ||
| * assumes an optimizer or something else already did it). Used for | ||
| * assignment. */ | ||
| public void storeUnchecked(ThreadContext tc, SixModelObject cont, SixModelObject obj) { | ||
| store(tc, cont, obj); | ||
| } | ||
|
|
||
| /* Name of this container specification. */ | ||
| public String name() { | ||
| return "code_pair"; | ||
| } | ||
|
|
||
| /* Serializes the container data, if any. */ | ||
| public void serialize(ThreadContext tc, STable st, SerializationWriter writer) { | ||
| writer.writeRef(fetchCode); | ||
| writer.writeRef(storeCode); | ||
| } | ||
|
|
||
| /* Deserializes the container data, if any. */ | ||
| public void deserialize(ThreadContext tc, STable st, SerializationReader reader) { | ||
| fetchCode = reader.readRef(); | ||
| storeCode = reader.readRef(); | ||
| } | ||
| } |
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
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