Skip to content

Commit

Permalink
Get BOOTInt and BOOTNum in place.
Browse files Browse the repository at this point in the history
Also a small refactor to avoid some code duplication.
  • Loading branch information
jnthn committed Dec 23, 2012
1 parent bc84245 commit 2fc7df2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
16 changes: 13 additions & 3 deletions src/org/perl6/nqp/runtime/GlobalContext.java
Expand Up @@ -15,17 +15,27 @@ public class GlobalContext {
public SixModelObject KnowHOWAttribute;

/**
* BOOTArray type; a very bare type with the VMArray REPR.
* BOOTArray type; a basic, method-less type with the VMArray REPR.
*/
public SixModelObject BOOTArray;

/**
* BOOTHash type; a very bare type with the VMHash REPR.
* BOOTHash type; a basic, method-less type with the VMHash REPR.
*/
public SixModelObject BOOTHash;

/**
* BOOTHash type; a very bare type with the P6str REPR.
* BOOTInt type; a basic, method-less type with the P6int REPR.
*/
public SixModelObject BOOTInt;

/**
* BOOTNum type; a basic, method-less type with the P6num REPR.
*/
public SixModelObject BOOTNum;

/**
* BOOTStr type; a basic, method-less type with the P6str REPR.
*/
public SixModelObject BOOTStr;

Expand Down
42 changes: 10 additions & 32 deletions src/org/perl6/nqp/sixmodel/KnowHOWBootstrapper.java
Expand Up @@ -10,9 +10,11 @@ public static void bootstrap(ThreadContext tc)
knowhowUnit.initializeCompilationUnit();
bootstrapKnowHOW(tc, knowhowUnit);
bootstrapKnowHOWAttribute(tc, knowhowUnit);
bootArray(tc);
bootHash(tc);
bootStr(tc);
tc.gc.BOOTArray = bootType(tc, "BOOTArray", "VMArray");
tc.gc.BOOTHash = bootType(tc, "BOOTHash", "VMHash");
tc.gc.BOOTInt = bootType(tc, "BOOTInt", "P6int");
tc.gc.BOOTNum = bootType(tc, "BOOTNum", "P6num");
tc.gc.BOOTStr = bootType(tc, "BOOTStr", "P6str");
}

private static void bootstrapKnowHOW(ThreadContext tc, CompilationUnit knowhowUnit) {
Expand Down Expand Up @@ -88,40 +90,16 @@ private static void bootstrapKnowHOWAttribute(ThreadContext tc, CompilationUnit
/* Stash the created type object. */
tc.gc.KnowHOWAttribute = type_obj;
}

private static void bootArray(ThreadContext tc) {
SixModelObject knowhow_how = tc.gc.KnowHOW.st.HOW;
KnowHOWREPRInstance meta_obj = (KnowHOWREPRInstance)knowhow_how.st.REPR.allocate(tc, knowhow_how.st);
meta_obj.initialize(tc);
meta_obj.name = "BOOTArray";
REPR repr = REPRRegistry.getByName("VMArray");
SixModelObject type_obj = repr.type_object_for(tc, meta_obj);
type_obj.st.MethodCache = meta_obj.methods;
type_obj.st.ModeFlags = STable.METHOD_CACHE_AUTHORITATIVE;
tc.gc.BOOTArray = type_obj;
}

private static void bootHash(ThreadContext tc) {
SixModelObject knowhow_how = tc.gc.KnowHOW.st.HOW;
KnowHOWREPRInstance meta_obj = (KnowHOWREPRInstance)knowhow_how.st.REPR.allocate(tc, knowhow_how.st);
meta_obj.initialize(tc);
meta_obj.name = "BOOTHash";
REPR repr = REPRRegistry.getByName("VMHash");
SixModelObject type_obj = repr.type_object_for(tc, meta_obj);
type_obj.st.MethodCache = meta_obj.methods;
type_obj.st.ModeFlags = STable.METHOD_CACHE_AUTHORITATIVE;
tc.gc.BOOTHash = type_obj;
}

private static void bootStr(ThreadContext tc) {
SixModelObject knowhow_how = tc.gc.KnowHOW.st.HOW;
private static SixModelObject bootType(ThreadContext tc, String typeName, String reprName) {
SixModelObject knowhow_how = tc.gc.KnowHOW.st.HOW;
KnowHOWREPRInstance meta_obj = (KnowHOWREPRInstance)knowhow_how.st.REPR.allocate(tc, knowhow_how.st);
meta_obj.initialize(tc);
meta_obj.name = "BOOTStr";
REPR repr = REPRRegistry.getByName("P6str");
meta_obj.name = typeName;
REPR repr = REPRRegistry.getByName(reprName);
SixModelObject type_obj = repr.type_object_for(tc, meta_obj);
type_obj.st.MethodCache = meta_obj.methods;
type_obj.st.ModeFlags = STable.METHOD_CACHE_AUTHORITATIVE;
tc.gc.BOOTStr = type_obj;
return type_obj;
}
}

0 comments on commit 2fc7df2

Please sign in to comment.