Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor type object checking into ACCEPTS
  • Loading branch information
sorear committed Feb 5, 2011
1 parent a7ef71e commit de2b3f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions TODO
Expand Up @@ -27,6 +27,9 @@ Other stuff

For STD difference minimization:
* Find a compromise on :$*endsym
- TimToady and I seem to both not hate traits
* Find a compromise on cursor mutability
* basic multimethods
* s///
* given / when
* constant %foo = (a => 1, b => 2)
13 changes: 7 additions & 6 deletions lib/SAFE.setting
Expand Up @@ -20,6 +20,7 @@ my class Mu {
$tn ~ "()"
}
}
method ACCEPTS(\$x) { defined(self) ?? self === $x !! $x.^does(self) }
method perl() { defined(self) ?? self.Str !! self.typename }
method so() { ?self }
method not() { !self }
Expand All @@ -44,7 +45,6 @@ my class Any is Mu {

method sort($cmp = &infix:<leg>) { @(self).sort($cmp) }

method ACCEPTS($t) { self === $t }
method !butWHENCE($cr) {
Q:CgOp { (newvsubvar (class_ref mo Any) (@ {$cr}) (@ {self})) }
}
Expand Down Expand Up @@ -176,7 +176,7 @@ my class Num is Cool {
(box Bool (compare != (double 0) (unbox num (@ {self}))))
} }
method Numeric() { self }
method ACCEPTS($t) { self == $t }
method ACCEPTS($t) { defined(self) ?? self == $t !! $t.^does(self) }
}

#TODO use a power from the standard library
Expand All @@ -192,7 +192,7 @@ sub infix:<**>($num,$power) {

my class Str is Cool {
method Str () { self }
method ACCEPTS($t) { self eq $t }
method ACCEPTS($t) { defined(self) ?? self eq $t !! $t.^does(self) }
method Bool () { self ne "" }
method chars() { chars(self) }
method say() { Q:CgOp {
Expand All @@ -214,7 +214,7 @@ my class Sub {
has $!info;

# Should be for Block, not Sub
method ACCEPTS($t) { (self)($t) }
method ACCEPTS($t) { defined(self) ?? (self)($t) !! $t.^does(self) }
}

my class ClassHOW {
Expand All @@ -228,7 +228,7 @@ my class EnumType is Cool { }
my class Bool is EnumType {
method Str() { self ?? "Bool::True" !! "Bool::False" }
method Bool() { self }
method ACCEPTS($) { self }
method ACCEPTS($t) { defined(self) ?? self !! $t.^does(self) }
method Numeric() { self ?? 1 !! 0 }
our constant True = Q:CgOp { (box Bool (bool 1)) };
our constant False = Q:CgOp { (box Bool (bool 0)) };
Expand Down Expand Up @@ -339,7 +339,7 @@ sub infix:<but>($obj, $role) { Q:CgOp {
(ns (stab_what (role_apply (obj_llhow (@ {$obj})) (obj_llhow (@ {$role})))))
} }
sub infix:<~~>($t,$m) { defined($m) ?? ($m.ACCEPTS($t)) !! ($t.^does($m)) }
sub infix:<~~>($t,$m) { $m.ACCEPTS($t) }
sub ord($x) { Q:CgOp { (bif_ord {$x}) } }
sub chr($x) { Q:CgOp { (bif_chr {$x}) } }
Expand Down Expand Up @@ -865,6 +865,7 @@ my class Match is Cool {
my class Regex is Sub {
method ACCEPTS($st) {
return $st.^does(self) unless defined self;
Q:CgOp {
(letn ix (i 0)
str (obj_getstr {$st})
Expand Down

0 comments on commit de2b3f3

Please sign in to comment.