Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement type checking return values.

  • Loading branch information...
commit ebb29bed9898007367f59cfcbab278fad1a387a8 1 parent 6c80bf5
@jnthn jnthn authored
Showing with 23 additions and 2 deletions.
  1. +23 −2 src/vm/jvm/runtime/org/perl6/rakudo/RakOps.java
View
25 src/vm/jvm/runtime/org/perl6/rakudo/RakOps.java
@@ -60,6 +60,7 @@ public GlobalExt(ThreadContext tc) { }
private static final int HINT_CODE_SIG = 1;
private static final int HINT_ROUTINE_RW = 7;
private static final int HINT_SIG_PARAMS = 0;
+ private static final int HINT_SIG_RETURNS = 1;
private static final int HINT_SIG_CODE = 4;
public static final int HINT_CD_OF = 0;
public static final int HINT_CD_RW = 1;
@@ -454,9 +455,29 @@ public static SixModelObject p6var(SixModelObject cont, ThreadContext tc) {
}
}
+ private static final CallSiteDescriptor rvThrower = new CallSiteDescriptor(
+ new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
public static SixModelObject p6typecheckrv(SixModelObject rv, SixModelObject routine, ThreadContext tc) {
- if (DEBUG_MODE)
- System.err.println("p6typecheckrv NYI");
+ GlobalExt gcx = key.getGC(tc);
+ SixModelObject sig = routine.get_attribute_boxed(tc, gcx.Code, "$!signature", HINT_CODE_SIG);
+ SixModelObject rtype = sig.get_attribute_boxed(tc, gcx.Signature, "$!returns", HINT_SIG_RETURNS);
+ if (rtype != null) {
+ SixModelObject decontValue = Ops.decont(rv, tc);
+ if (Ops.istype(decontValue, rtype, tc) == 0) {
+ /* Straight type check failed, but it's possible we're returning
+ * an Int that can unbox into an int or similar. */
+ StorageSpec spec = rtype.st.REPR.get_storage_spec(tc, rtype.st);
+ if (spec.inlineable == 0 || Ops.istype(rtype, decontValue.st.WHAT, tc) == 0) {
+ SixModelObject thrower = getThrower(tc, "X::TypeCheck::Return");
+ if (thrower == null)
+ throw ExceptionHandling.dieInternal(tc,
+ "Type check failed for return value");
+ else
+ Ops.invokeDirect(tc, thrower,
+ rvThrower, new Object[] { decontValue, rtype });
+ }
+ }
+ }
return rv;
}
Please sign in to comment.
Something went wrong with that request. Please try again.