#pragma once #include #include #include #include #include #include namespace Fig { class Object; class Function { public: std::size_t id; Ast::FunctionParameters paras; TypeInfo retType; Ast::BlockStatement body; bool isBuiltin = false; std::function &)> builtin; int builtinParamCount = -1; std::shared_ptr closureContext; // ===== Constructors ===== Function() : id(nextId()) {} Function(Ast::FunctionParameters _paras, TypeInfo _retType, Ast::BlockStatement _body, ContextPtr _closureContext) : id(nextId()), // εˆ†ι…ε”―δΈ€ ID paras(std::move(_paras)), retType(std::move(_retType)), body(std::move(_body)), closureContext(std::move(_closureContext)) { } Function(std::function &)> fn, int argc) : id(nextId()), isBuiltin(true), builtin(std::move(fn)), builtinParamCount(argc) { } // ===== Copy / Move ===== Function(const Function &other) = default; Function(Function &&) noexcept = default; Function &operator=(const Function &) = default; Function &operator=(Function &&) noexcept = default; // ===== Comparison ===== bool operator==(const Function &other) const noexcept { return id == other.id; } bool operator!=(const Function &other) const noexcept { return !(*this == other); } private: static std::size_t nextId() { static std::atomic counter{1}; return counter++; } }; } // namespace Fig