Add syntax for package and library (#792)

Doesn't add much logic, only takes advantage of parser structure for the ordering enforcement.

Note import_nonexistent tests should probably fail, but writing import tests needs a chain of functionality, and I figured I'd just start adding some to validate the syntax (not adding existent imports because that'd require multi-file structure).
This commit is contained in:
Jon Meow
2021-09-02 16:01:15 -07:00
committed by GitHub
parent 0980df65cd
commit a03536a196
152 changed files with 433 additions and 63 deletions
@@ -15,7 +15,7 @@ namespace Carbon {
// Adds builtins, currently only Print(). Note Print() is experimental, not
// standardized, but is made available for printing state in tests.
static void AddIntrinsics(std::list<Ptr<const Declaration>>* fs) {
static void AddIntrinsics(std::list<Ptr<const Declaration>>* declarations) {
SourceLocation loc("<intrinsic>", 0);
std::vector<TuplePattern::Field> print_fields = {TuplePattern::Field(
"0", global_arena->New<BindingPattern>(
@@ -34,24 +34,24 @@ static void AddIntrinsics(std::list<Ptr<const Declaration>>* fs) {
global_arena->New<ExpressionPattern>(
global_arena->New<TupleLiteral>(loc)),
/*is_omitted_return_type=*/false, print_return));
fs->insert(fs->begin(), print);
declarations->insert(declarations->begin(), print);
}
void ExecProgram(std::list<Ptr<const Declaration>> fs) {
AddIntrinsics(&fs);
void ExecProgram(AST ast) {
AddIntrinsics(&ast.declarations);
if (tracing_output) {
llvm::outs() << "********** source program **********\n";
for (const auto decl : fs) {
for (const auto decl : ast.declarations) {
llvm::outs() << *decl;
}
llvm::outs() << "********** type checking **********\n";
}
TypeChecker type_checker;
TypeChecker::TypeCheckContext p = type_checker.TopLevel(fs);
TypeChecker::TypeCheckContext p = type_checker.TopLevel(ast.declarations);
TypeEnv top = p.types;
Env ct_top = p.values;
std::list<Ptr<const Declaration>> new_decls;
for (const auto decl : fs) {
for (const auto decl : ast.declarations) {
new_decls.push_back(type_checker.MakeTypeChecked(decl, top, ct_top));
}
if (tracing_output) {