Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor parametric role creation PIR out into a macro, which neatens a…
…ctions.pm a little and means we can use it to create parametric roles from PIR too.
- Loading branch information
Showing
3 changed files
with
27 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This is a macro that helps in creating parametric roles. It exists to | ||
# keep actions.pm a little shorter, but also to enable us to more easily | ||
# construct parametric roles in PIR. | ||
.macro create_parametric_role(mr) | ||
"!meta_compose"(.mr) | ||
.local pmc orig_role, meths, meth_iter | ||
orig_role = getprop "$!orig_role", .mr | ||
meths = orig_role."methods"() | ||
meth_iter = iter meths | ||
it_loop: | ||
unless meth_iter goto it_loop_end | ||
$S0 = shift meth_iter | ||
$P0 = meths[$S0] | ||
$P1 = getprop "$!signature", $P0 | ||
$P0 = newclosure $P0 | ||
setprop $P0, "$!signature", $P1 | ||
.mr."add_method"($S0, $P0) | ||
goto it_loop | ||
it_loop_end: | ||
.return (.mr) | ||
.endm |