Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[truffle] Stub STables while deserializing
- Loading branch information
Showing
7 changed files
with
125 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.perl6.nqp.truffle.sixmodel; | ||
|
||
/** | ||
* Base of all 6model representations. Has default implementations of functions that | ||
* are not mandatory. | ||
*/ | ||
public abstract class REPR { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/REPRRegistry.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,15 @@ | ||
package org.perl6.nqp.truffle.sixmodel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
import org.perl6.nqp.truffle.sixmodel.reprs.P6opaque; | ||
|
||
public class REPRRegistry { | ||
public static REPR getByName(String name) { | ||
switch (name) { | ||
case "P6opaque": return new P6opaque(); | ||
default: throw new RuntimeException("No REPR " + name); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/STable.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.truffle.sixmodel; | ||
|
||
public class STable { | ||
/** Initializes a new STable. | ||
*/ | ||
public STable(REPR repr, Object how) { | ||
this.repr = repr; | ||
this.how = how; | ||
} | ||
|
||
/** | ||
* The representation operation table. | ||
*/ | ||
public REPR repr; | ||
|
||
/** | ||
* The meta-object. | ||
*/ | ||
public Object how; | ||
|
||
/** | ||
* The type-object. | ||
*/ | ||
public Object what; | ||
|
||
/** | ||
* Serialization context that this s-table belongs to. | ||
*/ | ||
public SerializationContext sc; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/SerializationContext.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,14 +1,59 @@ | ||
package org.perl6.nqp.truffle.sixmodel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
public final class SerializationContext { | ||
/* The handle of this SC. */ | ||
public String handle; | ||
|
||
/* Description (probably the file name) if any. */ | ||
public String description; | ||
|
||
/* The root set of objects that live in this SC. */ | ||
private ArrayList<Object> rootObjects; | ||
|
||
/* The root set of STables that live in this SC. */ | ||
private ArrayList<STable> rootSTables; | ||
|
||
public SerializationContext(String handle) { | ||
this.handle = handle; | ||
this.rootObjects = new ArrayList<Object>(); | ||
this.rootSTables = new ArrayList<STable>(); | ||
} | ||
|
||
public void initSTableList(int entries) { | ||
rootSTables.ensureCapacity(entries); | ||
for (int i = 0; i < entries; i++) | ||
rootSTables.add(null); | ||
} | ||
|
||
private HashMap<STable, Integer> stableIndexCache = new HashMap<STable, Integer>(); | ||
public void addSTable(STable stable) { | ||
int newIndex = rootSTables.size(); | ||
rootSTables.add(stable); | ||
stableIndexCache.put(stable, new Integer(newIndex)); | ||
} | ||
|
||
public void setSTable(int index, STable stable) { | ||
rootSTables.set(index, stable); | ||
stableIndexCache.put(stable, new Integer(index)); | ||
} | ||
|
||
public int getSTableIndex(STable stable) { | ||
Integer cachedIndex = stableIndexCache.get(stable); | ||
if (cachedIndex != null) { | ||
return cachedIndex.intValue(); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
|
||
public STable getSTable(int index) { | ||
return rootSTables.get(index); | ||
} | ||
|
||
public int stableCount() { | ||
return rootSTables.size(); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/reprs/P6opaque.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,6 @@ | ||
package org.perl6.nqp.truffle.sixmodel.reprs; | ||
|
||
import org.perl6.nqp.truffle.sixmodel.REPR; | ||
|
||
public class P6opaque extends REPR { | ||
} |
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