Skip to content

Commit

Permalink
[truffle] Deserialize a bit more things
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Sep 17, 2018
1 parent a01de2a commit 443ee71
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 58 deletions.
Expand Up @@ -35,7 +35,9 @@ public NQPCallmethodNode(NQPNode invocantNode, NQPNode methodNode, long[] argume

@Override
public Object execute(VirtualFrame frame) {
System.out.println("callmethod NYI");
Object invocant = invocantNode.execute(frame);
String method = this.methodNode.executeStr(frame);
System.out.println("callmethod NYI: " + method);
return org.perl6.nqp.truffle.runtime.NQPNull.SINGLETON;
}
}
Expand Down
@@ -1,9 +1,11 @@
package org.perl6.nqp.truffle.nodes.expression;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeInfo;
import java.io.File;
import org.perl6.nqp.truffle.nodes.NQPNode;
import org.perl6.nqp.truffle.nodes.NQPStrNode;
import org.perl6.nqp.dsl.Deserializer;
import org.perl6.nqp.truffle.ByteCodeRunnerGen;

@NodeInfo(shortName = "loadbytecode")
public final class NQPLoadbytecodeNode extends NQPStrNode {
Expand All @@ -16,8 +18,20 @@ public NQPLoadbytecodeNode(NQPNode argNode) {

@Override
public String executeStr(VirtualFrame frame) {
String file = argNode.executeStr(frame);
System.out.println("loadbytecode NYI");
return file;

String fileName = argNode.executeStr(frame);

System.out.println("loadbytecode " + fileName);

File file = new File(fileName);
if (!file.exists() && fileName.equals("ModuleLoader.truffle6")) {
/* We special case the initial ModuleLoader loading. */
System.out.println("We have the initial ModuleLoader");
fileName = "gen/truffle/stage1/" + fileName;
}

(new ByteCodeRunnerGen()).runByteCode(fileName);

return fileName;
}
}
37 changes: 37 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/STable.java
Expand Up @@ -22,6 +22,43 @@ public STable(Object how) {
*/
public Object what;

/**
* Array of type objects. If this is set, then it is expected to contain
* the type objects of all types that this type is equivalent to (e.g.
* all the things it isa and all the things it does).
*/
public Object[] typeCheckCache;

/**
* The type checking mode and method cache mode.
*/
public int modeFlags;

/**
* If this is a container, then this contains information needed in
* order to fetch the value in it. If not, it'll be null, which can
* be taken as a "not a container" indication.
*/
//public ContainerSpec containerSpec;

/**
* If this is invokable, then this contains information needed to
* figure out how to invoke it. If not, it'll be null.
*/
//public InvocationSpec invocationSpec;

/**
* Information - if any - about how we can turn something of this type
* into a boolean.
*/
//public BoolificationSpec BoolificationSpec;

/**
* The underlying package stash.
*/
public Object who;


/**
* Serialization context that this s-table belongs to.
*/
Expand Down
Expand Up @@ -7,6 +7,8 @@
import java.util.Map;
import java.util.HashMap;

import org.perl6.nqp.truffle.runtime.NQPNull;

public class SerializationReader {
/* The current version of the serialization format. */
private final int CURRENT_VERSION = 11;
Expand Down Expand Up @@ -277,9 +279,11 @@ private void resolveDependencies() {
if (desc == null)
desc = handle;

System.out.println("Missing or wrong version of dependency '" + desc + "'");
System.out.println("Missing or wrong version of dependency '" + desc + "' with handle " + handle);
//throw new RuntimeException(
// "Missing or wrong version of dependency '" + desc + "'");
} else {
System.out.println("Found " + desc + ": " + handle);
}
dependentSCs[i] = sc;
}
Expand Down Expand Up @@ -404,38 +408,41 @@ private void stubObjects() {
// }
// }
//
// private void deserializeSTables() {
// for (int i = 0; i < stTableEntries; i++) {
// // Seek to the right position in the data chunk.
// orig.position(stTableOffset + i * STABLES_TABLE_ENTRY_SIZE + 4);
// orig.position(stDataOffset + orig.getInt());
//
// // Get the STable we need to deserialize into.
// STable st = sc.getSTable(i);
//
// // Read the HOW, WHAT and WHO.
// st.HOW = readObjRef();
// st.WHAT = readObjRef();
// st.WHO = readRef();
//
// /* Method cache and v-table. */
// SixModelObject methodCache = readRef();
private void deserializeSTables() {
for (int i = 0; i < stTableEntries; i++) {
// Seek to the right position in the data chunk.
orig.position(stTableOffset + i * STABLES_TABLE_ENTRY_SIZE + 4);
orig.position(stDataOffset + orig.getInt());

// Get the STable we need to deserialize into.
STable st = sc.getSTable(i);

// Read the HOW, WHAT and WHO.
st.how = readObjRef();
st.what = readObjRef();
st.who = readRef();

/* Method cache and v-table. */
Object methodCache = readRef();
// if (methodCache != null)
// st.MethodCache = ((VMHashInstance)methodCache).storage;
// st.VTable = new SixModelObject[(int)orig.getLong()];
// for (int j = 0; j < st.VTable.length; j++)
// st.VTable[j] = readRef();
//
// /* Type check cache. */
// int tcCacheSize = (int)orig.getLong();
// if (tcCacheSize > 0) {
// st.TypeCheckCache = new SixModelObject[tcCacheSize];
// for (int j = 0; j < st.TypeCheckCache.length; j++)
// st.TypeCheckCache[j] = readRef();
// }
//
// /* Mode flags. */
// st.ModeFlags = (int)orig.getLong();

long vtableLength = orig.getLong();

if (vtableLength != 0) {
throw new RuntimeException("VTables shouldn't be ever deserialized");
}

/* Type check cache. */
int typeCheckCacheSize = (int)orig.getLong();
if (typeCheckCacheSize > 0) {
st.typeCheckCache = new Object[typeCheckCacheSize];
for (int j = 0; j < st.typeCheckCache.length; j++)
st.typeCheckCache[j] = readRef();
}

/* Mode flags. */
st.modeFlags = (int)orig.getLong();
//
// /* Boolification spec. */
// if (orig.getLong() != 0) {
Expand Down Expand Up @@ -503,8 +510,8 @@ private void stubObjects() {
//
// /* If the REPR has a function to deserialize representation data, call it. */
// st.REPR.deserialize_repr_data(tc, st, this);
// }
// }
}
}
//
// private void deserializeObjects() {
// for (int i = 0; i < objTableEntries; i++) {
Expand Down Expand Up @@ -599,15 +606,15 @@ private void stubObjects() {
// }
// }
//
// public SixModelObject readRef() {
// short discrim = orig.getShort();
// int elems;
// switch (discrim) {
// case REFVAR_NULL:
// case REFVAR_VM_NULL:
// return null;
// case REFVAR_OBJECT:
// return readObjRef();
public Object readRef() {
short discrim = orig.getShort();
int elems;
switch (discrim) {
case REFVAR_NULL:
case REFVAR_VM_NULL:
return NQPNull.SINGLETON;
case REFVAR_OBJECT:
return readObjRef();
// case REFVAR_VM_INT:
// SixModelObject BOOTInt = tc.gc.BOOTInt;
// SixModelObject iResult = BOOTInt.st.REPR.allocate(tc, BOOTInt.st);
Expand Down Expand Up @@ -671,18 +678,18 @@ private void stubObjects() {
// case REFVAR_STATIC_CODEREF:
// case REFVAR_CLONED_CODEREF:
// return readCodeRef();
// default:
// throw new RuntimeException("Unimplemented case of read_ref");
// }
// }
//
// public SixModelObject readObjRef() {
// SerializationContext sc = locateSC(orig.getInt());
// int idx = orig.getInt();
// if (idx < 0 || idx >= sc.objectCount())
// throw new RuntimeException("Invalid SC object index " + idx);
// return sc.getObject(idx);
// }
default:
throw new RuntimeException("Unimplemented case of read_ref: " + discrim);
}
}

public Object readObjRef() {
SerializationContext sc = locateSC(orig.getInt());
int idx = orig.getInt();
if (idx < 0 || idx >= sc.objectCount())
throw new RuntimeException("Invalid SC object index " + idx);
return sc.getObject(idx);
}
//
// public STable readSTableRef() {
// return lookupSTable(orig.getInt(), orig.getInt());
Expand Down

0 comments on commit 443ee71

Please sign in to comment.