Last active
September 26, 2019 12:30
-
-
Save lizmat/90974d3d89f7f64d02122362ff39c6cc to your computer and use it in GitHub Desktop.
alternate Proxy implementation
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
class Proxy { | |
has Mu &.FETCH; | |
has Mu &.STORE; | |
my constant $FETCH = method FETCH(\SELF:) { | |
my $self := nqp::create(Scalar); | |
nqp::bindattr($self, Scalar, '$!value', SELF); | |
nqp::decont(&!FETCH($self)) | |
} | |
my constant $STORE = method STORE(\SELF: \value) { | |
my $self := nqp::create(Scalar); | |
nqp::bindattr($self, Scalar, '$!value', SELF); | |
&!STORE($self, value) | |
} | |
BEGIN { | |
Proxy.HOW.set_container_spec(Proxy, nqp::hash( | |
'fetch', nqp::getstaticcode(nqp::getattr($FETCH,Code,'$!do')), | |
'store', nqp::getstaticcode(nqp::getattr($STORE,Code,'$!do')) | |
)); | |
Proxy.HOW.compose_repr(Proxy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment