Get basic G-machine compilation working.
This commit is contained in:
30
src/compiler.cpp
Normal file
30
src/compiler.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user