Skip to content

Commit

Permalink
Remove special-case code for handling typed attributes and just emit …
Browse files Browse the repository at this point in the history
…a call to trait_mod:<of>, like we do with variables, passing an AttributeDeclarand instead of a ContainerDeclarand.
  • Loading branch information
jnthn committed Aug 21, 2009
1 parent fd812be commit 5627efa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
17 changes: 1 addition & 16 deletions src/classes/Object.pir
Expand Up @@ -426,13 +426,12 @@ XXX This had probably best really just tailcall .^CREATE; move this stuff later.
attrinit_loop:
unless it goto attrinit_done
.local string attrname
.local pmc attrhash, itypeclass, type
.local pmc attrhash, itypeclass
attrname = shift it
$I0 = index attrname, '!'
if $I0 < 0 goto attrinit_loop
attrhash = attributes[attrname]
itypeclass = attrhash['itype']
type = attrhash['type']
$S0 = substr attrname, 0, 1
unless null itypeclass goto attrinit_itype
if $S0 == '@' goto attrinit_array
Expand All @@ -449,20 +448,6 @@ XXX This had probably best really just tailcall .^CREATE; move this stuff later.
.local pmc attr
attr = new itypeclass
setattribute example, cur_class, attrname, attr
if null type goto type_done
if $S0 == '@' goto pos_type
if $S0 == '%' goto ass_type
setprop attr, 'type', type
goto type_done
ass_type:
$P0 = get_hll_global 'Associative'
goto apply_type
pos_type:
$P0 = get_hll_global 'Positional'
apply_type:
$P0 = $P0.'!select'(type)
'infix:does'(attr, $P0)
type_done:
traits = attrhash['traits']
if null traits goto traits_done
$P0 = getprop 'metaclass', cur_class
Expand Down
15 changes: 12 additions & 3 deletions src/parser/actions.pm
Expand Up @@ -1807,7 +1807,7 @@ method scope_declarator($/) {
if $readtype eq 'rw' {
$has.push(PAST::Val.new( :value(1), :named('rw') ));
}
if $var<traitlist> {
if $var<traitlist> || $type {
# If we have a handles, then we pass that specially.
my $handles := has_compiler_trait($var<traitlist>, 'trait_mod:handles');
if $handles {
Expand All @@ -1818,13 +1818,22 @@ method scope_declarator($/) {
# We'll make a block for calling other handles, which'll be
# thunked.
my $trait_stmts := PAST::Stmts.new();
emit_traits($var<traitlist>, $trait_stmts, PAST::Op.new(
my $declarand := PAST::Op.new(
:pasttype('callmethod'), :name('new'),
PAST::Var.new( :name('AttributeDeclarand'), :scope('package'), :namespace(list()) ),
PAST::Var.new( :name('$_'), :scope('lexical'), :named('container') ),
PAST::Val.new( :value($var.name()), :named('name') ),
PAST::Var.new( :name('$how'), :scope('lexical'), :named('how') )
));
);
emit_traits($var<traitlist>, $trait_stmts, $declarand);
if $type {
$trait_stmts.push(PAST::Op.new(
:pasttype('call'),
:name('trait_mod:of'),
$declarand,
$type
));
}
if +@($trait_stmts) > 0 {
my $trait_block := PAST::Block.new(
:blocktype('declaration'),
Expand Down
4 changes: 4 additions & 0 deletions src/setting/traits.pm
Expand Up @@ -89,6 +89,10 @@ multi trait_mod:<is>(Code $block, :$default!) {
};
}
multi trait_mod:<is>(ContainerDeclarand $c, :$rw!) {
# The default anyway, so nothing to do.
}

multi trait_mod:<does>(Class $class is rw, Object $role) {
Q:PIR {
.local pmc metaclass, role
Expand Down

0 comments on commit 5627efa

Please sign in to comment.