Created
August 21, 2009 04:47
-
-
Save treed/171674 to your computer and use it in GitHub Desktop.
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
# The usual class setup stuff is combined with that of Object and Module. | |
# Look in src/builtins/classes.pir | |
.namespace ['Class';'meta'] | |
.sub 'new' :method | |
.param pmc superclass :optional | |
.param int super_flag :opt_flag | |
if super_flag goto have_super | |
superclass = get_hll_global 'Object' | |
have_super: | |
.local pmc new_pclass, new_meta_pclass, new_rclass, new_meta_rclass | |
.local pmc super_pclass, meta_super_pclass, super_rclass, meta_super_rclass | |
# We'll need this later: | |
.local pmc nil | |
nil = get_hll_global 'nil' | |
# First get all the superclass information. | |
super_rclass = getattribute superclass, '!class' | |
super_pclass = getattribute super_rclass, '!parrot_class' | |
meta_super_rclass = getattribute super_rclass, '!meta' | |
meta_super_pclass = getattribute meta_super_rclass, '!parrot_class' | |
# Then make the new parrot classes | |
new_pclass = subclass super_pclass | |
new_meta_pclass = subclass meta_super_pclass | |
# Then make the new ruby classes | |
new_rclass = new 'Class' | |
new_meta_rclass = new 'Class' | |
# Then fill in the parrot classes | |
setattribute new_rclass, '!parrot_class', new_pclass | |
setattribute new_meta_rclass, '!parrot_class', new_meta_pclass | |
# Then the super classes | |
setattribute new_rclass, '!super', super_rclass | |
setattribute new_meta_rclass, '!super', meta_super_rclass | |
# Then the metas | |
setattribute new_rclass, '!meta', new_meta_rclass | |
setattribute new_meta_rclass, '!meta', nil | |
.return (new_rclass) | |
.end | |
.namespace ['Class'] | |
.sub 'allocate' :method | |
$P0 = getattribute self, '!parrot_class' | |
$P1 = new $P0 | |
.return ($P1) | |
.end | |
.sub 'inherited' :method | |
.param pmc subclass | |
.end | |
.sub 'new' :method | |
.param pmc args :slurpy | |
.local pmc obj | |
obj = self.'allocate'() | |
obj.'initialize'() | |
.return (obj) | |
.end | |
.sub 'superclass' :method | |
$P0 = getattribute self, '!super' | |
.return ($P0) | |
.end | |
# Local Variables: | |
# mode: pir | |
# fill-column: 100 | |
# End: | |
# vim: expandtab shiftwidth=4 ft=pir: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment