Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Sketch out SubsetHOW. Untested.
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,41 @@ | ||
| class Perl6::Metamodel::SubsetHOW | ||
| does Perl6::Metamodel::Naming | ||
| { | ||
| # The subset type or nominal type that we refine. | ||
| has $!refinee; | ||
|
|
||
| # The block implementing the refinement. | ||
| has $!refinement; | ||
|
|
||
| method new_type(:$name = '<anon>', :$refinee!, :$refinement!) { | ||
| my $metasubset := self.new(:name($name), :refinee($refinee), | ||
| :refinement($refinement)); | ||
| my $type := pir::repr_type_object_for__PPS($metasubset, 'Uninstantiable'); | ||
| pir::stable_set_type_check_mode__0PI($type, 2) | ||
| } | ||
|
|
||
| method set_of($obj, $refinee) { | ||
| $!refinee := $refinee | ||
| } | ||
|
|
||
| method refinee($obj) { | ||
| $!refinee | ||
| } | ||
|
|
||
| method refinement($obj) { | ||
| $!refinement | ||
| } | ||
|
|
||
| # Do check when we're on LHS of smartmatch (e.g. Even ~~ Int). | ||
| method type_check($obj, $checkee) { | ||
| pir::perl6_booleanize__PI($checkee.HOW =:= self || | ||
| pir::type_check__IPP($checkee, $!refinee)) | ||
| } | ||
|
|
||
| # Here we check the value itself (when on RHS on smartmatch). | ||
| method accepts_type($obj, $checkee) { | ||
| pir::perl6_booleanize__PI( | ||
| pir::type_check__IPP($checkee, $!refinee) && | ||
| $!refinement.ACCEPTS($checkee)) | ||
| } | ||
| } |
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
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