31 lines
890 B
C++
31 lines
890 B
C++
#include "compiler.hpp"
|
|
#include "error.hpp"
|
|
|
|
namespace lily {
|
|
void compile_env::set_parent(std::shared_ptr<compile_env> p) {
|
|
parent = p;
|
|
}
|
|
|
|
int compile_env_var::get_offset(const std::string& name) {
|
|
if(this->var == name) return 0;
|
|
if(parent) return parent->get_offset(name) + 1;
|
|
throw error("unknown variable name");
|
|
}
|
|
|
|
bool compile_env_var::is_variable(const std::string& name) {
|
|
if(this->var == name) return true;
|
|
if(parent) return parent->is_variable(name);
|
|
return false;
|
|
}
|
|
|
|
int compile_env_offset::get_offset(const std::string& name) {
|
|
if(parent) return parent->get_offset(name) + offset;
|
|
throw error("unknown variable name");
|
|
}
|
|
|
|
bool compile_env_offset::is_variable(const std::string& name) {
|
|
if(parent) return parent->is_variable(name);
|
|
return false;
|
|
}
|
|
}
|