Description
Currently, cursors that access variables implement a name(self) -> str
function which return the name attribute of the Sym
node. However, Syms don't just represent a string name, it really represents a pair of (name, id)
. This means that there is currently no way in user-code to (unambiguously) check if two symbols are the same. We need to expose the id information somehow to make sure we can ask questions about symbol equalities, build environments in a way that is unambiguous.
What we will want out of this API:
- Be able to do comparisons on two symbols.
- Be able to build environments out of symbols: it needs to be hashable.
- Be able to introspect it is components: the name and the id
There are a few design choices here:
- Should we just let the cursors return a free object (
Symbol
) or make it a navigation to another cursorSymbolCursor
. - How can we support the functionalities above with either of those APIs.
Symbol:
class Symbol:
_impl: Sym
# wrappers around all the functions Sym implements (except for copy()): https://github.com/exo-lang/exo/blob/59ed05f2aa6ec5f76db208889a7539543adedc6f/src/exo/prelude.py#L21
SymbolCursor:
It is a bit confusing to directly implement things like __hash__
or __eq__
on a cursor when we haven't implemented for any other cursor. The meaning of equality is also ambiguous between location (cursor path) and the node. One option is to have the cursor return the Symbol
object above.
class SymbolCursor:
_impl: Sym
def get_symbol(self) -> Symbol
The alternative:
class SymbolCursor:
_impl: Sym
def name() -> str
def id() -> int
def get_pair() -> Tuple(str, int)
# This tuple can be used for comparison and be hashable.
I don't think there is really a reason to be able to point to a Symbol. So, I think the free object design is what makes more sense.