mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:51:03 +01:00
improve abstraction for AssocList, fix bug in optional else (#315)
* improve abstraction for AssocList, fix bug in optional else * add flag for tracing output, clean up code for output * turned off tracing by default, updated goldens, removed two examples that use pointers, shouldn't have been there yet
This commit is contained in:
@@ -15,14 +15,16 @@
|
||||
namespace Carbon {
|
||||
|
||||
struct Value;
|
||||
|
||||
template <class K, class V>
|
||||
struct AssocList;
|
||||
class AssocList;
|
||||
|
||||
using Address = unsigned int;
|
||||
using TypeEnv = AssocList<std::string, Value*>;
|
||||
using Env = AssocList<std::string, Address>;
|
||||
|
||||
/// TODO:explain this. Also name it if necessary. Consult with jsiek.
|
||||
using ExecutionEnvironment = std::pair<TypeEnv*, Env*>;
|
||||
using ExecutionEnvironment = std::pair<TypeEnv, Env>;
|
||||
|
||||
/// An existential AST declaration satisfying the Declaration concept.
|
||||
class Declaration {
|
||||
@@ -38,10 +40,10 @@ class Declaration {
|
||||
public: // Declaration concept API, in addition to ValueSemantic.
|
||||
void Print() const { box->Print(); }
|
||||
auto Name() const -> std::string { return box->Name(); }
|
||||
auto TypeChecked(TypeEnv* env, Env* ct_env) const -> Declaration {
|
||||
auto TypeChecked(TypeEnv env, Env ct_env) const -> Declaration {
|
||||
return box->TypeChecked(env, ct_env);
|
||||
}
|
||||
void InitGlobals(Env*& globals) const { return box->InitGlobals(globals); }
|
||||
void InitGlobals(Env& globals) const { return box->InitGlobals(globals); }
|
||||
auto TopLevel(ExecutionEnvironment& e) const -> void {
|
||||
return box->TopLevel(e);
|
||||
}
|
||||
@@ -60,9 +62,9 @@ class Declaration {
|
||||
virtual ~Box() {}
|
||||
virtual auto Print() const -> void = 0;
|
||||
virtual auto Name() const -> std::string = 0;
|
||||
virtual auto TypeChecked(TypeEnv* env, Env* ct_env) const
|
||||
virtual auto TypeChecked(TypeEnv env, Env ct_env) const
|
||||
-> Declaration = 0;
|
||||
virtual auto InitGlobals(Env*& globals) const -> void = 0;
|
||||
virtual auto InitGlobals(Env& globals) const -> void = 0;
|
||||
virtual auto TopLevel(ExecutionEnvironment&) const -> void = 0;
|
||||
};
|
||||
|
||||
@@ -75,10 +77,10 @@ class Declaration {
|
||||
|
||||
auto Print() const -> void override { return content.Print(); }
|
||||
auto Name() const -> std::string override { return content.Name(); }
|
||||
auto TypeChecked(TypeEnv* env, Env* ct_env) const -> Declaration override {
|
||||
auto TypeChecked(TypeEnv env, Env ct_env) const -> Declaration override {
|
||||
return content.TypeChecked(env, ct_env);
|
||||
}
|
||||
auto InitGlobals(Env*& globals) const -> void override {
|
||||
auto InitGlobals(Env& globals) const -> void override {
|
||||
content.InitGlobals(globals);
|
||||
}
|
||||
auto TopLevel(ExecutionEnvironment& e) const -> void override {
|
||||
@@ -98,8 +100,8 @@ struct FunctionDeclaration {
|
||||
|
||||
auto Print() const -> void;
|
||||
auto Name() const -> std::string;
|
||||
auto TypeChecked(TypeEnv* env, Env* ct_env) const -> Declaration;
|
||||
auto InitGlobals(Env*& globals) const -> void;
|
||||
auto TypeChecked(TypeEnv env, Env ct_env) const -> Declaration;
|
||||
auto InitGlobals(Env& globals) const -> void;
|
||||
auto TopLevel(ExecutionEnvironment&) const -> void;
|
||||
};
|
||||
|
||||
@@ -110,8 +112,8 @@ struct StructDeclaration {
|
||||
|
||||
void Print() const;
|
||||
auto Name() const -> std::string;
|
||||
auto TypeChecked(TypeEnv* env, Env* ct_env) const -> Declaration;
|
||||
void InitGlobals(Env*& globals) const;
|
||||
auto TypeChecked(TypeEnv env, Env ct_env) const -> Declaration;
|
||||
void InitGlobals(Env& globals) const;
|
||||
auto TopLevel(ExecutionEnvironment&) const -> void;
|
||||
};
|
||||
|
||||
@@ -126,8 +128,8 @@ struct ChoiceDeclaration {
|
||||
|
||||
void Print() const;
|
||||
auto Name() const -> std::string;
|
||||
auto TypeChecked(TypeEnv* env, Env* ct_env) const -> Declaration;
|
||||
void InitGlobals(Env*& globals) const;
|
||||
auto TypeChecked(TypeEnv env, Env ct_env) const -> Declaration;
|
||||
void InitGlobals(Env& globals) const;
|
||||
auto TopLevel(ExecutionEnvironment&) const -> void;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user