Created
May 25, 2012 07:48
-
-
Save sorear/2786465 to your computer and use it in GitHub Desktop.
Tried fix for sorear/niecza#124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/CORE.setting b/lib/CORE.setting | |
index 896c849..004df61 100644 | |
--- a/lib/CORE.setting | |
+++ b/lib/CORE.setting | |
@@ -1458,14 +1458,41 @@ my class IterCursor { | |
# subclasses must provide .reify, return parcel | |
} | |
+my class ListIterator is IterCursor { | |
+ has $!source; # P6any | |
+ has $!index; # Int32 | |
+} | |
+ | |
+my class EMPTY { } | |
+ | |
+my class GatherIterator is IterCursor { | |
+ has $.frame; | |
+ has $!reify; | |
+ | |
+ method reify() { | |
+ my $*nextframe; | |
+ $!reify // ($!reify = ( | |
+ Q:CgOp { | |
+ (letn getv (cotake (cast frame (@ {$!frame}))) | |
+ (box Parcel (ternary (== (@ {EMPTY}) (@ (l getv))) | |
+ (fvarlist_new) | |
+ (fvarlist_new | |
+ (l getv) | |
+ {GatherIterator.new(frame => $*nextframe)})))) | |
+ })); | |
+ } | |
+} | |
+ | |
+sub _gather($fr) { | |
+ &infix:<,>(GatherIterator.new(frame => $fr)).list | |
+} | |
+ | |
sub flat(*@x) { @x } | |
sub hash(|cap) { | |
(%(cap) || cap.Parcel.raw_elems != 1) ?? | |
%( @(cap), %(cap) ) !! %( $(cap) ) | |
} | |
-my class EMPTY { } | |
- | |
my class Parcel is Cool does Positional { | |
method ACCEPTS(\what) { defined(self) ?? self.flat.ACCEPTS(what) !! nextsame } | |
method flat() { self.iterator.flat } | |
@@ -2352,28 +2379,6 @@ sub _vivify_array_at_pos(\ary, $ix) { | |
Q:CgOp { (newvnewarrayvar (class_ref mo Any) {ary} (cast int (obj_getnum {$ix})) (@ {Any})) }; | |
} | |
-my class GatherIterator is IterCursor { | |
- has $.frame; | |
- has $!reify; | |
- | |
- method reify() { | |
- my $*nextframe; | |
- $!reify // ($!reify = ( | |
- Q:CgOp { | |
- (letn getv (cotake (cast frame (@ {$!frame}))) | |
- (box Parcel (ternary (== (@ {EMPTY}) (@ (l getv))) | |
- (fvarlist_new) | |
- (fvarlist_new | |
- (l getv) | |
- {GatherIterator.new(frame => $*nextframe)})))) | |
- })); | |
- } | |
-} | |
- | |
-sub _gather($fr) { | |
- &infix:<,>(GatherIterator.new(frame => $fr)).list | |
-} | |
- | |
sub reverse(*@array) { | |
my @acc; | |
push @acc, pop(@array) while @array; | |
diff --git a/lib/Kernel.cs b/lib/Kernel.cs | |
index 3c340b4..89d67ad 100644 | |
--- a/lib/Kernel.cs | |
+++ b/lib/Kernel.cs | |
@@ -3323,9 +3323,33 @@ bound: ; | |
public override VarDeque Get(Variable obj) { | |
var d = obj.Fetch(); | |
if (!d.IsDefined()) return new VarDeque(); | |
- VarDeque r = new VarDeque( (VarDeque) d.GetSlot(Kernel.ListMO, "$!items" )); | |
- r.PushD((VarDeque) d.GetSlot(Kernel.ListMO, "$!rest")); | |
- return r; | |
+ return new VarDeque(MakeIter(d, 0)); | |
+ } | |
+ internal static Variable MakeIter(P6any list, int index) { | |
+ var ret = new P6opaque(Kernel.ListIteratorMO); | |
+ ret.slots[0] = list; | |
+ ret.slots[1] = index; | |
+ return Kernel.NewROScalar(ret); | |
+ } | |
+ } | |
+ class CtxListItReify : ContextHandler<Variable[]> { | |
+ public override Variable[] Get(Variable obj) { | |
+ var it = (P6opaque)obj.Fetch(); | |
+ | |
+ // XXX speed hack | |
+ var src = (P6opaque) it.slots[0]; | |
+ var ix = (int) it.slots[1]; | |
+ | |
+ var items = (VarDeque) src.slots[0]; | |
+ var rest = (VarDeque) src.slots[1]; | |
+ | |
+ while (items.Count() <= ix && Kernel.IterHasFlat(rest, false)) { | |
+ items.Push(rest.Shift()); | |
+ } | |
+ if (items.Count() <= ix) { | |
+ return Variable.None; | |
+ } | |
+ return new [] { items[ix], CtxListIterator.MakeIter(src, ix+1) }; | |
} | |
} | |
@@ -4850,6 +4874,7 @@ saveme: | |
[CORESaved] public static STable MatchMO; | |
[CORESaved] public static STable ParcelMO; | |
[CORESaved] public static STable ListMO; | |
+ [CORESaved] public static STable ListIteratorMO; | |
[CORESaved] public static STable HashMO; | |
[CORESaved] public static STable BoolMO; | |
[CORESaved] public static STable MuMO; | |
@@ -6255,6 +6280,12 @@ slow: | |
ListMO.FillProtoClass(AnyMO, new string[] { "$!items", "$!rest" }, | |
new STable[] { ListMO, ListMO }); | |
+ ListIteratorMO = new STable("ListIterator"); | |
+ Handler_PandBox(ListIteratorMO, "reify", new CtxListItReify(), | |
+ ParcelMO); | |
+ ListIteratorMO.FillProtoClass(AnyMO, new [] { "$!source", | |
+ "$!index" }, new [] { ListIteratorMO, ListIteratorMO }); | |
+ | |
ArrayMO = new STable("Array"); | |
WrapHandler1(ArrayMO, "LISTSTORE", new IxArrayLISTSTORE()); | |
WrapIndexy(ArrayMO, "postcircumfix:<[ ]>", new IxListAtPos(true), | |
diff --git a/lib/Serialize.cs b/lib/Serialize.cs | |
index b39abb6..afee157 100644 | |
--- a/lib/Serialize.cs | |
+++ b/lib/Serialize.cs | |
@@ -68,7 +68,7 @@ namespace Niecza.Serialization { | |
new Dictionary<string,Dictionary<string,MethodInfo>>(); | |
static readonly string signature = "Niecza-Serialized-Module"; | |
- static readonly int version = 25; | |
+ static readonly int version = 26; | |
// Routines for use by serialization code | |
public bool CheckWriteObject(SerUnit into, object o, | |
diff --git a/src/STD.pm6 b/src/STD.pm6 | |
index dffb9cd..c0aec31 100644 | |
--- a/src/STD.pm6 | |
+++ b/src/STD.pm6 | |
@@ -1807,12 +1807,6 @@ grammar P6 is STD { | |
when '...' { return 1 } | |
when '!!!' { return 1 } | |
when '???' { return 1 } | |
- when '*' { | |
- if $*MULTINESS eq 'proto' and $statements.elems == 1 { | |
- self.<blockoid>:delete; | |
- self.<onlystar> = 1; | |
- } | |
- } | |
} | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment