-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Divide the run()
function in smaller portions
#366
Comments
Hmmm. I think doing this at compile time is better than having to do it at runtime. |
So, |
A different option would be to still have an |
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! |
I shall give it a go :) |
Go ahead! |
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 aBox<dyn Executable>
. And eachNode
type should be a struct where we could useBox
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:Tracking:
Node::ArrayDecl
Node::ArrowFunctionDecl
Node::Assign
Node::BinOp
Node::Block
Node::Break
Node::Call
Node::ConditionalOp
Node::Const
Node::ConstDeclList
Node::Continue
Node::DoWhileLoop
Node::FunctionDecl
Node::FunctionExpr
Node::GetConstField
Node::GetField
Node::ForLoop
Node::If
Node::LetDeclList
Node::Identifier
Node::New
Node::Object
Node::Return
Node::Switch
Node::Spread
StatementList
Node::Throw
Node::Try
Node::This
Node::UnaryOp
Node::VarDeclList
Node::WhileLoop
The text was updated successfully, but these errors were encountered: