Get basic G-machine compilation working.

This commit is contained in:
2019-06-11 17:24:28 -07:00
parent d729611486
commit da515437e6
11 changed files with 430 additions and 19 deletions

30
src/compiler.cpp Normal file
View 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;
}
}