mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 18:51:09 +01:00
Make the AST mutable (#849)
The code is pretty intertwined: having the AST be truly mutable means (to me) changing parser.ypp to return non-const values, but then the way things are passed around between objects should be non-const (particularly an issue with lists), which then creates issues with construction of lists in the TypeChecker, which then TypeChecker needs to mostly be non-const. Due to the difficulties in breaking this apart, whereas I'd previously considering refactoring accessor naming in the same PR, I've largely avoided doing so. The intent is then that this PR focuses mainly on const -> non-const AST behavior. call_main moves out of interpreter.cpp so that interpreter.cpp can receive a fully const AST.
This commit is contained in:
@@ -1133,7 +1133,8 @@ void Interpreter::Step() {
|
||||
}
|
||||
|
||||
auto Interpreter::InterpProgram(
|
||||
const std::vector<Nonnull<const Declaration*>>& fs) -> int {
|
||||
const std::vector<Nonnull<const Declaration*>>& fs,
|
||||
Nonnull<const Expression*> call_main) -> int {
|
||||
// Check that the interpreter is in a clean state.
|
||||
CHECK(globals.IsEmpty());
|
||||
CHECK(stack.IsEmpty());
|
||||
@@ -1144,11 +1145,6 @@ auto Interpreter::InterpProgram(
|
||||
}
|
||||
InitGlobals(fs);
|
||||
|
||||
SourceLocation loc("<InterpProgram()>", 0);
|
||||
|
||||
Nonnull<const Expression*> arg = arena->New<TupleLiteral>(loc);
|
||||
Nonnull<const Expression*> call_main = arena->New<CallExpression>(
|
||||
loc, arena->New<IdentifierExpression>(loc, "main"), arg);
|
||||
auto todo = Stack<Nonnull<Action*>>(arena->New<ExpressionAction>(call_main));
|
||||
auto scopes = Stack<Nonnull<Scope*>>(arena->New<Scope>(globals));
|
||||
stack = Stack<Nonnull<Frame*>>(arena->New<Frame>("top", scopes, todo));
|
||||
|
||||
Reference in New Issue
Block a user