[WIP] Plumbing to expand polymorphic functions

This commit is contained in:
2017-05-04 21:26:43 -04:00
parent 93c563e073
commit 46ed9bdb3c
10 changed files with 130 additions and 7 deletions

29
ast.cpp
View File

@@ -42,8 +42,11 @@
#include "func.h"
#include "stmt.h"
#include "sym.h"
#include "type.h"
#include "util.h"
#include <map>
///////////////////////////////////////////////////////////////////////////
// ASTNode
@@ -62,7 +65,9 @@ AST::AddFunction(Symbol *sym, Stmt *code) {
Function *f = new Function(sym, code);
if (f->IsPolyFunction()) {
FATAL("This is a good start, but implement me!");
std::vector<Function *> *expanded = f->ExpandPolyArguments();
for (size_t i=0; i<expanded->size(); i++)
functions.push_back((*expanded)[i]);
} else {
functions.push_back(f);
}
@@ -515,3 +520,25 @@ SafeToRunWithMaskAllOff(ASTNode *root) {
WalkAST(root, lCheckAllOffSafety, NULL, &safe);
return safe;
}
struct PolyData {
const PolyType *polyType;
const Type *replacement;
};
static ASTNode *
lTranslatePolyNode(ASTNode *node, void *d) {
struct PolyData *data = (struct PolyData*)d;
return node->ReplacePolyType(data->polyType, data->replacement);
}
ASTNode *
TranslatePoly(ASTNode *root, const PolyType *polyType, const Type *replacement) {
struct PolyData data;
data.polyType = polyType;
data.replacement = replacement;
return WalkAST(root, NULL, lTranslatePolyNode, &replacement);
}