Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add support for unions in NativeCall using CUnion repr
  • Loading branch information
FROGGS committed May 19, 2015
1 parent f4de5f3 commit 67245d3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/NativeCall.pm
Expand Up @@ -155,6 +155,7 @@ my %repr_map =
'CStruct' => 'cstruct',
'CPointer' => 'cpointer',
'CArray' => 'carray',
'CUnion' => 'cunion',
'VMArray' => 'vmarray',
;
sub type_code_for(Mu ::T) {
Expand Down Expand Up @@ -413,6 +414,10 @@ multi trait_mod:<is>(Routine $p, :$encoded!) is export(:DEFAULT, :traits) {
$p does NativeCallEncoded[$encoded];
}

multi trait_mod:<is>(Attribute $a, :$inlined!) is export(:DEFAULT, :traits) {
nqp::bindattr_i(nqp::decont($a), $a.WHAT, '$!inlined', 1);
}

role ExplicitlyManagedString {
has $.cstr is rw;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -21,10 +21,12 @@ my class BOOTSTRAPATTR {
has $!type;
has $!box_target;
has $!package;
has $!inlined;
method name() { $!name }
method type() { $!type }
method box_target() { $!box_target }
method package() { $!package }
method inlined() { $!inlined }
method has_accessor() { 0 }
method has-accessor() { 0 }
method positional_delegate() { 0 }
Expand Down Expand Up @@ -1081,20 +1083,22 @@ BEGIN {
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!auto_viv_container>, :type(Mu), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!build_closure>, :type(Mu), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!package>, :type(Mu), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!inlined>, :type(int), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!box_target>, :type(int), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!positional_delegate>, :type(int), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!associative_delegate>, :type(int), :package(Attribute)));
Attribute.HOW.add_attribute(Attribute, BOOTSTRAPATTR.new(:name<$!why>, :type(Mu), :package(Attribute)));

# Need new and accessor methods for Attribute in here for now.
Attribute.HOW.add_method(Attribute, 'new',
nqp::getstaticcode(sub ($self, :$name!, :$type!, :$package!, :$has_accessor,
nqp::getstaticcode(sub ($self, :$name!, :$type!, :$package!, :$inlined = 0, :$has_accessor,
:$positional_delegate = 0, :$associative_delegate = 0, *%other) {
my $attr := nqp::create($self);
nqp::bindattr_s($attr, Attribute, '$!name', $name);
nqp::bindattr($attr, Attribute, '$!type', nqp::decont($type));
nqp::bindattr_i($attr, Attribute, '$!has_accessor', $has_accessor);
nqp::bindattr($attr, Attribute, '$!package', $package);
nqp::bindattr_i($attr, Attribute, '$!inlined', $inlined);
if nqp::existskey(%other, 'container_descriptor') {
nqp::bindattr($attr, Attribute, '$!container_descriptor', %other<container_descriptor>);
if nqp::existskey(%other, 'auto_viv_container') {
Expand Down
3 changes: 3 additions & 0 deletions src/Perl6/Metamodel/REPRComposeProtocol.nqp
Expand Up @@ -46,6 +46,9 @@ role Perl6::Metamodel::REPRComposeProtocol {
if $attr.associative_delegate {
%attr_info<associative_delegate> := 1;
}
if nqp::can($attr, 'inlined') {
%attr_info<inlined> := $attr.inlined;
}
nqp::push(@attrs, %attr_info);
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/Attribute.pm
Expand Up @@ -8,6 +8,7 @@ my class Attribute { # declared in BOOTSTRAP
# has Mu $!auto_viv_container;
# has Mu $!build_closure;
# has Mu $!package;
# has int $!inlined;
# has int $!positional_delegate;
# has int $!associative_delegate;
# has Mu $!why;
Expand Down Expand Up @@ -110,6 +111,7 @@ my class Attribute { # declared in BOOTSTRAP
method has-accessor() { ?$!has_accessor }
method readonly() { !self.rw }
method package() { $!package }
method inlined() { $!inlined }
multi method Str(Attribute:D:) { self.name }
multi method gist(Attribute:D:) { self.type.^name ~ " " ~ self.name }

Expand Down

0 comments on commit 67245d3

Please sign in to comment.