xo-jit: use Environment for toplevel lambdas

This commit is contained in:
Roland Conybeare 2024-06-30 20:03:55 -04:00
commit 1f0c0cb71d
4 changed files with 16 additions and 286 deletions

View file

@ -20,6 +20,7 @@
#include "xo/expression/Lambda.hpp"
#include "xo/expression/Variable.hpp"
#include "xo/expression/IfExpr.hpp"
#include "xo/expression/GlobalEnv.hpp"
/* stuff from kaleidoscope.cpp */
#include "llvm/ADT/APFloat.h"
@ -57,6 +58,7 @@ namespace xo {
public:
using Expression = xo::ast::Expression;
using Lambda = xo::ast::Lambda;
using GlobalEnv = xo::ast::GlobalEnv;
using TypeDescr = xo::reflect::TypeDescr;
using ExecutionSession = llvm::orc::ExecutionSession;
using DataLayout = llvm::DataLayout;
@ -211,7 +213,7 @@ namespace xo {
std::unique_ptr<llvm::Module> llvm_module_;
/** map global names to functions/variables **/
std::map<std::string, xo::ref::rp<Expression>> global_env_;
ref::rp<GlobalEnv> global_env_;
/** map variable names (formal parameters) to
* corresponding llvm IR.

View file

@ -22,41 +22,16 @@ namespace xo {
**/
class activation_record {
public:
activation_record(llvm::Function * llvm_fn,
llvm::AllocaInst * frame) : frame_{frame} {
int i_arg = 0;
for (auto & arg : llvm_fn->args()) {
std::string arg_name = std::string(arg.getName());
activation_record() = default;
name2ix_map_[arg_name] = 2 + i_arg;
}
}
std::int32_t lookup_var(const std::string & var_name) const;
#ifdef OBSOLETE
llvm::AllocaInst * lookup_var(const std::string & var_name) const;
llvm::AllocaInst * alloc_var(const std::string & var_name,
llvm::AllocaInst * alloca);
#endif
private:
/** stack frame for a user-defined function (lambda) **/
llvm::AllocaInst * frame_ = nullptr;
/** for each formal parameter,
* reports its position in stack frame.
* This is the position to use with getelementptr,
* i.e. +2 to skip first two slots, that are reserved
* for nextframe pointer (slot 0) + unwind pointer (slot 1)
**/
std::map<std::string, std::int32_t> name2ix_map_;
#ifdef OBSOLETE
/** maps named slots in a stack frame to logical addresses **/
std::map<std::string, llvm::AllocaInst*> frame_; /* <-> kaleidoscope NamedValues */
#endif
}; /*activation_record*/
} /*namespace jit*/