mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
Fix globals in JIT
This commit is contained in:
parent
7655e09e83
commit
d5741a27e0
@ -144,19 +144,19 @@ StmtPtr SimplifyVisitor::transformAssignment(ExprPtr lhs, ExprPtr rhs, ExprPtr t
|
|||||||
// Generate new canonical variable name for this assignment and add it to the context
|
// Generate new canonical variable name for this assignment and add it to the context
|
||||||
auto canonical = ctx->generateCanonicalName(e->value);
|
auto canonical = ctx->generateCanonicalName(e->value);
|
||||||
auto assign = N<AssignStmt>(N<IdExpr>(canonical), rhs, type);
|
auto assign = N<AssignStmt>(N<IdExpr>(canonical), rhs, type);
|
||||||
|
val = nullptr;
|
||||||
if (rhs && rhs->isType()) {
|
if (rhs && rhs->isType()) {
|
||||||
ctx->addType(e->value, canonical, lhs->getSrcInfo());
|
val = ctx->addType(e->value, canonical, lhs->getSrcInfo());
|
||||||
} else {
|
} else {
|
||||||
auto val = ctx->addVar(e->value, canonical, lhs->getSrcInfo());
|
val = ctx->addVar(e->value, canonical, lhs->getSrcInfo());
|
||||||
if (auto st = getStaticGeneric(type.get()))
|
if (auto st = getStaticGeneric(type.get()))
|
||||||
val->staticType = st;
|
val->staticType = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register all toplevel variables as global in JIT mode
|
// Register all toplevel variables as global in JIT mode
|
||||||
bool isGlobal =
|
bool isGlobal = (ctx->cache->isJit && val->isGlobal() && !val->isGeneric() == 0) ||
|
||||||
(ctx->cache->isJit && ctx->isGlobal() && getStaticGeneric(type.get()) == 0) ||
|
(canonical == VAR_ARGV);
|
||||||
(canonical == VAR_ARGV);
|
if (isGlobal && !val->isGeneric())
|
||||||
if (isGlobal && !getStaticGeneric(type.get()))
|
|
||||||
ctx->cache->addGlobal(canonical);
|
ctx->cache->addGlobal(canonical);
|
||||||
|
|
||||||
return assign;
|
return assign;
|
||||||
|
@ -56,8 +56,9 @@ void SimplifyVisitor::visit(WhileStmt *stmt) {
|
|||||||
transformConditionalScope(stmt->suite);
|
transformConditionalScope(stmt->suite);
|
||||||
ctx->leaveConditionalBlock();
|
ctx->leaveConditionalBlock();
|
||||||
// Dominate loop variables
|
// Dominate loop variables
|
||||||
for (auto &var : ctx->getBase()->getLoop()->seenVars)
|
for (auto &var : ctx->getBase()->getLoop()->seenVars) {
|
||||||
ctx->findDominatingBinding(var);
|
ctx->findDominatingBinding(var);
|
||||||
|
}
|
||||||
ctx->getBase()->loops.pop_back();
|
ctx->getBase()->loops.pop_back();
|
||||||
|
|
||||||
// Complete while-else clause
|
// Complete while-else clause
|
||||||
|
Loading…
x
Reference in New Issue
Block a user