support closure!!!!!

This commit is contained in:
2025-12-20 20:38:59 +08:00
parent e7ca714a89
commit 56459a5eeb
3 changed files with 31 additions and 17 deletions

View File

@@ -132,7 +132,8 @@ namespace Fig
evaluatedArgs.argv.push_back(defaultVal);
}
// create new context for function call
auto newContext = std::make_shared<Context>(FString(std::format("<Function {}()>", fnName.toBasicString())), currentContext);
auto newContext = std::make_shared<Context>(FString(std::format("<Function {}()>", fnName.toBasicString())),
fnStruct.closureContext);
auto previousContext = currentContext;
currentContext = newContext;
// define parameters in new context
@@ -238,8 +239,8 @@ namespace Fig
return Function(
fn->paras,
ValueType::Any,
body
);
body,
currentContext);
}
else
{
@@ -247,8 +248,8 @@ namespace Fig
return Function(
fn->paras,
ValueType::Any,
body
);
body,
currentContext);
}
}
case AstType::ListExpr: {
@@ -341,7 +342,8 @@ namespace Fig
Value(Function(
fnDef->paras,
TypeInfo(fnDef->retType),
fnDef->body)));
fnDef->body,
currentContext)));
return StatementResult::normal();
};
case AstType::StructSt: {