-
Notifications
You must be signed in to change notification settings - Fork 21
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
Refactor compiler skeleton #22
Refactor compiler skeleton #22
Conversation
…created AST namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the awesome changes! I have some comments below:
- I also like
T&
/T*
more thanT &
/T *
. #pragma once
seems like a less-error prone concept, but StackOverflow is still divided - do you have some insights from industry? The companies I worked for still used classic header guards.- Namespace names should be lowercase according to Google Style Guide that we are following.
NodePtr
usage is inconsistent - there are still many places that useNode*
.- I like the use of
unique_ptr
- however, it might be a little tricky, so it should definitely be explained well in the docs. - New implementation of
type_specifier
is a bit advanced, but I do like the changes. Hopefully we can assume that people implementing more types thanint
would be proficient enough to understand the used constructs. - I think
type_specifier
should still be split into.hpp
and.cpp
as currently all the implementation is in.hpp
. emplace_back
needs a mention in the docs along with move semantics in general as it's certainly an advanced topic.
It'd be good to split the less intrusive changes that you suggest into a separate PR, so that it can get merged into main
ASAP, while the rest is going to wait on a separate branch.
To address your points:
From my experience in industry,
sadge. will update
Not 100% sure I follow here. I'm pretty sure I use
Given that they have to compile
Given that
Can also touch on it, currently using it to ensure that In terms of less intrusive changes to include, what are you thinking? I could add (in order of least to most intrusive):
|
Update:
|
Changes:
#ifndef
header guards with#pragma once
AST
namespace - it's in general good practice to do this in projects, and I think it'll help encourage students to do this without being too confusing for them.Node*
stored by nodes toNodePtr = std::unique_ptr<const Node>
. This change incorporates a couple elements:const
reduces the chances of programmer errornew
anddelete
manually is very C-like (/ pre C++11). Although it's all that students are taught in Y1, I think understanding what astd::unique_ptr
is is relatively straightforward, and encourages students to use a more modern interface.NodePtr
as an alias for the stored type, it not only saves on characters, but makes it much easier for students to switch this type out with something else (like raw pointers) if they find the use ofstd::unique_ptr
too confusing.TypeSpecifier
is no longer aNode
- this makes sense imo because just a type specifier is never enough information for you to produce assembly, meaning thatEmitRISC(...)
will always have an empty / throwing implementation. Also switched to using anenum class
instead of astd::string
for hopefully obvious reasons.branches_
fromNode
- see here for reasoningmain
to fix this since it's minimally invasive and it's kinda unfair to assess students on not leaking memory if we give them a leaky base.T &
toT&
- I think it's much nicer to have the type information all together rather than separated by whitespace (sorry, I couldn't resist)Other considered changes:
Expression
). Unfortunately, with the basic skeleton we provide, there's no really meaningful intermediate abstract classes we can really provide, for example, we could makeReturn
store a pointer to anExpression
instead of a general node, but currently anExpression
and aNode
are exactly the same (it would also make it more difficult for them to switch out the pointer implementation they're using). In general, I'm hoping thatTypeSpecifier
is enough to show them that it's fine for differentNode
s to store things which aren'tNode
s / it's fine for them to add more types to their parser.Identifier
, it would be best practice to use move semantics to avoid copying the string unnecessarily. However, move semantics / r-values is definitely something I'd classify as a more advanced topic, and since we're not really concerned about performance, I don't think there's enough upside to include it to justify the extra burden on the students.