Files
carbon-lang/executable_semantics/interpreter/exec_program.cpp
T
Jeremy G. Siek ac0b810bf3 Adds basic support for class functions and methods. (#1057)
* adding methods to the ast

* pre commit stuff?

* implementation of class functions

* implemented methods

* some cleanup

* more cleanup

* add newlines in test programs

* pre-commit fixups

* added include of return_term.h

* a test of a method calling another method

* replacing Member with Declaration

* removing the member.h etc files

* clarify a type annotation

* update uses of FunctionDeclaration

* remove ReturnTarget, no longer needed

* more cleanup

* more cleanup

* yet more cleanup, playing with pre-commit

* did a pre-commit run --all-files

* fixed const issue

* remove comment

* checking dependencies in BUILD files and headers

* pre-commit working now

* refactor NominalClassType to just hold a pointer to the class declaration

* remove Member from rtti

* responding to Geoffreys review

* change field_types to a non-member function
2022-02-05 12:30:13 -05:00

57 lines
1.9 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "executable_semantics/interpreter/exec_program.h"
#include <variant>
#include "common/check.h"
#include "common/ostream.h"
#include "executable_semantics/common/arena.h"
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/resolve_control_flow.h"
#include "executable_semantics/interpreter/resolve_names.h"
#include "executable_semantics/interpreter/type_checker.h"
namespace Carbon {
void ExecProgram(Nonnull<Arena*> arena, AST ast, bool trace) {
if (trace) {
llvm::outs() << "********** source program **********\n";
for (const auto decl : ast.declarations) {
llvm::outs() << *decl;
}
}
SourceLocation source_loc("<Main()>", 0);
ast.main_call = arena->New<CallExpression>(
source_loc, arena->New<IdentifierExpression>(source_loc, "Main"),
arena->New<TupleLiteral>(source_loc));
// Although name resolution is currently done once, generic programming
// (particularly templates) may require more passes.
if (trace) {
llvm::outs() << "********** resolving names **********\n";
}
ResolveNames(ast);
if (trace) {
llvm::outs() << "********** resolving control flow **********\n";
}
ResolveControlFlow(ast);
if (trace) {
llvm::outs() << "********** type checking **********\n";
}
TypeChecker(arena, trace).TypeCheck(ast);
if (trace) {
llvm::outs() << "\n";
llvm::outs() << "********** type checking complete **********\n";
for (const auto decl : ast.declarations) {
llvm::outs() << *decl;
}
llvm::outs() << "********** starting execution **********\n";
}
int result = InterpProgram(ast, arena, trace);
llvm::outs() << "result: " << result << "\n";
}
} // namespace Carbon