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

Cannot set the bits of UInt data with __setitem__. #552

Open
iSunfield opened this issue Apr 14, 2024 · 0 comments
Open

Cannot set the bits of UInt data with __setitem__. #552

iSunfield opened this issue Apr 14, 2024 · 0 comments

Comments

@iSunfield
Copy link

iSunfield commented Apr 14, 2024

I tried to implement code to extend the UInt[N] class to set a specific bit of UInt[N] type data, but it seems that the setitem argument, self, is given a copy of the UInt[N] data as an argument, so the setitem function I could not set a specific bit of UInt[N] type data. After checking with the following simple code, it seems that the cause is that the address of the A variable and the address of self in setitem are different. Is there a way to use setitem to set bits of data of type UInt[N]?

@extend
class UInt:
    def __setitem__(self,Slice,val):
        print(f"self of A address:{__ptr__(self)} , Slice:{Slice.start}:{Slice.stop}:{Slice.step} , Set value:{val}")
        self = UInt[N](int(val))

A = UInt[64](0)
B = UInt[32](1)

A[0:32] = B
print(f"A address:{__ptr__(A)}, Result:{A}")

self of A address:0x7ffe93eecbe8 , Slice:0:32:None , Set value:1
A address:0x7ffe93eecbb8, Result:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant