Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'nom' of github.com:rakudo/rakudo into nom
  • Loading branch information
labster committed Jul 3, 2013
2 parents 827bcc4 + c83b634 commit 174bf4f
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 26 deletions.
9 changes: 9 additions & 0 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -971,6 +971,7 @@ BEGIN {
my $many_res := $many ?? [] !! Mu;
my @possibles;
my int $done := 0;
my int $done_bind_check := 0;
until $done {
$cur_candidate := nqp::atpos(@candidates, $cur_idx);

Expand Down Expand Up @@ -1077,6 +1078,14 @@ BEGIN {
$new_possibles := [] unless nqp::islist($new_possibles);

my $sig := nqp::getattr($sub, Code, '$!signature');
#?if !parrot
unless $done_bind_check {
# Need a copy of the capture, as we may later do a
# multi-dispatch when evaluating the constraint.
$capture := nqp::clone($capture);
$done_bind_check := 1;
}
#?endif
if nqp::p6isbindable($sig, $capture) {
nqp::push($new_possibles, nqp::atpos(@possibles, $i));
unless $many {
Expand Down
5 changes: 2 additions & 3 deletions src/core/Str.pm
Expand Up @@ -970,9 +970,8 @@ my class Str does Stringy {
my Int $outdent = $steps ~~ Whatever ?? $common-prefix
!! -$steps;

warn sprintf('Asked to remove %d spaces, ' ~
'but the shortest indent is %d spaces',
$outdent, $common-prefix) if $outdent > $common-prefix;
warn "Asked to remove $outdent spaces, but the shortest indent is $common-prefix spaces"
if $outdent > $common-prefix;

# Work backwards from the right end of the indent whitespace, removing
# array elements up to # (or over, in the case of tab-explosion)
Expand Down
3 changes: 0 additions & 3 deletions src/core/Temporal.pm
Expand Up @@ -621,10 +621,7 @@ multi infix:«>»(Date:D $a, Date:D $b) {
$a.daycount > $b.daycount
}

# XXX JVM doesn't handle DateTime stuff properly yet
#?if !jvm
$PROCESS::TZ = get-local-timezone-offset();
#?endif

# =begin pod
#
Expand Down
58 changes: 56 additions & 2 deletions src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
Expand Up @@ -4,6 +4,7 @@

import org.perl6.nqp.runtime.*;
import org.perl6.nqp.sixmodel.*;
import org.perl6.nqp.sixmodel.reprs.ContextRefInstance;

public final class Binder {
/* Possible results of binding. */
Expand Down Expand Up @@ -182,6 +183,16 @@ private static int juncOrFail(ThreadContext tc, Ops.GlobalExt gcx, SixModelObjec
/* 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 final CallSiteDescriptor genIns = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor ACCEPTS_o = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor ACCEPTS_i = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_INT }, null);
private static final CallSiteDescriptor ACCEPTS_n = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_NUM }, null);
private static final CallSiteDescriptor ACCEPTS_s = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_STR }, null);
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. */
Expand Down Expand Up @@ -299,7 +310,12 @@ else if (desiredNative == 0) {
SixModelObject HOW = nomType.st.HOW;
SixModelObject ig = org.perl6.nqp.runtime.Ops.findmethod(tc, HOW,
"instantiate_generic");
throw new RuntimeException("Generic type parameter binding NYI");
SixModelObject ContextRef = tc.gc.ContextRef;
SixModelObject cc = ContextRef.st.REPR.allocate(tc, ContextRef.st);
((ContextRefInstance)cc).context = cf;
org.perl6.nqp.runtime.Ops.invokeDirect(tc, ig, genIns,
new Object[] { HOW, nomType, cc });
nomType = org.perl6.nqp.runtime.Ops.result_o(tc.curFrame);
}

/* If not, do the check. If the wanted nominal type is Mu, then
Expand Down Expand Up @@ -436,7 +452,45 @@ else if ((paramFlags & SIG_ELEM_HASH_SIGIL) != 0) {
if ((paramFlags & SIG_ELEM_INVOCANT) != 0)
cf.oLex[sci.oTryGetLexicalIdx("self")] = decontValue;

/* TODO: post_constraints. */
/* Handle any constraint types (note that they may refer to the parameter by
* name, so we need to have bound it already). */
SixModelObject postConstraints = param.get_attribute_boxed(tc, gcx.Parameter,
"$!post_contraints", HINT_post_constraints);
if (postConstraints != null) {
long numConstraints = postConstraints.elems(tc);
for (long i = 0; i < numConstraints; i++) {
/* Check we meet the constraint. */
SixModelObject consType = postConstraints.at_pos_boxed(tc, i);
SixModelObject acceptsMeth = org.perl6.nqp.runtime.Ops.findmethod(consType, "ACCEPTS", tc);
if (org.perl6.nqp.runtime.Ops.istype(consType, gcx.Code, tc) != 0)
Ops.p6capturelex(consType, tc);
switch (flag) {
case CallSiteDescriptor.ARG_INT:
org.perl6.nqp.runtime.Ops.invokeDirect(tc, acceptsMeth,
ACCEPTS_i, new Object[] { consType, arg_i });
break;
case CallSiteDescriptor.ARG_NUM:
org.perl6.nqp.runtime.Ops.invokeDirect(tc, acceptsMeth,
ACCEPTS_n, new Object[] { consType, arg_n });
break;
case CallSiteDescriptor.ARG_STR:
org.perl6.nqp.runtime.Ops.invokeDirect(tc, acceptsMeth,
ACCEPTS_s, new Object[] { consType, arg_s });
break;
default:
org.perl6.nqp.runtime.Ops.invokeDirect(tc, acceptsMeth,
ACCEPTS_o, new Object[] { consType, arg_o });
break;
}
long result = org.perl6.nqp.runtime.Ops.istrue(
org.perl6.nqp.runtime.Ops.result_o(tc.curFrame), tc);
if (result == 0) {
if (error != null)
error[0] = "Constraint type check failed for parameter '" + varName + "'";
return BIND_RESULT_FAIL;
}
}
}

/* TODO: attributives. */
if ((paramFlags & SIG_ELEM_BIND_ATTRIBUTIVE) != 0) {
Expand Down
69 changes: 64 additions & 5 deletions src/vm/jvm/runtime/org/perl6/rakudo/Ops.java
@@ -1,9 +1,11 @@
package org.perl6.rakudo;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import org.perl6.nqp.runtime.*;
import org.perl6.nqp.sixmodel.*;
import org.perl6.nqp.sixmodel.reprs.CallCaptureInstance;
import org.perl6.nqp.sixmodel.reprs.ContextRefInstance;
import org.perl6.nqp.sixmodel.reprs.LexoticInstance;
import org.perl6.nqp.sixmodel.reprs.VMArrayInstance;
Expand Down Expand Up @@ -33,6 +35,7 @@ public static class GlobalExt {
public SixModelObject ListIter;
public SixModelObject Array;
public SixModelObject LoL;
public SixModelObject Nil;
public SixModelObject EnumMap;
public SixModelObject Hash;
public SixModelObject Junction;
Expand All @@ -57,7 +60,11 @@ 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_CODE = 4;
public static final int HINT_CD_OF = 0;
public static final int HINT_CD_RW = 1;
public static final int HINT_CD_NAME = 2;
public static final int HINT_CD_DEFAULT = 3;
private static final int HINT_LIST_items = 0;
private static final int HINT_LIST_flattens = 1;
private static final int HINT_LIST_nextiter = 2;
Expand Down Expand Up @@ -308,11 +315,39 @@ public static SixModelObject p6bindcaptosig(SixModelObject sig, SixModelObject c
}
}

public static long p6isbindable(SixModelObject signature, SixModelObject capture, ThreadContext tc) {
/* TODO */
if (DEBUG_MODE)
System.err.println("p6isbindable NYI (always returns true)");
return 1;
public static long p6isbindable(SixModelObject sig, SixModelObject cap, ThreadContext tc) {
GlobalExt gcx = key.getGC(tc);

CallSiteDescriptor csd;
Object[] args;
if (cap instanceof CallCaptureInstance) {
CallCaptureInstance cc = (CallCaptureInstance)cap;
csd = cc.descriptor;
args = cc.args;
} else {
csd = Binder.explodeCapture(tc, gcx, cap);
args = tc.flatArgs;
}

SixModelObject params = sig.get_attribute_boxed(tc, gcx.Signature,
"$!params", HINT_SIG_PARAMS);
SixModelObject codeObj = sig.get_attribute_boxed(tc, gcx.Signature,
"$!code", HINT_SIG_CODE);
CodeRef cr = (CodeRef)codeObj.get_attribute_boxed(tc, gcx.Code,
"$!do", HINT_CODE_DO);

CallFrame cf = new CallFrame(tc, cr);
try {
switch (Binder.bind(tc, gcx, cf, params, csd, args, false, null)) {
case Binder.BIND_RESULT_FAIL:
return 0;
default:
return 1;
}
}
finally {
tc.curFrame = tc.curFrame.caller;
}
}

public static long p6trialbind(SixModelObject routine, SixModelObject values, SixModelObject flags, ThreadContext tc) {
Expand Down Expand Up @@ -644,4 +679,28 @@ public static SixModelObject p6finddispatcher(String usage, ThreadContext tc) {

return dispatcher;
}

public static SixModelObject p6decodelocaltime(long sinceEpoch, ThreadContext tc) {
// Get calendar for current local host's timezone.
Calendar c = Calendar.getInstance();
c.setTimeInMillis(sinceEpoch * 1000);

// Populate result int array.
SixModelObject BOOTIntArray = tc.gc.BOOTIntArray;
SixModelObject result = BOOTIntArray.st.REPR.allocate(tc, BOOTIntArray.st);
tc.native_i = c.get(Calendar.SECOND);
result.bind_pos_native(tc, 0);
tc.native_i = c.get(Calendar.MINUTE);
result.bind_pos_native(tc, 1);
tc.native_i = c.get(Calendar.HOUR_OF_DAY);
result.bind_pos_native(tc, 2);
tc.native_i = c.get(Calendar.DAY_OF_MONTH);
result.bind_pos_native(tc, 3);
tc.native_i = c.get(Calendar.MONTH) + 1;
result.bind_pos_native(tc, 4);
tc.native_i = c.get(Calendar.YEAR);
result.bind_pos_native(tc, 5);

return result;
}
}
28 changes: 24 additions & 4 deletions src/vm/jvm/runtime/org/perl6/rakudo/RakudoContainerSpec.java
Expand Up @@ -19,7 +19,9 @@ public SixModelObject fetch(ThreadContext tc, SixModelObject cont) {
}

/* Stores a value in a container. Used for assignment. */
public void store(ThreadContext tc, SixModelObject cont, SixModelObject obj) {
private static final CallSiteDescriptor storeThrower = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_STR, CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
public void store(ThreadContext tc, SixModelObject cont, SixModelObject value) {
Ops.GlobalExt gcx = Ops.key.getGC(tc);

long rw = 0;
Expand All @@ -33,15 +35,33 @@ public void store(ThreadContext tc, SixModelObject cont, SixModelObject obj) {
throw ExceptionHandling.dieInternal(tc,
"Cannot assign to a readonly variable or a value");

if (Ops.DEBUG_MODE)
System.err.println("scalar store typecheck NYI");
SixModelObject of = desc.get_attribute_boxed(tc,
gcx.ContainerDescriptor, "$!of", Ops.HINT_CD_OF);
long ok = org.perl6.nqp.runtime.Ops.istype(value, of, tc);
if (ok == 0) {
if (value.st.WHAT == gcx.Nil) {
value = desc.get_attribute_boxed(tc,
gcx.ContainerDescriptor, "$!default", Ops.HINT_CD_DEFAULT);
}
else {
desc.get_attribute_native(tc, gcx.ContainerDescriptor, "$!name", Ops.HINT_CD_NAME);
String name = tc.native_s;
SixModelObject thrower = Ops.getThrower(tc, "X::TypeCheck::Assignment");
if (thrower == null)
throw ExceptionHandling.dieInternal(tc,
"Type check failed in assignment to '" + name + "'");
else
org.perl6.nqp.runtime.Ops.invokeDirect(tc, thrower,
storeThrower, new Object[] { name, value, of });
}
}

SixModelObject whence = cont.get_attribute_boxed(tc, gcx.Scalar, "$!whence", HINT_whence);
if (whence != null)
org.perl6.nqp.runtime.Ops.invokeDirect(tc, whence,
WHENCE, new Object[] { });

cont.bind_attribute_boxed(tc, gcx.Scalar, "$!value", HINT_value, obj);
cont.bind_attribute_boxed(tc, gcx.Scalar, "$!value", HINT_value, value);
}

/* Stores a value in a container, without any checking of it (this
Expand Down
18 changes: 9 additions & 9 deletions tools/build/Makefile-JVM.in
Expand Up @@ -150,15 +150,6 @@ CORE_SOURCES = \
src/core/Parameter.pm \
src/core/Signature.pm \
src/core/Buf.pm \
src/core/Regex.pm \
src/core/IO/Spec/Unix.pm \
src/core/IO/Spec/Win32.pm \
src/core/IO/Spec/Cygwin.pm \
src/core/IO/Spec.pm \
src/core/IO.pm \
src/core/IO/ArgFiles.pm \
src/core/IO/Socket.pm \
src/core/IO/Socket/INET.pm \
src/core/Rational.pm \
src/core/Rat.pm \
src/core/Complex.pm \
Expand All @@ -168,6 +159,15 @@ CORE_SOURCES = \
src/core/Match.pm \
src/core/Cursor.pm \
src/core/Grammar.pm \
src/core/Regex.pm \
src/core/IO/Spec/Unix.pm \
src/core/IO/Spec/Win32.pm \
src/core/IO/Spec/Cygwin.pm \
src/core/IO/Spec.pm \
src/core/IO.pm \
src/core/IO/ArgFiles.pm \
src/core/IO/Socket.pm \
src/core/IO/Socket/INET.pm \
src/core/AST.pm \
src/core/CallFrame.pm \
src/core/Main.pm \
Expand Down

0 comments on commit 174bf4f

Please sign in to comment.