Comments (2)
Hi @bifunctor ,
Good point! Never really thought about it, but it might be convenient to make the ir
nodes hashable. One reason why they perhaps are not hashable is that they might be modified (in other words, they might not be immutable). For example the python list
is mutable, and hence not hashable. A tuple
on the other hand is immutable, and hence hashable. The IR nodes shoud probably be immutable, but I know that they are sometimes modified in place, for example in some optimization passes.
So in short: no specific reason, just never thought about it.
from ppci.
tl;dr: Its a good idea to implement __eq__
, and (maybe) an okay idea to implement __hash__
.
I believe that support should be added for __eq__
and __hash__
(or at very least __eq__
). As you said, hashing might be problematic in the case of mutability. A way to get around this would be to hash only some defining attributes. For example, Block
's name
and function
won't be changed (once function
is set that is). So Block
could be hashed as so:
class Block:
...
def __hash__(self):
assert self.function, "function should have been set"
return hash((self.name, self.function))
or if you wish to be able to compare blocks without having added them to functions:
class Block:
...
def __hash__(self):
return hash(self.name)
and so on.
from ppci.
Related Issues (20)
- ppci-cc: binary operators & | ^ and unary ~ & not supported in initializer constants
- ppci-cc: cannot take the address of a function static variable for initializing a function static variable
- ppci-ld: linker imports too many modules from the libraries
- ppci-cc: ++ and -- should work for floating point types HOT 2
- ppci-cc: conditional operator does not work with struct/union types
- pcci-cc: handling of array type of unknown size
- ppci-cc: initializing a global enum variable is not possible HOT 2
- ppci-cc: cannot compile combined struct assignment
- ppci-cc: switch/case statements should be better tested in the front-end HOT 1
- Implementation of sbrk HOT 9
- Tool to compile IR to machine code? HOT 1
- Translating to ppci assembly HOT 7
- Pass pointer HOT 1
- Compiling and running a simple GC
- Reading section failed HOT 1
- c parser crash in stdlib.h HOT 1
- Evaluation of constant expression in preprocessing directives may produce incorrect results
- Missing diagnostics: "invalid constant"
- ARM clarification
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppci.