Begin implementation of new environment
This commit is contained in:
39
06/env.hpp
39
06/env.hpp
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user