public
Created

Tried fix for sorear/niecza#124

  • Download Gist
124.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
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;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.