You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Divide the run() function in smaller portions #366
Currently, the run() function is around 500 lines long. This is going to quickly become unmaintainable, so we need to divide this.
The first thing that comes to my mind to improve this is to just create new function for each match arm, but as we saw in the parser, we can probably do this better and easier to understand.
One option is to have an Executable trait, as I proposed in #304. This trait would just be as simple as this:
Then, I think that we should change the Node enum to be just a Box<dyn Executable>. And each Node type should be a struct where we could use Box to box dynamic types, or we could use compile-time generics to have less allocations (but longer compile times).
Then we implement this trait individually for each of the node types, which is easily extensible, and we reduce the run() function to:
Hmmm. I think doing this at compile time is better than having to do it at runtime.
Using Box<dyn Trait> has to allocate and use dynamic dispatch (vtable) which would worsen the execution time.
Hmmm. I think doing this at compile time is better than having to do it at runtime.
Using Box<dyn Trait> has to allocate and use dynamic dispatch (vtable) which would worsen the execution time.
So, Node would be Node<T: Executable>, but that would make it more difficult to have for example a Vec<Node> of different kinds, and we already use Box inside of nodes, this would just make a Box and only one allocation per node.
Activity
HalidOdat commentedon May 2, 2020
Hmmm. I think doing this at compile time is better than having to do it at runtime.
Using
Box<dyn Trait>has to allocate and use dynamic dispatch (vtable) which would worsen the execution time.Razican commentedon May 2, 2020
So,
Nodewould beNode<T: Executable>, but that would make it more difficult to have for example aVec<Node>of different kinds, and we already useBoxinside of nodes, this would just make aBoxand only one allocation per node.Razican commentedon May 7, 2020
A different option would be to still have an
enum, but each of the enum members would be just a box to a givenExecutable.Razican commentedon May 26, 2020
Tracking list of nodes added, now that we have the infrastructure in place.
This could be a very good first issue, since it shows you how the AST nodes work, so feel free to claim it and to ask for help!
Lan2u commentedon May 26, 2020
I shall give it a go :)
Razican commentedon May 26, 2020
Go ahead!