Skip to content
Browse files

Move Rakudo global state into a GlobalContext extension

  • Loading branch information...
1 parent 98a5e56 commit 76f8db7c740b7d902473d350f27f5f2d035c302f @sorear sorear committed
View
3 src/vm/jvm/Perl6/Ops.nqp
@@ -119,8 +119,9 @@ my $p6bool := -> $qastcomp, $op {
$il.append(JAST::PushIVal.new( :value(0) ));
$il.append(JAST::Instruction.new( :op('lcmp') ));
}
+ $il.append(JAST::Instruction.new( :op('aload'), 'tc' ));
$il.append(JAST::Instruction.new( :op('invokestatic'),
- $TYPE_P6OPS, 'booleanize', $TYPE_SMO, 'I' ));
+ $TYPE_P6OPS, 'booleanize', $TYPE_SMO, 'I', $TYPE_TC ));
$ops.result($il, $RT_OBJ);
};
$ops.add_hll_op('perl6', 'p6bool', $p6bool);
View
114 src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
@@ -65,20 +65,20 @@
private static final int HINT_CAPTURE_hash = 1;
private static final int HINT_SIG_params = 0;
- private static SixModelObject createBox(ThreadContext tc, Object arg, int flag) {
+ private static SixModelObject createBox(ThreadContext tc, Ops.GlobalExt gcx, Object arg, int flag) {
switch (flag) {
case CallSiteDescriptor.ARG_INT:
- return org.perl6.nqp.runtime.Ops.box_i((long)arg, Ops.Int, tc);
+ return org.perl6.nqp.runtime.Ops.box_i((long)arg, gcx.Int, tc);
case CallSiteDescriptor.ARG_NUM:
- return org.perl6.nqp.runtime.Ops.box_n((double)arg, Ops.Num, tc);
+ return org.perl6.nqp.runtime.Ops.box_n((double)arg, gcx.Num, tc);
case CallSiteDescriptor.ARG_STR:
- return org.perl6.nqp.runtime.Ops.box_s((String)arg, Ops.Str, tc);
+ return org.perl6.nqp.runtime.Ops.box_s((String)arg, gcx.Str, tc);
default:
throw new RuntimeException("Impossible case reached in createBox");
}
}
- private static String arityFail(ThreadContext tc, SixModelObject params,
+ private static String arityFail(ThreadContext tc, Ops.GlobalExt gcx, SixModelObject params,
int numParams, int numPosArgs, boolean tooMany) {
int arity = 0;
int count = 0;
@@ -87,10 +87,10 @@ private static String arityFail(ThreadContext tc, SixModelObject params,
/* Work out how many we could have been passed. */
for (int i = 0; i < numParams; i++) {
SixModelObject param = params.at_pos_boxed(tc, i);
- param.get_attribute_native(tc, Ops.Parameter, "$!flags", HINT_flags);
+ param.get_attribute_native(tc, gcx.Parameter, "$!flags", HINT_flags);
int flags = (int)tc.native_i;
SixModelObject namedNames = param.get_attribute_boxed(tc,
- Ops.Parameter, "$!named_names", HINT_named_names);
+ gcx.Parameter, "$!named_names", HINT_named_names);
if (namedNames != null)
continue;
@@ -124,8 +124,8 @@ else if (count == -1)
}
/* Returns an appropriate failure mode (junction fail or normal fail). */
- private static int junc_or_fail(SixModelObject value) {
- if (value.st.WHAT == Ops.Junction)
+ private static int junc_or_fail(Ops.GlobalExt gcx, SixModelObject value) {
+ if (value.st.WHAT == gcx.Junction)
return BIND_RESULT_JUNCTION;
else
return BIND_RESULT_FAIL;
@@ -144,12 +144,12 @@ public static void bindTypeCaptures(ThreadContext tc, SixModelObject typeCaps, C
/* Binds a single argument into the lexpad, after doing any checks that are
* needed. Also handles any type captures. If there is a sub signature, then
* re-enters the binder. Returns one of the BIND_RESULT_* codes. */
- private static int bindOneParam(ThreadContext tc, CallFrame cf, SixModelObject param,
+ private static int bindOneParam(ThreadContext tc, Ops.GlobalExt gcx, CallFrame cf, SixModelObject param,
Object origArg, byte origFlag, boolean noNomTypeCheck, String[] error) {
/* Get parameter flags and variable name. */
- param.get_attribute_native(tc, Ops.Parameter, "$!flags", HINT_flags);
+ param.get_attribute_native(tc, gcx.Parameter, "$!flags", HINT_flags);
int paramFlags = (int)tc.native_i;
- param.get_attribute_native(tc, Ops.Parameter, "$!variable_name", HINT_variable_name);
+ param.get_attribute_native(tc, gcx.Parameter, "$!variable_name", HINT_variable_name);
String varName = tc.native_s;
if (Ops.DEBUG_MODE)
System.err.println(varName);
@@ -184,7 +184,7 @@ else if (desiredNative == SIG_ELEM_NATIVE_STR_VALUE && gotNative == CallSiteDesc
else if (desiredNative == 0) {
/* We need to do a boxing operation. */
flag = CallSiteDescriptor.ARG_OBJ;
- arg_o = createBox(tc, origArg, gotNative);
+ arg_o = createBox(tc, gcx, origArg, gotNative);
}
else {
/* We need to do an unboxing opeation. */
@@ -258,7 +258,7 @@ else if (desiredNative == 0) {
}
/* Type captures. */
- SixModelObject typeCaps = param.get_attribute_boxed(tc, Ops.Parameter,
+ SixModelObject typeCaps = param.get_attribute_boxed(tc, gcx.Parameter,
"$!type_captures", HINT_type_captures);
if (typeCaps != null)
bindTypeCaptures(tc, typeCaps, cf, decontValue.st.WHAT);
@@ -319,13 +319,13 @@ else if ((paramFlags & SIG_ELEM_HASH_SIGIL) != 0) {
* container and store it, for copy or ro case (the rw bit
* in the container descriptor takes care of the rest). */
else {
- STable stScalar = Ops.Scalar.st;
+ STable stScalar = gcx.Scalar.st;
SixModelObject new_cont = stScalar.REPR.allocate(tc, stScalar);
- SixModelObject desc = param.get_attribute_boxed(tc, Ops.Parameter,
+ SixModelObject desc = param.get_attribute_boxed(tc, gcx.Parameter,
"$!container_descriptor", HINT_container_descriptor);
- new_cont.bind_attribute_boxed(tc, Ops.Scalar, "$!descriptor",
+ new_cont.bind_attribute_boxed(tc, gcx.Scalar, "$!descriptor",
RakudoContainerSpec.HINT_descriptor, desc);
- new_cont.bind_attribute_boxed(tc, Ops.Scalar, "$!value",
+ new_cont.bind_attribute_boxed(tc, gcx.Scalar, "$!value",
RakudoContainerSpec.HINT_value, decontValue);
cf.oLex[sci.oTryGetLexicalIdx(varName)] = new_cont;
}
@@ -340,7 +340,7 @@ else if ((paramFlags & SIG_ELEM_HASH_SIGIL) != 0) {
/* TODO: attributives. */
- SixModelObject subSignature = param.get_attribute_boxed(tc, Ops.Parameter,
+ SixModelObject subSignature = param.get_attribute_boxed(tc, gcx.Parameter,
"$!sub_signature", HINT_sub_signature);
/* If it has a sub-signature, bind that. */
@@ -363,10 +363,10 @@ else if ((paramFlags & SIG_ELEM_HASH_SIGIL) != 0) {
}
SixModelObject subParams = subSignature
- .get_attribute_boxed(tc, Ops.Signature, "$!params", HINT_SIG_params);
+ .get_attribute_boxed(tc, gcx.Signature, "$!params", HINT_SIG_params);
/* Recurse into signature binder. */
- CallSiteDescriptor subCsd = explodeCapture(tc, capture);
- result = bind(tc, cf, subParams, subCsd, tc.flatArgs, noNomTypeCheck, error);
+ CallSiteDescriptor subCsd = explodeCapture(tc, gcx, capture);
+ result = bind(tc, gcx, cf, subParams, subCsd, tc.flatArgs, noNomTypeCheck, error);
if (result != BIND_RESULT_OK)
{
if (error != null) {
@@ -392,10 +392,10 @@ else if ((paramFlags & SIG_ELEM_HASH_SIGIL) != 0) {
CallSiteDescriptor.ARG_OBJ | CallSiteDescriptor.ARG_FLAT,
CallSiteDescriptor.ARG_OBJ | CallSiteDescriptor.ARG_FLAT | CallSiteDescriptor.ARG_NAMED
}, null);
- private static CallSiteDescriptor explodeCapture(ThreadContext tc, SixModelObject capture) {
+ private static CallSiteDescriptor explodeCapture(ThreadContext tc, Ops.GlobalExt gcx, SixModelObject capture) {
capture = org.perl6.nqp.runtime.Ops.decont(capture, tc);
- SixModelObject capType = Ops.Capture;
+ SixModelObject capType = gcx.Capture;
SixModelObject list = capture.get_attribute_boxed(tc, capType, "$!list", HINT_CAPTURE_list);
SixModelObject hash = capture.get_attribute_boxed(tc, capType, "$!hash", HINT_CAPTURE_hash);
@@ -404,16 +404,16 @@ private static CallSiteDescriptor explodeCapture(ThreadContext tc, SixModelObjec
/* This takes a signature element and either runs the closure to get a default
* value if there is one, or creates an appropriate undefined-ish thingy. */
- private static SixModelObject handleOptional(ThreadContext tc, int flags, SixModelObject param, CallFrame cf) {
+ private static SixModelObject handleOptional(ThreadContext tc, Ops.GlobalExt gcx, int flags, SixModelObject param, CallFrame cf) {
/* Is the "get default from outer" flag set? */
if ((flags & SIG_ELEM_DEFAULT_FROM_OUTER) != 0) {
- param.get_attribute_native(tc, Ops.Parameter, "$!variable_name", HINT_variable_name);
+ param.get_attribute_native(tc, gcx.Parameter, "$!variable_name", HINT_variable_name);
String varName = tc.native_s;
return cf.outer.oLex[cf.outer.codeRef.staticInfo.oTryGetLexicalIdx(varName)];
}
/* Do we have a default value or value closure? */
- SixModelObject defaultValue = param.get_attribute_boxed(tc, Ops.Parameter,
+ SixModelObject defaultValue = param.get_attribute_boxed(tc, gcx.Parameter,
"$!default_value", HINT_default_value);
if (defaultValue != null) {
if ((flags & SIG_ELEM_DEFAULT_IS_LITERAL) != 0) {
@@ -429,14 +429,14 @@ private static SixModelObject handleOptional(ThreadContext tc, int flags, SixMod
/* Otherwise, go by sigil to pick the correct default type of value. */
else {
if ((flags & SIG_ELEM_ARRAY_SIGIL) != 0) {
- return Ops.p6list(null, Ops.Array, Ops.True, tc);
+ return Ops.p6list(null, gcx.Array, gcx.True, tc);
}
else if ((flags & SIG_ELEM_HASH_SIGIL) != 0) {
- SixModelObject res = Ops.Hash.st.REPR.allocate(tc, Ops.Hash.st);
+ SixModelObject res = gcx.Hash.st.REPR.allocate(tc, gcx.Hash.st);
return res;
}
else {
- return param.get_attribute_boxed(tc, Ops.Parameter, "$!nominal_type", HINT_nominal_type);
+ return param.get_attribute_boxed(tc, gcx.Parameter, "$!nominal_type", HINT_nominal_type);
}
}
}
@@ -445,7 +445,7 @@ else if ((flags & SIG_ELEM_HASH_SIGIL) != 0) {
* into the provided callframe. Returns BIND_RESULT_OK if binding works out,
* BIND_RESULT_FAIL if there is a failure and BIND_RESULT_JUNCTION if the
* failure was because of a Junction being passed (meaning we need to auto-thread). */
- public static int bind(ThreadContext tc, CallFrame cf, SixModelObject params,
+ public static int bind(ThreadContext tc, Ops.GlobalExt gcx, CallFrame cf, SixModelObject params,
CallSiteDescriptor csd, Object[] args,
boolean noNomTypeCheck, String[] error) {
int bindFail = BIND_RESULT_OK;
@@ -469,22 +469,22 @@ public static int bind(ThreadContext tc, CallFrame cf, SixModelObject params,
for (long i = 0; i < numParams; i++) {
/* Get parameter, its flags and any named names. */
SixModelObject param = params.at_pos_boxed(tc, i);
- param.get_attribute_native(tc, Ops.Parameter, "$!flags", HINT_flags);
+ param.get_attribute_native(tc, gcx.Parameter, "$!flags", HINT_flags);
int flags = (int)tc.native_i;
SixModelObject namedNames = param.get_attribute_boxed(tc,
- Ops.Parameter, "$!named_names", HINT_named_names);
+ gcx.Parameter, "$!named_names", HINT_named_names);
/* Is it looking for us to bind a capture here? */
if ((flags & SIG_ELEM_IS_CAPTURE) != 0) {
/* Capture the arguments from this point forwards into a Capture.
* Of course, if there's no variable name we can (cheaply) do pretty
* much nothing. */
- param.get_attribute_native(tc, Ops.Parameter, "$!variable_name", HINT_variable_name);
+ param.get_attribute_native(tc, gcx.Parameter, "$!variable_name", HINT_variable_name);
if (tc.native_s == null) {
bindFail = BIND_RESULT_OK;
}
else {
- SixModelObject posArgs = Ops.EMPTYARR.clone(tc);
+ SixModelObject posArgs = gcx.EMPTYARR.clone(tc);
for (int k = curPosArg; k < numPosArgs; k++) {
switch (csd.argFlags[k]) {
case CallSiteDescriptor.ARG_OBJ:
@@ -501,14 +501,14 @@ public static int bind(ThreadContext tc, CallFrame cf, SixModelObject params,
break;
}
}
- SixModelObject namedArgs = vmHashOfRemainingNameds(tc, namedArgsCopy, args);
+ SixModelObject namedArgs = vmHashOfRemainingNameds(tc, gcx, namedArgsCopy, args);
- SixModelObject capType = Ops.Capture;
+ SixModelObject capType = gcx.Capture;
SixModelObject capSnap = capType.st.REPR.allocate(tc, capType.st);
capSnap.bind_attribute_boxed(tc, capType, "$!list", HINT_CAPTURE_list, posArgs);
capSnap.bind_attribute_boxed(tc, capType, "$!hash", HINT_CAPTURE_hash, namedArgs);
- bindFail = bindOneParam(tc, cf, param, capSnap, CallSiteDescriptor.ARG_OBJ,
+ bindFail = bindOneParam(tc, gcx, cf, param, capSnap, CallSiteDescriptor.ARG_OBJ,
noNomTypeCheck, error);
}
if (bindFail != 0) {
@@ -522,7 +522,7 @@ else if (i + 1 == numParams) {
}
else {
SixModelObject nextParam = params.at_pos_boxed(tc, i + 1);
- nextParam.get_attribute_native(tc, Ops.Parameter, "$!flags", HINT_flags);
+ nextParam.get_attribute_native(tc, gcx.Parameter, "$!flags", HINT_flags);
if (((int)tc.native_i & (SIG_ELEM_SLURPY_POS | SIG_ELEM_SLURPY_NAMED)) != 0)
suppressArityFail = true;
}
@@ -530,11 +530,11 @@ else if (i + 1 == numParams) {
/* Could it be a named slurpy? */
else if ((flags & SIG_ELEM_SLURPY_NAMED) != 0) {
- SixModelObject slurpy = vmHashOfRemainingNameds(tc, namedArgsCopy, args);
- SixModelObject bindee = Ops.Hash.st.REPR.allocate(tc, Ops.Hash.st);
- bindee.bind_attribute_boxed(tc, Ops.EnumMap, "$!storage",
+ SixModelObject slurpy = vmHashOfRemainingNameds(tc, gcx, namedArgsCopy, args);
+ SixModelObject bindee = gcx.Hash.st.REPR.allocate(tc, gcx.Hash.st);
+ bindee.bind_attribute_boxed(tc, gcx.EnumMap, "$!storage",
HINT_ENUMMAP_storage, slurpy);
- bindFail = bindOneParam(tc, cf, param, bindee, CallSiteDescriptor.ARG_OBJ,
+ bindFail = bindOneParam(tc, gcx, cf, param, bindee, CallSiteDescriptor.ARG_OBJ,
noNomTypeCheck, error);
if (bindFail != 0)
return bindFail;
@@ -550,7 +550,7 @@ else if (namedNames == null) {
if ((flags & (SIG_ELEM_SLURPY_POS | SIG_ELEM_SLURPY_LOL)) != 0) {
/* Create Perl 6 array, create VM array of all remaining things,
* then store it. */
- SixModelObject slurpy = Ops.EMPTYARR.clone(tc);
+ SixModelObject slurpy = gcx.EMPTYARR.clone(tc);
while (curPosArg < numPosArgs) {
switch (csd.argFlags[curPosArg]) {
case CallSiteDescriptor.ARG_OBJ:
@@ -572,15 +572,15 @@ else if (namedNames == null) {
SixModelObject bindee;
if ((flags & SIG_ELEM_SLURPY_POS) != 0) {
if ((flags & SIG_ELEM_IS_RW) != 0)
- bindee = Ops.p6list(slurpy, Ops.List, Ops.True, tc);
+ bindee = Ops.p6list(slurpy, gcx.List, gcx.True, tc);
else
- bindee = Ops.p6list(slurpy, Ops.Array, Ops.True, tc);
+ bindee = Ops.p6list(slurpy, gcx.Array, gcx.True, tc);
}
else {
- bindee = Ops.p6list(slurpy, Ops.LoL, Ops.False, tc);
+ bindee = Ops.p6list(slurpy, gcx.LoL, gcx.False, tc);
}
- bindFail = bindOneParam(tc, cf, param, bindee, CallSiteDescriptor.ARG_OBJ,
+ bindFail = bindOneParam(tc, gcx, cf, param, bindee, CallSiteDescriptor.ARG_OBJ,
noNomTypeCheck, error);
if (bindFail != 0)
return bindFail;
@@ -591,7 +591,7 @@ else if (namedNames == null) {
/* Do we have a value?. */
if (curPosArg < numPosArgs) {
/* Easy - just bind that. */
- bindFail = bindOneParam(tc, cf, param, args[curPosArg],
+ bindFail = bindOneParam(tc, gcx, cf, param, args[curPosArg],
csd.argFlags[curPosArg], noNomTypeCheck, error);
if (bindFail != 0)
return bindFail;
@@ -602,15 +602,15 @@ else if (namedNames == null) {
* if not, we're screwed. Note that we never nominal type check
* an optional with no value passed. */
if ((flags & SIG_ELEM_IS_OPTIONAL) != 0) {
- bindFail = bindOneParam(tc, cf, param,
- handleOptional(tc, flags, param, cf),
+ bindFail = bindOneParam(tc, gcx, cf, param,
+ handleOptional(tc, gcx, flags, param, cf),
CallSiteDescriptor.ARG_OBJ, false, error);
if (bindFail != 0)
return bindFail;
}
else {
if (error != null)
- error[0] = arityFail(tc, params, (int)numParams, numPosArgs, false);
+ error[0] = arityFail(tc, gcx, params, (int)numParams, numPosArgs, false);
return BIND_RESULT_FAIL;
}
}
@@ -635,8 +635,8 @@ else if (namedNames == null) {
if (lookup == null) {
/* Nope. We'd better hope this param was optional... */
if ((flags & SIG_ELEM_IS_OPTIONAL) != 0) {
- bindFail = bindOneParam(tc, cf, param,
- handleOptional(tc, flags, param, cf),
+ bindFail = bindOneParam(tc, gcx, cf, param,
+ handleOptional(tc, gcx, flags, param, cf),
CallSiteDescriptor.ARG_OBJ, false, error);
}
else if (!suppressArityFail) {
@@ -648,7 +648,7 @@ else if (!suppressArityFail) {
}
}
else {
- bindFail = bindOneParam(tc, cf, param, args[lookup >> 3],
+ bindFail = bindOneParam(tc, gcx, cf, param, args[lookup >> 3],
(byte)(lookup & 7), noNomTypeCheck, error);
}
@@ -663,8 +663,8 @@ else if (!suppressArityFail) {
}
/* Takes any nameds we didn't capture yet and makes a VM Hash of them. */
- private static SixModelObject vmHashOfRemainingNameds(ThreadContext tc, HashMap<String, Integer> namedArgsCopy, Object[] args) {
- SixModelObject slurpy = Ops.Mu;
+ private static SixModelObject vmHashOfRemainingNameds(ThreadContext tc, Ops.GlobalExt gcx, HashMap<String, Integer> namedArgsCopy, Object[] args) {
+ SixModelObject slurpy = gcx.Mu;
if (namedArgsCopy != null) {
SixModelObject BOOTHash = tc.gc.BOOTHash;
slurpy = BOOTHash.st.REPR.allocate(tc, BOOTHash.st);
View
208 src/vm/jvm/runtime/org/perl6/rakudo/Ops.java
@@ -10,32 +10,43 @@
*/
public final class Ops {
public static final boolean DEBUG_MODE = false;
-
- public static SixModelObject Mu;
- public static SixModelObject Parcel;
- public static SixModelObject Code;
- public static SixModelObject Routine;
- public static SixModelObject Signature;
- public static SixModelObject Parameter;
- public static SixModelObject Int;
- public static SixModelObject Num;
- public static SixModelObject Str;
- public static SixModelObject List;
- public static SixModelObject ListIter;
- public static SixModelObject Array;
- public static SixModelObject LoL;
- public static SixModelObject EnumMap;
- public static SixModelObject Hash;
- public static SixModelObject Junction;
- public static SixModelObject Scalar;
- public static SixModelObject Capture;
- public static SixModelObject ContainerDescriptor;
- public static SixModelObject False;
- public static SixModelObject True;
- public static SixModelObject AutoThreader;
- public static SixModelObject EMPTYARR;
- private static boolean initialized = false;
-
+
+ public static class ThreadExt {
+ // not currently used
+ public ThreadExt(ThreadContext tc) { }
+ }
+
+ public static class GlobalExt {
+ public SixModelObject Mu;
+ public SixModelObject Parcel;
+ public SixModelObject Code;
+ public SixModelObject Routine;
+ public SixModelObject Signature;
+ public SixModelObject Parameter;
+ public SixModelObject Int;
+ public SixModelObject Num;
+ public SixModelObject Str;
+ public SixModelObject List;
+ public SixModelObject ListIter;
+ public SixModelObject Array;
+ public SixModelObject LoL;
+ public SixModelObject EnumMap;
+ public SixModelObject Hash;
+ public SixModelObject Junction;
+ public SixModelObject Scalar;
+ public SixModelObject Capture;
+ public SixModelObject ContainerDescriptor;
+ public SixModelObject False;
+ public SixModelObject True;
+ public SixModelObject AutoThreader;
+ public SixModelObject EMPTYARR;
+ boolean initialized;
+
+ public GlobalExt(ThreadContext tc) { }
+ }
+
+ public static ContextKey<ThreadExt, GlobalExt> key = new ContextKey< >(ThreadExt.class, GlobalExt.class);
+
/* Parameter hints for fast lookups. */
private static final int HINT_PARCEL_STORAGE = 0;
private static final int HINT_CODE_DO = 0;
@@ -52,86 +63,96 @@
private static final int HINT_LISTITER_list = 3;
public static SixModelObject p6init(ThreadContext tc) {
- if (!initialized) {
+ GlobalExt gcx = key.getGC(tc);
+ if (!gcx.initialized) {
tc.gc.contConfigs.put("rakudo_scalar", new RakudoContainerConfigurer());
SixModelObject BOOTArray = tc.gc.BOOTArray;
- EMPTYARR = BOOTArray.st.REPR.allocate(tc, BOOTArray.st);
- initialized = true;
+ gcx.EMPTYARR = BOOTArray.st.REPR.allocate(tc, BOOTArray.st);
+ gcx.initialized = true;
}
return null;
}
public static SixModelObject p6settypes(SixModelObject conf, ThreadContext tc) {
- Mu = conf.at_key_boxed(tc, "Mu");
- Parcel = conf.at_key_boxed(tc, "Parcel");
- Code = conf.at_key_boxed(tc, "Code");
- Routine = conf.at_key_boxed(tc, "Routine");
- Signature = conf.at_key_boxed(tc, "Signature");
- Parameter = conf.at_key_boxed(tc, "Parameter");
- Int = conf.at_key_boxed(tc, "Int");
- Num = conf.at_key_boxed(tc, "Num");
- Str = conf.at_key_boxed(tc, "Str");
- List = conf.at_key_boxed(tc, "List");
- ListIter = conf.at_key_boxed(tc, "ListIter");
- Array = conf.at_key_boxed(tc, "Array");
- LoL = conf.at_key_boxed(tc, "LoL");
- EnumMap = conf.at_key_boxed(tc, "EnumMap");
- Hash = conf.at_key_boxed(tc, "Hash");
- Junction = conf.at_key_boxed(tc, "Junction");
- Scalar = conf.at_key_boxed(tc, "Scalar");
- Capture = conf.at_key_boxed(tc, "Capture");
- ContainerDescriptor = conf.at_key_boxed(tc, "ContainerDescriptor");
- False = conf.at_key_boxed(tc, "False");
- True = conf.at_key_boxed(tc, "True");
+ GlobalExt gcx = key.getGC(tc);
+ gcx.Mu = conf.at_key_boxed(tc, "Mu");
+ gcx.Parcel = conf.at_key_boxed(tc, "Parcel");
+ gcx.Code = conf.at_key_boxed(tc, "Code");
+ gcx.Routine = conf.at_key_boxed(tc, "Routine");
+ gcx.Signature = conf.at_key_boxed(tc, "Signature");
+ gcx.Parameter = conf.at_key_boxed(tc, "Parameter");
+ gcx.Int = conf.at_key_boxed(tc, "Int");
+ gcx.Num = conf.at_key_boxed(tc, "Num");
+ gcx.Str = conf.at_key_boxed(tc, "Str");
+ gcx.List = conf.at_key_boxed(tc, "List");
+ gcx.ListIter = conf.at_key_boxed(tc, "ListIter");
+ gcx.Array = conf.at_key_boxed(tc, "Array");
+ gcx.LoL = conf.at_key_boxed(tc, "LoL");
+ gcx.EnumMap = conf.at_key_boxed(tc, "EnumMap");
+ gcx.Hash = conf.at_key_boxed(tc, "Hash");
+ gcx.Junction = conf.at_key_boxed(tc, "Junction");
+ gcx.Scalar = conf.at_key_boxed(tc, "Scalar");
+ gcx.Capture = conf.at_key_boxed(tc, "Capture");
+ gcx.ContainerDescriptor = conf.at_key_boxed(tc, "ContainerDescriptor");
+ gcx.False = conf.at_key_boxed(tc, "False");
+ gcx.True = conf.at_key_boxed(tc, "True");
return conf;
}
public static SixModelObject p6setautothreader(SixModelObject autoThreader, ThreadContext tc) {
- AutoThreader = autoThreader;
+ GlobalExt gcx = key.getGC(tc);
+ gcx.AutoThreader = autoThreader;
return autoThreader;
}
- public static SixModelObject booleanize(int x) {
- return x == 0 ? False : True;
+ public static SixModelObject booleanize(int x, ThreadContext tc) {
+ GlobalExt gcx = key.getGC(tc);
+ return x == 0 ? gcx.False : gcx.True;
}
public static SixModelObject p6definite(SixModelObject obj, ThreadContext tc) {
+ GlobalExt gcx = key.getGC(tc);
obj = org.perl6.nqp.runtime.Ops.decont(obj, tc);
- return obj instanceof TypeObject ? False : True;
+ return obj instanceof TypeObject ? gcx.False : gcx.True;
}
public static SixModelObject p6box_i(long value, ThreadContext tc) {
- SixModelObject res = Int.st.REPR.allocate(tc, Int.st);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject res = gcx.Int.st.REPR.allocate(tc, gcx.Int.st);
res.set_int(tc, value);
return res;
}
public static SixModelObject p6box_n(double value, ThreadContext tc) {
- SixModelObject res = Num.st.REPR.allocate(tc, Num.st);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject res = gcx.Num.st.REPR.allocate(tc, gcx.Num.st);
res.set_num(tc, value);
return res;
}
public static SixModelObject p6box_s(String value, ThreadContext tc) {
- SixModelObject res = Str.st.REPR.allocate(tc, Str.st);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject res = gcx.Str.st.REPR.allocate(tc, gcx.Str.st);
res.set_str(tc, value);
return res;
}
public static SixModelObject p6list(SixModelObject arr, SixModelObject type, SixModelObject flattens, ThreadContext tc) {
+ GlobalExt gcx = key.getGC(tc);
SixModelObject list = type.st.REPR.allocate(tc, type.st);
if (arr != null)
- list.bind_attribute_boxed(tc, List, "$!nextiter", HINT_LIST_nextiter,
+ list.bind_attribute_boxed(tc, gcx.List, "$!nextiter", HINT_LIST_nextiter,
p6listiter(arr, list, tc));
- list.bind_attribute_boxed(tc, List, "$!flattens", HINT_LIST_flattens, flattens);
+ list.bind_attribute_boxed(tc, gcx.List, "$!flattens", HINT_LIST_flattens, flattens);
return list;
}
public static SixModelObject p6listitems(SixModelObject list, ThreadContext tc) {
- SixModelObject items = list.get_attribute_boxed(tc, List, "$!items", HINT_LIST_items);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject items = list.get_attribute_boxed(tc, gcx.List, "$!items", HINT_LIST_items);
if (!(items instanceof VMArrayInstance)) {
- items = EMPTYARR.clone(tc);
- list.bind_attribute_boxed(tc, List, "$!items", HINT_LIST_items, items);
+ items = gcx.EMPTYARR.clone(tc);
+ list.bind_attribute_boxed(tc, gcx.List, "$!items", HINT_LIST_items, items);
}
return items;
}
@@ -182,16 +203,19 @@ public static SixModelObject p6shiftpush(SixModelObject a, SixModelObject b, lon
setPos++;
}
}
- if (total > 0)
- b.splice(tc, EMPTYARR, 0, total);
+ if (total > 0) {
+ GlobalExt gcx = key.getGC(tc);
+ b.splice(tc, gcx.EMPTYARR, 0, total);
+ }
return a;
}
public static SixModelObject p6listiter(SixModelObject arr, SixModelObject list, ThreadContext tc) {
- SixModelObject iter = ListIter.st.REPR.allocate(tc, ListIter.st);
- iter.bind_attribute_boxed(tc, ListIter, "$!rest", HINT_LISTITER_rest, arr);
- iter.bind_attribute_boxed(tc, ListIter, "$!list", HINT_LISTITER_list, list);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject iter = gcx.ListIter.st.REPR.allocate(tc, gcx.ListIter.st);
+ iter.bind_attribute_boxed(tc, gcx.ListIter, "$!rest", HINT_LISTITER_rest, arr);
+ iter.bind_attribute_boxed(tc, gcx.ListIter, "$!list", HINT_LISTITER_list, list);
return iter;
}
@@ -232,14 +256,15 @@ public static CallSiteDescriptor p6bindsig(ThreadContext tc, CallSiteDescriptor
if (cf.codeRef.staticInfo.name != null)
System.err.println("Binding for " + cf.codeRef.staticInfo.name);
}
+ GlobalExt gcx = key.getGC(tc);
SixModelObject sig = cf.codeRef.codeObject
- .get_attribute_boxed(tc, Code, "$!signature", HINT_CODE_SIG);
+ .get_attribute_boxed(tc, gcx.Code, "$!signature", HINT_CODE_SIG);
SixModelObject params = sig
- .get_attribute_boxed(tc, Signature, "$!params", HINT_SIG_PARAMS);
+ .get_attribute_boxed(tc, gcx.Signature, "$!params", HINT_SIG_PARAMS);
/* Run binder, and handle any errors. */
String[] error = new String[1];
- switch (Binder.bind(tc, cf, params, csd, args, false, error)) {
+ switch (Binder.bind(tc, gcx, cf, params, csd, args, false, error)) {
case Binder.BIND_RESULT_FAIL:
throw ExceptionHandling.dieInternal(tc, error[0]);
case Binder.BIND_RESULT_JUNCTION:
@@ -264,8 +289,9 @@ public static long p6trialbind(SixModelObject routine, SixModelObject values, Si
}
public static SixModelObject p6parcel(SixModelObject array, SixModelObject fill, ThreadContext tc) {
- SixModelObject parcel = Parcel.st.REPR.allocate(tc, Parcel.st);
- parcel.bind_attribute_boxed(tc, Parcel, "$!storage", HINT_PARCEL_STORAGE, array);
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject parcel = gcx.Parcel.st.REPR.allocate(tc, gcx.Parcel.st);
+ parcel.bind_attribute_boxed(tc, gcx.Parcel, "$!storage", HINT_PARCEL_STORAGE, array);
if (fill != null) {
long elems = array.elems(tc);
@@ -306,12 +332,13 @@ public static SixModelObject p6store(SixModelObject cont, SixModelObject value,
}
public static SixModelObject p6decontrv(SixModelObject cont, ThreadContext tc) {
- if (isRWScalar(tc, cont)) {
- tc.curFrame.codeRef.codeObject.get_attribute_native(tc, Routine, "$!rw", HINT_ROUTINE_RW);
+ GlobalExt gcx = key.getGC(tc);
+ if (isRWScalar(tc, gcx, cont)) {
+ tc.curFrame.codeRef.codeObject.get_attribute_native(tc, gcx.Routine, "$!rw", HINT_ROUTINE_RW);
if (tc.native_i == 0) {
/* Recontainerize to RO. */
- SixModelObject roCont = Scalar.st.REPR.allocate(tc, Scalar.st);
- roCont.bind_attribute_boxed(tc, Ops.Scalar, "$!value",
+ SixModelObject roCont = gcx.Scalar.st.REPR.allocate(tc, gcx.Scalar.st);
+ roCont.bind_attribute_boxed(tc, gcx.Scalar, "$!value",
RakudoContainerSpec.HINT_value,
cont.st.ContainerSpec.fetch(tc, cont));
return roCont;
@@ -321,9 +348,10 @@ public static SixModelObject p6decontrv(SixModelObject cont, ThreadContext tc) {
}
public static SixModelObject p6recont_ro(SixModelObject cont, ThreadContext tc) {
- if (isRWScalar(tc, cont)) {
- SixModelObject roCont = Scalar.st.REPR.allocate(tc, Scalar.st);
- roCont.bind_attribute_boxed(tc, Ops.Scalar, "$!value",
+ GlobalExt gcx = key.getGC(tc);
+ if (isRWScalar(tc, gcx, cont)) {
+ SixModelObject roCont = gcx.Scalar.st.REPR.allocate(tc, gcx.Scalar.st);
+ roCont.bind_attribute_boxed(tc, gcx.Scalar, "$!value",
RakudoContainerSpec.HINT_value,
cont.st.ContainerSpec.fetch(tc, cont));
return roCont;
@@ -331,13 +359,13 @@ public static SixModelObject p6recont_ro(SixModelObject cont, ThreadContext tc)
return cont;
}
- private static boolean isRWScalar(ThreadContext tc, SixModelObject check) {
- if (!(check instanceof TypeObject) && check.st.WHAT == Scalar) {
- SixModelObject desc = check.get_attribute_boxed(tc, Scalar, "$!descriptor",
+ private static boolean isRWScalar(ThreadContext tc, GlobalExt gcx, SixModelObject check) {
+ if (!(check instanceof TypeObject) && check.st.WHAT == gcx.Scalar) {
+ SixModelObject desc = check.get_attribute_boxed(tc, gcx.Scalar, "$!descriptor",
RakudoContainerSpec.HINT_descriptor);
if (desc == null)
return false;
- desc.get_attribute_native(tc, ContainerDescriptor, "$!rw", HINT_CD_RW);
+ desc.get_attribute_native(tc, gcx.ContainerDescriptor, "$!rw", HINT_CD_RW);
return tc.native_i != 0;
}
return false;
@@ -345,8 +373,9 @@ private static boolean isRWScalar(ThreadContext tc, SixModelObject check) {
public static SixModelObject p6var(SixModelObject cont, ThreadContext tc) {
if (cont != null && cont.st.ContainerSpec != null) {
- SixModelObject wrapper = Scalar.st.REPR.allocate(tc, Scalar.st);
- wrapper.bind_attribute_boxed(tc, Ops.Scalar, "$!value",
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject wrapper = gcx.Scalar.st.REPR.allocate(tc, gcx.Scalar.st);
+ wrapper.bind_attribute_boxed(tc, gcx.Scalar, "$!value",
RakudoContainerSpec.HINT_value,
cont);
return wrapper;
@@ -365,7 +394,8 @@ public static SixModelObject p6typecheckrv(SixModelObject rv, SixModelObject rou
private static final CallSiteDescriptor baThrower = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
public static SixModelObject p6bindassert(SixModelObject value, SixModelObject type, ThreadContext tc) {
- if (type != Mu) {
+ GlobalExt gcx = key.getGC(tc);
+ if (type != gcx.Mu) {
SixModelObject decont = org.perl6.nqp.runtime.Ops.decont(value, tc);
if (org.perl6.nqp.runtime.Ops.istype(decont, type, tc) == 0) {
SixModelObject thrower = getThrower(tc, "X::TypeCheck::Binding");
@@ -381,19 +411,21 @@ public static SixModelObject p6bindassert(SixModelObject value, SixModelObject t
}
public static SixModelObject p6capturelex(SixModelObject codeObj, ThreadContext tc) {
+ GlobalExt gcx = key.getGC(tc);
CodeRef closure = (CodeRef)codeObj.get_attribute_boxed(tc,
- Code, "$!do", HINT_CODE_DO);
+ gcx.Code, "$!do", HINT_CODE_DO);
closure.outer = tc.curFrame;
return codeObj;
}
public static SixModelObject p6captureouters(SixModelObject capList, ThreadContext tc) {
+ GlobalExt gcx = key.getGC(tc);
CallFrame cf = tc.curFrame;
long elems = capList.elems(tc);
for (long i = 0; i < elems; i++) {
SixModelObject codeObj = capList.at_pos_boxed(tc, i);
CodeRef closure = (CodeRef)codeObj.get_attribute_boxed(tc,
- Code, "$!do", HINT_CODE_DO);
+ gcx.Code, "$!do", HINT_CODE_DO);
CallFrame ctxToDiddle = closure.outer;
ctxToDiddle.outer = tc.curFrame;
}
View
12 src/vm/jvm/runtime/org/perl6/rakudo/RakudoContainerSpec.java
@@ -15,32 +15,34 @@
/* Fetches a value out of a container. Used for decontainerization. */
public SixModelObject fetch(ThreadContext tc, SixModelObject cont) {
- return cont.get_attribute_boxed(tc, Ops.Scalar, "$!value", HINT_value);
+ return cont.get_attribute_boxed(tc, Ops.key.getGC(tc).Scalar, "$!value", HINT_value);
}
/* Stores a value in a container. Used for assignment. */
public void store(ThreadContext tc, SixModelObject cont, SixModelObject obj) {
+ SixModelObject Scalar = Ops.key.getGC(tc).Scalar;
if (Ops.DEBUG_MODE)
System.err.println("scalar store typecheck / rwcheck NYI");
- SixModelObject whence = cont.get_attribute_boxed(tc, Ops.Scalar, "$!whence", HINT_whence);
+ SixModelObject whence = cont.get_attribute_boxed(tc, Scalar, "$!whence", HINT_whence);
if (whence != null)
org.perl6.nqp.runtime.Ops.invokeDirect(tc, whence,
WHENCE, new Object[] { });
- cont.bind_attribute_boxed(tc, Ops.Scalar, "$!value", HINT_value, obj);
+ cont.bind_attribute_boxed(tc, Scalar, "$!value", HINT_value, 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) {
- SixModelObject whence = cont.get_attribute_boxed(tc, Ops.Scalar, "$!whence", HINT_whence);
+ SixModelObject Scalar = Ops.key.getGC(tc).Scalar;
+ SixModelObject whence = cont.get_attribute_boxed(tc, Scalar, "$!whence", HINT_whence);
if (whence != null)
org.perl6.nqp.runtime.Ops.invokeDirect(tc, whence,
WHENCE, new Object[] { });
- cont.bind_attribute_boxed(tc, Ops.Scalar, "$!value", HINT_value, obj);
+ cont.bind_attribute_boxed(tc, Scalar, "$!value", HINT_value, obj);
}
/* Name of this container specification. */

0 comments on commit 76f8db7

Please sign in to comment.
Something went wrong with that request. Please try again.