mirror of https://github.com/exaloop/codon.git
pyextension.h support [wip]
parent
252f8c2c0d
commit
6343a6c8a4
|
@ -12,6 +12,7 @@
|
|||
#include "codon/parser/visitors/translate/translate.h"
|
||||
#include "codon/parser/visitors/typecheck/ctx.h"
|
||||
#include "codon/parser/visitors/typecheck/typecheck.h"
|
||||
#include "codon/cir/pyextension.h"
|
||||
|
||||
namespace codon::ast {
|
||||
|
||||
|
@ -229,4 +230,14 @@ std::vector<ExprPtr> Cache::mergeC3(std::vector<std::vector<ExprPtr>> &seqs) {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<ir::PyModule> Cache::getPythonModule() {
|
||||
LOG("====== module generation =======");
|
||||
|
||||
for (auto &[cn, c]: classes)
|
||||
LOG("-> {} {}", cn, c.module);
|
||||
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace codon::ast
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "codon/parser/ast.h"
|
||||
#include "codon/parser/common.h"
|
||||
#include "codon/parser/ctx.h"
|
||||
#include "codon/cir/pyextension.h"
|
||||
|
||||
#define FILE_GENERATED "<generated>"
|
||||
#define MODULE_MAIN "__main__"
|
||||
|
@ -156,6 +157,9 @@ struct Cache : public std::enable_shared_from_this<Cache> {
|
|||
/// List of statically inherited classes.
|
||||
std::vector<std::string> staticParentClasses;
|
||||
|
||||
/// Module information
|
||||
std::string module;
|
||||
|
||||
Class() : ast(nullptr), originalAst(nullptr) {}
|
||||
};
|
||||
/// Class lookup table that maps a canonical class identifier to the corresponding
|
||||
|
@ -186,6 +190,9 @@ struct Cache : public std::enable_shared_from_this<Cache> {
|
|||
/// Unrealized function type.
|
||||
types::FuncTypePtr type;
|
||||
|
||||
/// Module information
|
||||
std::string module;
|
||||
|
||||
Function() : ast(nullptr), origAst(nullptr), type(nullptr) {}
|
||||
};
|
||||
/// Function lookup table that maps a canonical function identifier to the
|
||||
|
@ -300,6 +307,8 @@ public:
|
|||
void parseCode(const std::string &code);
|
||||
|
||||
static std::vector<ExprPtr> mergeC3(std::vector<std::vector<ExprPtr>> &);
|
||||
|
||||
std::shared_ptr<ir::PyModule> getPythonModule();
|
||||
};
|
||||
|
||||
} // namespace codon::ast
|
||||
|
|
|
@ -177,6 +177,7 @@ void SimplifyVisitor::visit(ClassStmt *stmt) {
|
|||
for (auto &b : staticBaseASTs)
|
||||
ctx->cache->classes[canonicalName].staticParentClasses.emplace_back(b->name);
|
||||
ctx->cache->classes[canonicalName].ast->validate();
|
||||
ctx->cache->classes[canonicalName].module = ctx->getModule();
|
||||
|
||||
// Codegen default magic methods
|
||||
for (auto &m : stmt->attributes.magics) {
|
||||
|
|
|
@ -278,6 +278,7 @@ void SimplifyVisitor::visit(FunctionStmt *stmt) {
|
|||
ctx->cache->functions[canonicalName].ast = f;
|
||||
ctx->cache->functions[canonicalName].origAst =
|
||||
std::static_pointer_cast<FunctionStmt>(stmt->clone());
|
||||
ctx->cache->functions[canonicalName].module = ctx->getModule();
|
||||
|
||||
// Expression to be used if function binding is modified by captures or decorators
|
||||
ExprPtr finalExpr = nullptr;
|
||||
|
|
|
@ -29,6 +29,7 @@ StmtPtr TypecheckVisitor::apply(Cache *cache, const StmtPtr &stmts) {
|
|||
}
|
||||
if (s->getSuite()) {
|
||||
v.prepareVTables();
|
||||
auto _ = cache->getPythonModule();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue