[libre-riscv-dev] [Bug 353] formal proof of soc.regfile classes RegFile and RegFileArray needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed May 27 19:08:15 BST 2020


--- Comment #6 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Cole Poirier from comment #5)

> Are class attributes (self.x) declared within __init__ public and those
> declared within elaborate() private? 

in python the concept of public and private in classes does not exist, like it
does in c++

class instance atttributes are therefore *always* public.  there does exist
however a convention that if something starts with underscores it is *by
convention* considered "not for public use".

what you are getting confused about is "scope".

within a function, any local variables are entirely local.  however note that
stuff declared in a module is *also* accessible within the function.

therefore, only variables created *inside* the function are private scope to
that function.

> I though all python class attributes
> were public, and in order to get 'private' variables in a class you have to
> do as you did in virtual_port.py by simply declaring it a variable and not
> an attribute of the class object. I ask because I'm having an issue where
> I'm trying to access self.reg of class Register(), which is declared inside
> elaborate(),

no it is not declared (this is not c), it is created, and it is created only
when the function elaborate is called.

how can you expect Register.reg to be created when Register.elaborate has not
been called?

> and I get an error, but accessing any of the self.xyz
> attributes like self.width declared in __init__ works fine.

this is correct behaviour.  python is not a static language.

commit it let's have a look.

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-riscv-dev mailing list