Skip to content

Commit

Permalink
Add nqp::settypecheckmode for JVM.
Browse files Browse the repository at this point in the history
Also, start to flesh out istype a little more, though it needs more
work to finish it.
  • Loading branch information
jnthn committed Apr 27, 2013
1 parent 9d9a2af commit 3ca71af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -1871,6 +1871,7 @@ QAST::OperationsJAST.map_classlib_core_op('setboolspec', $TYPE_OPS, 'setboolspec
QAST::OperationsJAST.map_classlib_core_op('setmethcache', $TYPE_OPS, 'setmethcache', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('setmethcacheauth', $TYPE_OPS, 'setmethcacheauth', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('settypecache', $TYPE_OPS, 'settypecache', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('settypecheckmode', $TYPE_OPS, 'settypecheckmode', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('objprimspec', $TYPE_OPS, 'objprimspec', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('isinvokable', $TYPE_OPS, 'isinvokable', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('setinvokespec', $TYPE_OPS, 'setinvokespec', [$RT_OBJ, $RT_OBJ, $RT_STR, $RT_OBJ], $RT_OBJ, :tc);
Expand Down
30 changes: 29 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1431,6 +1431,11 @@ public static SixModelObject settypecache(SixModelObject obj, SixModelObject typ
obj.st.TypeCheckCache = cache;
return obj;
}
public static SixModelObject settypecheckmode(SixModelObject obj, long mode, ThreadContext tc) {
obj.st.ModeFlags = (int)mode |
(obj.st.ModeFlags & (~STable.TYPE_CHECK_CACHE_FLAG_MASK));
return obj;
}
public static long objprimspec(SixModelObject obj, ThreadContext tc) {
return obj.st.REPR.get_storage_spec(tc, obj.st).boxed_primitive;
}
Expand All @@ -1448,15 +1453,38 @@ public static long isinvokable(SixModelObject obj, ThreadContext tc) {
return obj instanceof CodeRef || obj.st.InvocationSpec != null ? 1 : 0;
}
public static long istype(SixModelObject obj, SixModelObject type, ThreadContext tc) {
/* Just the basic case so far. */
/* Null always type checks false. */
if (obj == null)
return 0;

int typeCheckMode = type.st.ModeFlags & STable.TYPE_CHECK_CACHE_FLAG_MASK;
SixModelObject[] cache = obj.st.TypeCheckCache;
if (cache != null) {
/* We have the cache, so just look for the type object we
* want to be in there. */
for (int i = 0; i < cache.length; i++)
if (cache[i] == type)
return 1;

/* If the type check cache is definitive, we're done. */
if ((typeCheckMode & STable.TYPE_CHECK_CACHE_THEN_METHOD) == 0 &&
(typeCheckMode & STable.TYPE_CHECK_NEEDS_ACCEPTS) == 0)
return 0;
}

/* If we get here, need to call .^type_check on the value we're
* checking. */
if (cache == null || (typeCheckMode & STable.TYPE_CHECK_CACHE_THEN_METHOD) != 0) {
/* TODO: Implement this. */
return 0;
}

/* If the flag to call .accepts_type on the target value is set, do so. */
if ((typeCheckMode & STable.TYPE_CHECK_NEEDS_ACCEPTS) != 0) {
throw new RuntimeException("Type accepts method fallback NYI");
}

/* If we get here, type check failed. */
return 0;
}

Expand Down

0 comments on commit 3ca71af

Please sign in to comment.