mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 06:50:12 +01:00
* add command-line flag to enable/disable tracing output * adding missing exit for pattern variable in wrong context and a test case for it (#324) * Update executable_semantics/interpreter/interpreter.cpp comment on separate line as code Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com> * fix interpreter's handling of optional else of if statement (#323) * Update pattern_variable_fail.golden due to error (#334) * Use llvm's CommandLine for parsing (#332) * GitHub testing action (#331) Co-authored-by: Chandler Carruth <chandlerc@gmail.com> * add copyright * Create a Dictionary abstraction over the raw Cons list. (#327) * Create a Dictionary abstraction over the raw Cons list. * renamed Cons and some methods of Dictionary, various other cleanup * Update executable_semantics/tracing_flag.cpp added namespace comment Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com> * added a comment to cpp file Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com> Co-authored-by: Dave Abrahams <dabrahams@google.com> Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
51 lines
1.5 KiB
C++
51 lines
1.5 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/syntax_helpers.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include "executable_semantics/interpreter/interpreter.h"
|
|
#include "executable_semantics/interpreter/typecheck.h"
|
|
#include "executable_semantics/tracing_flag.h"
|
|
|
|
namespace Carbon {
|
|
|
|
const char* input_filename = nullptr;
|
|
|
|
void PrintSyntaxError(char* error, int line_num) {
|
|
std::cerr << input_filename << ":" << line_num << ": " << error << std::endl;
|
|
exit(-1);
|
|
}
|
|
|
|
void ExecProgram(std::list<Declaration>* fs) {
|
|
if (tracing_output) {
|
|
std::cout << "********** source program **********" << std::endl;
|
|
for (const auto& decl : *fs) {
|
|
decl.Print();
|
|
}
|
|
std::cout << "********** type checking **********" << std::endl;
|
|
}
|
|
state = new State(); // Compile-time state.
|
|
std::pair<TypeEnv*, Env*> p = TopLevel(fs);
|
|
TypeEnv* top = p.first;
|
|
Env* ct_top = p.second;
|
|
std::list<Declaration> new_decls;
|
|
for (const auto& decl : *fs) {
|
|
new_decls.push_back(decl.TypeChecked(top, ct_top));
|
|
}
|
|
if (tracing_output) {
|
|
std::cout << std::endl;
|
|
std::cout << "********** type checking complete **********" << std::endl;
|
|
for (const auto& decl : new_decls) {
|
|
decl.Print();
|
|
}
|
|
std::cout << "********** starting execution **********" << std::endl;
|
|
}
|
|
int result = InterpProgram(&new_decls);
|
|
std::cout << "result: " << result << std::endl;
|
|
}
|
|
|
|
} // namespace Carbon
|