Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an Attribute class that will be the descriptor for an attribute. …
…For now it only has a .name, will add more later. Also implement first cut of .^attributes.
  • Loading branch information
jnthn committed Jul 22, 2009
1 parent d8505f8 commit 03aa56f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -114,6 +114,7 @@ SETTING = \
src/setting/Any-num.pm \
src/setting/Any-str.pm \
src/setting/Array.pm \
src/setting/Attribute.pm \
src/setting/Bool.pm \
src/setting/Buf.pm \
src/setting/Hash.pm \
Expand Down
58 changes: 58 additions & 0 deletions src/parrot/ClassHOW.pir
Expand Up @@ -36,6 +36,64 @@ Tests role membership.
.end


=item attributes()

Gets the attributes that the class declares, returning a list of
Attribute descriptors.

=cut

.sub 'attributes' :method
.param pmc obj
.param pmc local :named('local') :optional

# Create result list and get Attribute proto.
.local pmc result_list, attr_proto
result_list = get_root_global [.RAKUDO_HLL], 'Array'
result_list = result_list.'new'()
attr_proto = get_root_global [.RAKUDO_HLL], 'Attribute'

# Get list of parents whose attributes we are interested in, and put
# this class on the start. With the local flag, that's just it.
.local pmc parents, parents_it, cur_class
if null local goto all_parents
unless local goto all_parents
parents = get_root_global [.RAKUDO_HLL], 'Array'
parents = parents.'new'()
goto parents_list_made
all_parents:
parents = self.'parents'(obj)
parents_list_made:
$P0 = obj.'WHAT'()
parents.'unshift'($P0)
parents_it = iter parents
parents_it_loop:
unless parents_it goto done
cur_class = shift parents_it

# Get Parrot-level class.
.local pmc parrot_class, attributes, attr_it, cur_attr_hash, cur_attr_info
parrot_class = self.'get_parrotclass'(cur_class)

# Iterate over attributes and build an Attribute descriptor for each one.
attributes = parrot_class.'attributes'()
attr_it = iter attributes
attr_it_loop:
unless attr_it goto attr_it_loop_end
$S0 = shift attr_it
cur_attr_hash = attributes[$S0]
$S0 = cur_attr_hash['name']
cur_attr_info = attr_proto.'new'('name' => $S0)
result_list.'push'(cur_attr_info)
goto attr_it_loop
attr_it_loop_end:
goto parents_it_loop

done:
.return (result_list)
.end


=item parents()

Gets a list of this class' parents.
Expand Down
5 changes: 5 additions & 0 deletions src/setting/Attribute.pm
@@ -0,0 +1,5 @@
class Attribute {
has $.name;
}

# vim: ft=perl6

0 comments on commit 03aa56f

Please sign in to comment.