Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atrribute Introspect shape #6197

Open
p6rt opened this issue Apr 19, 2017 · 6 comments
Open

Atrribute Introspect shape #6197

p6rt opened this issue Apr 19, 2017 · 6 comments
Labels
NYI Features not yet implemented

Comments

@p6rt
Copy link

p6rt commented Apr 19, 2017

Migrated from rt.perl.org#131174 (status was 'open')

Searchable as RT131174$

@p6rt
Copy link
Author

p6rt commented Apr 19, 2017

From @dwarring

AFAIK there's currently no way of introspecting the shape of a Class
attribute that's a native shaped array.

I'd like this feature for the Native​::Packing module. For example to
interpret​:

class C {
  has byte @​.gif-header[6];
  has uint16 $.width;
  has uint16 $height;
}

At the moment, I just can't determine the size of shaped native arrays,
such as @​.gif-header above​:

say .type, .container
  for C.^attributes;

(Positional[byte])(array[byte])
(uint16)(uint16)
(uint16)(uint16)

@p6rt
Copy link
Author

p6rt commented Apr 19, 2017

From @zoffixznet

On Tue, 18 Apr 2017 20​:34​:15 -0700, david.warring wrote​:

AFAIK there's currently no way of introspecting the shape of a Class
attribute that's a native shaped array.

I'd like this feature for the Native​::Packing module. For example to
interpret​:

class C {
has byte @​.gif-header[6];
has uint16 $.width;
has uint16 $height;
}

At the moment, I just can't determine the size of shaped native arrays,
such as @​.gif-header above​:

say .type, .container
for C.^attributes;

(Positional[byte])(array[byte])
(uint16)(uint16)
(uint16)(uint16)

Seems .container does have method .shape, but it returns a Whatever​:

class C {
  has byte @​.gif-header[6];
  has uint16 $.width;
  has uint16 $height;
}
say .container.shape for C.^attributes[0]; # (*)
dd C.new.gif-header.shape; # (6,)

my byte @​z[6];
dd @​z.shape; # (6,)

@p6rt
Copy link
Author

p6rt commented Apr 19, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 20, 2017

From @dwarring

I've added a fudged test to S12-introspection/attributes.t
that the container shape is as declared; not a Whatever.

On Wed, 19 Apr 2017 03​:14​:35 -0700, cpan@​zoffix.com wrote​:

On Tue, 18 Apr 2017 20​:34​:15 -0700, david.warring wrote​:

AFAIK there's currently no way of introspecting the shape of a Class
attribute that's a native shaped array.

I'd like this feature for the Native​::Packing module. For example to
interpret​:

class C {
has byte @​.gif-header[6];
has uint16 $.width;
has uint16 $height;
}

At the moment, I just can't determine the size of shaped native arrays,
such as @​.gif-header above​:

say .type, .container
for C.^attributes;

(Positional[byte])(array[byte])
(uint16)(uint16)
(uint16)(uint16)

Seems .container does have method .shape, but it returns a Whatever​:

class C {
has byte @​.gif-header[6];
has uint16 $.width;
has uint16 $height;
}
say .container.shape for C.^attributes[0]; # (*)
dd C.new.gif-header.shape; # (6,)

my byte @​z[6];
dd @​z.shape; # (6,)

@p6rt p6rt added the NYI Features not yet implemented label Jan 5, 2020
@dwarring
Copy link

dwarring commented Apr 4, 2022

Rechecking as of 2022.03. The example in this is now a syntax error (with both has and HAS variants):

$ raku -v
Welcome to Rakudo™ v2022.03-127-gbb9d7497b.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.03-13-ga3476e286.
$ raku -e'class C { has byte @​.gif-header[6];}'
===SORRY!=== Error while compiling -e
Cannot declare an anonymous attribute
at -e:1
------> class C { has byte @⏏​.gif-header[6];}
    expecting any of:
        constraint
$ raku -e'class C { HAS byte @​.gif-header[6];}'
===SORRY!=== Error while compiling -e
Cannot declare an anonymous attribute
at -e:1
------> class C { HAS byte @⏏​.gif-header[6];}
    expecting any of:
        constraint

@dwarring
Copy link

dwarring commented Apr 4, 2022

New formulation, based on this this SO question:

use NativeCall;
class C is repr('CStruct') {
    HAS int8 @.gif-header[6] is CArray;
    has int32 $.width;
    has int32 $.height;
}

say nativesizeof(C);
dd C.new.gif-header.elems; # 6

nativesizeof(C) now evaluates correctly, but C.new.gif-header.elems is zero.

So, I'm still not sure of a way of introspecting the gif-header array length in isolation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NYI Features not yet implemented
Projects
None yet
Development

No branches or pull requests

2 participants