support function literal, set builtins to global context. great!

This commit is contained in:
2025-12-20 20:27:36 +08:00
parent b9a98150ae
commit e7ca714a89
19 changed files with 362 additions and 502 deletions

View File

@@ -0,0 +1,47 @@
#pragma once
#include <Ast/astBase.hpp>
#include <Ast/functionParameters.hpp>
#include <fig_string.hpp>
#include <variant>
namespace Fig::Ast
{
class FunctionLiteralExprAst final : public ExpressionAst
{
public:
FunctionParameters paras;
std::variant<BlockStatement, Expression> body;
FunctionLiteralExprAst(FunctionParameters _paras, BlockStatement _body) :
paras(std::move(_paras)), body(std::move(_body))
{
type = AstType::FunctionLiteralExpr;
}
FunctionLiteralExprAst(FunctionParameters _paras, Expression _exprBody) :
paras(std::move(_paras)), body(std::move(_exprBody))
{
type = AstType::FunctionLiteralExpr;
}
bool isExprMode() const
{
return std::holds_alternative<Expression>(body);
}
BlockStatement &getBlockBody()
{
return std::get<BlockStatement>(body);
}
Expression &getExprBody()
{
return std::get<Expression>(body);
}
~FunctionLiteralExprAst() = default;
};
using FunctionLiteralExpr = std::shared_ptr<FunctionLiteralExprAst>;
} // namespace Fig::Ast