mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:34:41 +01:00
Replace all lists with vectors (#815)
This commit is contained in:
@@ -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>>* declarations) {
|
||||
static void AddIntrinsics(std::vector<Ptr<const Declaration>>* declarations) {
|
||||
SourceLocation loc("<intrinsic>", 0);
|
||||
std::vector<TuplePattern::Field> print_fields = {TuplePattern::Field(
|
||||
"0", global_arena->New<BindingPattern>(
|
||||
@@ -50,7 +50,7 @@ void ExecProgram(AST ast) {
|
||||
TypeChecker::TypeCheckContext p = type_checker.TopLevel(ast.declarations);
|
||||
TypeEnv top = p.types;
|
||||
Env ct_top = p.values;
|
||||
std::list<Ptr<const Declaration>> new_decls;
|
||||
std::vector<Ptr<const Declaration>> new_decls;
|
||||
for (const auto decl : ast.declarations) {
|
||||
new_decls.push_back(type_checker.MakeTypeChecked(decl, top, ct_top));
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_EXEC_PROGRAM_H_
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_EXEC_PROGRAM_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "executable_semantics/ast/ast.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_FRAME_H_
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_FRAME_H_
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/interpreter/action.h"
|
||||
@@ -20,12 +20,12 @@ namespace Carbon {
|
||||
using Env = Dictionary<std::string, Address>;
|
||||
|
||||
struct Scope {
|
||||
explicit Scope(Env values) : Scope(values, std::list<std::string>()) {}
|
||||
Scope(Env values, std::list<std::string> l)
|
||||
explicit Scope(Env values) : Scope(values, std::vector<std::string>()) {}
|
||||
Scope(Env values, std::vector<std::string> l)
|
||||
: values(values), locals(std::move(l)) {}
|
||||
|
||||
Env values;
|
||||
std::list<std::string> locals;
|
||||
std::vector<std::string> locals;
|
||||
};
|
||||
|
||||
// A frame represents either a function call or a delimited continuation.
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "executable_semantics/interpreter/interpreter.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
@@ -174,7 +173,7 @@ void Interpreter::InitEnv(const Declaration& d, Env* env) {
|
||||
}
|
||||
}
|
||||
|
||||
void Interpreter::InitGlobals(const std::list<Ptr<const Declaration>>& fs) {
|
||||
void Interpreter::InitGlobals(const std::vector<Ptr<const Declaration>>& fs) {
|
||||
for (const auto d : fs) {
|
||||
InitEnv(*d, &globals);
|
||||
}
|
||||
@@ -772,14 +771,13 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
frame->scopes.Pop();
|
||||
return Done{};
|
||||
}
|
||||
auto c = match_stmt.Clauses().begin();
|
||||
std::advance(c, clause_num);
|
||||
auto c = match_stmt.Clauses()[clause_num];
|
||||
|
||||
if (act->Pos() % 2 == 1) {
|
||||
// start interpreting the pattern of the clause
|
||||
// { {v :: (match ([]) ...) :: C, E, F} :: S, H}
|
||||
// -> { {pi :: (match ([]) ...) :: C, E, F} :: S, H}
|
||||
return Spawn{global_arena->New<PatternAction>(c->first)};
|
||||
return Spawn{global_arena->New<PatternAction>(c.first)};
|
||||
} else { // try to match
|
||||
auto v = act->Results()[0];
|
||||
auto pat = act->Results()[clause_num + 1];
|
||||
@@ -792,7 +790,7 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
frame->scopes.Top()->values.Set(name, value);
|
||||
frame->scopes.Top()->locals.push_back(name);
|
||||
}
|
||||
return Spawn{global_arena->New<StatementAction>(c->second)};
|
||||
return Spawn{global_arena->New<StatementAction>(c.second)};
|
||||
} else {
|
||||
return RunAgain{};
|
||||
}
|
||||
@@ -1090,7 +1088,7 @@ class Interpreter::DoTransition {
|
||||
<< "internal error in call_function, pattern match failed";
|
||||
// Create the new frame and push it on the stack
|
||||
Env values = interpreter->globals;
|
||||
std::list<std::string> params;
|
||||
std::vector<std::string> params;
|
||||
for (const auto& [name, value] : *matches) {
|
||||
values.Set(name, value);
|
||||
params.push_back(name);
|
||||
@@ -1134,7 +1132,7 @@ void Interpreter::Step() {
|
||||
} // switch
|
||||
}
|
||||
|
||||
auto Interpreter::InterpProgram(const std::list<Ptr<const Declaration>>& fs)
|
||||
auto Interpreter::InterpProgram(const std::vector<Ptr<const Declaration>>& fs)
|
||||
-> int {
|
||||
// Check that the interpreter is in a clean state.
|
||||
CHECK(globals.IsEmpty());
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
|
||||
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -26,7 +25,7 @@ using Env = Dictionary<std::string, Address>;
|
||||
class Interpreter {
|
||||
public:
|
||||
// Interpret the whole program.
|
||||
auto InterpProgram(const std::list<Ptr<const Declaration>>& fs) -> int;
|
||||
auto InterpProgram(const std::vector<Ptr<const Declaration>>& fs) -> int;
|
||||
|
||||
// Interpret an expression at compile-time.
|
||||
auto InterpExp(Env values, Ptr<const Expression> e) -> Ptr<const Value>;
|
||||
@@ -124,7 +123,7 @@ class Interpreter {
|
||||
// State transition for statements.
|
||||
auto StepStmt() -> Transition;
|
||||
|
||||
void InitGlobals(const std::list<Ptr<const Declaration>>& fs);
|
||||
void InitGlobals(const std::vector<Ptr<const Declaration>>& fs);
|
||||
auto CurrentEnv() -> Env;
|
||||
auto GetFromEnv(SourceLocation loc, const std::string& name) -> Address;
|
||||
|
||||
|
||||
@@ -658,7 +658,7 @@ auto TypeChecker::TypeCheckStmt(Ptr<const Statement> s, TypeEnv types,
|
||||
const auto& match = cast<Match>(*s);
|
||||
auto res = TypeCheckExp(match.Exp(), types, values);
|
||||
auto res_type = res.type;
|
||||
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
|
||||
std::vector<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
|
||||
new_clauses;
|
||||
for (auto& clause : match.Clauses()) {
|
||||
new_clauses.push_back(TypeCheckCase(res_type, clause.first,
|
||||
@@ -816,7 +816,7 @@ static auto CheckOrEnsureReturn(std::optional<Ptr<const Statement>> opt_stmt,
|
||||
switch (stmt->Tag()) {
|
||||
case Statement::Kind::Match: {
|
||||
const auto& match = cast<Match>(*stmt);
|
||||
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
|
||||
std::vector<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
|
||||
new_clauses;
|
||||
for (const auto& clause : match.Clauses()) {
|
||||
auto s = CheckOrEnsureReturn(clause.second, omitted_ret_type,
|
||||
@@ -995,7 +995,7 @@ auto TypeChecker::MakeTypeChecked(const Ptr<const Declaration> d,
|
||||
case Declaration::Kind::ClassDeclaration: {
|
||||
const ClassDefinition& class_def =
|
||||
cast<ClassDeclaration>(*d).Definition();
|
||||
std::list<Ptr<Member>> fields;
|
||||
std::vector<Ptr<Member>> fields;
|
||||
for (Ptr<Member> m : class_def.members) {
|
||||
switch (m->Tag()) {
|
||||
case Member::Kind::FieldMember:
|
||||
@@ -1091,7 +1091,7 @@ void TypeChecker::TopLevel(const Declaration& d, TypeCheckContext* tops) {
|
||||
}
|
||||
}
|
||||
|
||||
auto TypeChecker::TopLevel(const std::list<Ptr<const Declaration>>& fs)
|
||||
auto TypeChecker::TopLevel(const std::vector<Ptr<const Declaration>>& fs)
|
||||
-> TypeCheckContext {
|
||||
TypeCheckContext tops;
|
||||
bool found_main = false;
|
||||
|
||||
@@ -30,7 +30,7 @@ class TypeChecker {
|
||||
auto MakeTypeChecked(const Ptr<const Declaration> d, const TypeEnv& types,
|
||||
const Env& values) -> Ptr<const Declaration>;
|
||||
|
||||
auto TopLevel(const std::list<Ptr<const Declaration>>& fs)
|
||||
auto TopLevel(const std::vector<Ptr<const Declaration>>& fs)
|
||||
-> TypeCheckContext;
|
||||
|
||||
private:
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_VALUE_H_
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_VALUE_H_
|
||||
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
@@ -86,7 +85,7 @@ class Value {
|
||||
const Kind tag;
|
||||
};
|
||||
|
||||
using VarValues = std::list<std::pair<std::string, Ptr<const Value>>>;
|
||||
using VarValues = std::vector<std::pair<std::string, Ptr<const Value>>>;
|
||||
|
||||
auto FindInVarValues(const std::string& field, const VarValues& inits)
|
||||
-> std::optional<Ptr<const Value>>;
|
||||
|
||||
Reference in New Issue
Block a user