From 03f7ce1cb3ca92f335e49f875ec798f209138891 Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Tue, 20 Jul 2010 19:26:47 -0700 Subject: [PATCH] Implement Mu.bless, Any.flat --- rxwork.pl | 24 ------------------------ setting | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/rxwork.pl b/rxwork.pl index 960c8ed3..9d88efdb 100644 --- a/rxwork.pl +++ b/rxwork.pl @@ -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). diff --git a/setting b/setting index c0fb962c..9d5e4ffa 100644 --- a/setting +++ b/setting @@ -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 }); @@ -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); @@ -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;