Skip to content

Instantly share code, notes, and snippets.

@scovit
Created September 15, 2017 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scovit/a72b8973e872d69044f4890032c5ff2d to your computer and use it in GitHub Desktop.
Save scovit/a72b8973e872d69044f4890032c5ff2d to your computer and use it in GitHub Desktop.
use nqp;
my $b := sub ($cont) { say "here" };
my $c := sub ($cont, $val) { say "pera" };
my $A_FETCH;
my $A_STORE;
constant A := Metamodel::ClassHOW.new_type( name => 'A' );
A.HOW.add_parent(A, Any);
A.HOW.add_method(A, 'FETCH', ($A_FETCH := nqp::getstaticcode(
nqp::getattr($b, Code, '$!do')
)));
A.HOW.add_method(A, 'STORE', ($A_STORE := nqp::getstaticcode(
nqp::getattr($c, Code, '$!do')
)));
A.HOW.add_method(A, 'new', nqp::getstaticcode(
nqp::getattr(sub ($type) {
my $cont := nqp::create(A);
say "chiu";
$cont
}, Code, '$!do')
));
A.HOW.compose(A);
nqp::setcontspec(A, 'code_pair', nqp::hash(
'fetch', $A_FETCH,
'store', $A_STORE
));
A.HOW.compose_repr(A);
my $f = A.new();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment