Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created January 12, 2010 17:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ashgti/275400 to your computer and use it in GitHub Desktop.
.sub 'add_meta_method' :method
.param pmc meta
.param string name
.param pmc meth
# Add the method to the meta model
$P0 = meta.'HOW'()
$P0.'add_method'(name, meth)
# Add forward method to the class itself.
.lex '$meth_name', name
.const 'Sub' $P1 = '!metaclass_method_forwarder'
$P1 = newclosure $P1
$P0 = getattribute meta, 'parrotclass'
$P0.'add_method'(name, $P1)
.end
.sub '!metaclass_method_forwarder' :outer('add_meta_method') :method :anon
.param pmc pos_args :slurpy
.param pmc named_args :slurpy :named
$P0 = self.'HOW'()
$P1 = find_lex '$meth_name'
$S0 = $P1
.tailcall $P0.$S0(self, pos_args :flat, named_args :flat :named)
.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment