49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
/* file Environment.hpp
|
|
*
|
|
* author: Roland Conybeare, Jun 2024
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "xo/refcnt/Refcounted.hpp"
|
|
#include "binding_path.hpp"
|
|
|
|
namespace xo {
|
|
namespace ast {
|
|
class Expression;
|
|
|
|
class Environment : public ref::Refcount {
|
|
public:
|
|
/** true if this is toplevel (global) environment.
|
|
* Toplevel environment doesn't have slot numbers.
|
|
*
|
|
* Variables that bind in the global environment have unique
|
|
* names, which we rely on instead of slot numbers.
|
|
**/
|
|
virtual bool is_global_env() const = 0;
|
|
|
|
/** lookup binding path for @p vname in this environment.
|
|
*
|
|
* Reports ingredients needed to address variable at runtime,
|
|
* in runtime analog of this environment
|
|
**/
|
|
virtual binding_path lookup_binding(const std::string & vname) const = 0;
|
|
|
|
/** lookup variable-expression @p vname in this environment.
|
|
* returns llvm::Value representing code that produces a value for vname
|
|
**/
|
|
virtual bp<Expression> lookup_var(const std::string & vname) const = 0;
|
|
|
|
virtual void print(std::ostream & os) const = 0;
|
|
};
|
|
|
|
inline std::ostream &
|
|
operator<< (std::ostream & os, const Environment & x) {
|
|
x.print(os);
|
|
return os;
|
|
}
|
|
} /*namespace ast*/
|
|
} /*namespace xo*/
|
|
|
|
|
|
/* end Environment.hpp */
|