Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial preparations for container handling.
This rips out the port of a previous approach, stubs the current one
that is needed for Rakudo, and updates the serializer for it.
  • Loading branch information
jnthn committed May 10, 2013
1 parent ef11486 commit 866fe1a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 28 deletions.
8 changes: 8 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;

import org.perl6.nqp.sixmodel.ContainerConfigurer;
import org.perl6.nqp.sixmodel.KnowHOWBootstrapper;
import org.perl6.nqp.sixmodel.SerializationContext;
import org.perl6.nqp.sixmodel.SixModelObject;
Expand Down Expand Up @@ -121,6 +122,11 @@ public class GlobalContext {
*/
public HashMap<String, SixModelObject> compilerRegistry;

/**
* Container configurer registry.
*/
public HashMap<String, ContainerConfigurer> contConfigs;

/**
* Serialization context lookup hash.
*/
Expand Down Expand Up @@ -148,6 +154,8 @@ public GlobalContext()
compilerRegistry = new HashMap<String, SixModelObject>();
hllSyms = new HashMap<String, HashMap<String, SixModelObject>>();

contConfigs = new HashMap<String, ContainerConfigurer>();

mainThread = new ThreadContext(this);
KnowHOWBootstrapper.bootstrap(mainThread);

Expand Down
14 changes: 14 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/ContainerConfigurer.java
@@ -0,0 +1,14 @@
package org.perl6.nqp.sixmodel;
import org.perl6.nqp.runtime.ThreadContext;

/**
* A container configurer knows how to attach a certain type of container
* to an STable and configure it.
*/
public abstract class ContainerConfigurer {
/* Sets this container spec in place for the specified STable. */
public abstract void setContainerSpec(ThreadContext tc, STable st);

/* Configures the container spec with the specified info. */
public abstract void configureContainerSpec(ThreadContext tc, STable st, SixModelObject config);
}
39 changes: 20 additions & 19 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/ContainerSpec.java
@@ -1,27 +1,28 @@
package org.perl6.nqp.sixmodel;
import org.perl6.nqp.runtime.ThreadContext;

/**
* Language interop information that we hold if the type is declaring a
* container of some sort.
* A scalar container has a ContainerSpec hung off its STable. It should be a
* subclass of this abstract base class.
*/
public class ContainerSpec {
/**
* Class handle where we find the contained value.
*/
SixModelObject ClassHandle;
public abstract class ContainerSpec {
/* Fetches a value out of a container. Used for decontainerization. */
public abstract SixModelObject fetch(ThreadContext tc, SixModelObject cont);

/**
* Attribute name where we find the contained value.
*/
String AttrName;
/* Stores a value in a container. Used for assignment. */
public abstract void store(ThreadContext tc, SixModelObject cont, SixModelObject obj);

/**
* Attribute lookup hint used in gradual typing.
*/
int Hint;
/* 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 abstract void storeUnchecked(ThreadContext tc, SixModelObject cont, SixModelObject obj);

/**
* FETCH method if applicable.
*/
SixModelObject FetchMethod;
/* Name of this container specification. */
public String name;

/* Serializes the container data, if any. */
public abstract void serialize(ThreadContext tc, STable st, SerializationWriter writer);

/* Deserializes the container data, if any. */
public abstract void deserialize(ThreadContext tc, STable st, SerializationReader reader);
}
16 changes: 11 additions & 5 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/SerializationReader.java
Expand Up @@ -328,11 +328,17 @@ private void deserializeSTables() {

/* Container spec. */
if (orig.getLong() != 0) {
st.ContainerSpec = new ContainerSpec();
st.ContainerSpec.ClassHandle = readRef();
st.ContainerSpec.AttrName = lookupString(orig.getInt());
st.ContainerSpec.Hint = (int)orig.getLong();
st.ContainerSpec.FetchMethod = readRef();
if (version >= 5) {
String ccName = readStr();
ContainerConfigurer cc = tc.gc.contConfigs.get(ccName);
if (cc == null)
throw new RuntimeException("Unknown container config " + ccName);
cc.setContainerSpec(tc, st);
st.ContainerSpec.deserialize(tc, st, this);
}
else {
throw new RuntimeException("Unable to deserialize old container spec format");
}
}

/* Invocation spec. */
Expand Down
Expand Up @@ -533,10 +533,8 @@ private void serializeStable(STable st) {
/* Container spec. */
writeInt(st.ContainerSpec == null ? 0 : 1);
if (st.ContainerSpec != null) {
writeRef(st.ContainerSpec.ClassHandle);
writeStr(st.ContainerSpec.AttrName);
writeInt(st.ContainerSpec.Hint);
writeRef(st.ContainerSpec.FetchMethod);
writeStr(st.ContainerSpec.name);
st.ContainerSpec.serialize(tc, st, this);
}

/* Invocation spec. */
Expand Down

0 comments on commit 866fe1a

Please sign in to comment.