Skip to content

Commit

Permalink
Implement Mu.bless, Any.flat
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 21, 2010
1 parent f0e814f commit 03f7ce1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 0 additions & 24 deletions rxwork.pl
Expand Up @@ -6,30 +6,6 @@
method from() { $!from }
}

PRE-INIT {
Mu.HOW.add-method(Q:CgOp { (w (clr_string "bless")) },
anon method bless($obj) { Q:CgOp {
(prog
[setfield klass (cast DynObject (@ (l $obj)))
(getfield klass (cast DynObject (@ (l self))))]
[l $obj])
} });
Mu.HOW.add-method(Q:CgOp { (w (clr_string "flat")) },
anon method flat() { self, });
Parcel.HOW.add-method(Q:CgOp { (w (clr_string "flat")) },
anon method flat() {
my @x := self;
List.RAWCREATE("flat", 1, "items", LLArray.new(),
"rest", LLArray.new(@x));
});
List.HOW.add-method(Q:CgOp { (w (clr_string "flat")) },
anon method flat() {
my @x := self;
List.RAWCREATE("flat", 1, "items", LLArray.new(),
"rest", LLArray.new(@x));
});
}

# Outside a regex, a result is a lazy list.
# Inside a regex, a result is a bare iterator, or a double return (if
# ratcheting).
Expand Down
24 changes: 24 additions & 0 deletions setting
Expand Up @@ -372,6 +372,16 @@ PRE-INIT {
}
$obj;
});
Mu.HOW.add-method(Q:CgOp { (w (clr_string "bless")) },
anon method bless($obj) { Q:CgOp {
(prog
[setfield klass (cast DynObject (@ (l $obj)))
(getfield klass (cast DynObject (@ (l self))))]
[l $obj])
} });
Any.HOW.add-method(Q:CgOp { (w (clr_string "flat")) },
anon method flat() { self, });

Any.HOW.add-method(Q:CgOp { (w (clr_string "ACCEPTS")) },
anon method ACCEPTS($t) { self === $t });
Expand Down Expand Up @@ -430,9 +440,17 @@ my class Iterator {

my class EMPTY { }

my class List { ... }

my class Parcel {
# $!ll

method flat() {
my @x := self;
List.RAWCREATE("flat", 1, "items", LLArray.new(),
"rest", LLArray.new(@x));
}

method iterator() {
my $ll = $!ll;
my $it = Iterator.RAWCREATE("valid", 1, "value", Any, "next", Any);
Expand Down Expand Up @@ -475,6 +493,12 @@ sub Nil {
my class List is Cool {
# low level, so not declared yet
# @!items @!rest $!flat
method flat() {
my @x := self;
List.RAWCREATE("flat", 1, "items", LLArray.new(),
"rest", LLArray.new(@x));
}

method fill($nr) {
my $i = $!items;
my $r = $!rest;
Expand Down

0 comments on commit 03f7ce1

Please sign in to comment.