Begin implementation of new environment

This commit is contained in:
2019-10-01 14:34:38 -07:00
parent ef86d60bda
commit 9ca56f51ae
7 changed files with 142 additions and 20 deletions

View File

@@ -1,16 +1,31 @@
#pragma once
#include <map>
#include "type.hpp"
#include <memory>
#include <string>
struct type_env {
std::map<std::string, type_ptr> names;
type_env const* parent = nullptr;
struct env {
virtual ~env() = default;
type_env(type_env const* p)
: parent(p) {}
type_env() : type_env(nullptr) {}
type_ptr lookup(const std::string& name) const;
void bind(const std::string& name, type_ptr t);
type_env scope() const;
virtual int get_offset(const std::string& name) const = 0;
};
using env_ptr = std::shared_ptr<env>;
struct env_var {
std::string name;
env_ptr parent;
env_var(std::string& n, env_ptr p)
: name(std::move(n)), parent(std::move(p)) {}
virtual int get_offset(const std::string& name) const;
};
struct env_offset {
int offset;
env_ptr parent;
env_offset(int o, env_ptr p)
: offset(o), parent(std::move(p)) {}
virtual int get_offset(const std::string& name) const;
};