#ifndef QLOW_SEM_BUILTIN_H #define QLOW_SEM_BUILTIN_H #include "Semantic.h" #include "Scope.h" #include #include namespace qlow { namespace sem { NativeScope generateNativeScope(void); struct NativeMethod; struct UnaryNativeMethod; struct BinaryNativeMethod; } } struct qlow::sem::NativeMethod : public sem::Method { inline NativeMethod(std::shared_ptr returnType) : Method{ NativeScope::getInstance(), std::move(returnType) } { } virtual llvm::Value* generateCode(llvm::IRBuilder<>& builder, std::vector arguments) = 0; }; struct qlow::sem::UnaryNativeMethod : public sem::NativeMethod { std::function&, llvm::Value*)> generator; inline UnaryNativeMethod(std::shared_ptr returnType, const std::function &, llvm::Value*)>& generator) : NativeMethod{ std::move(returnType) }, generator{ generator } { } virtual llvm::Value* generateCode(llvm::IRBuilder<>& builder, std::vector arguments); }; struct qlow::sem::BinaryNativeMethod : public sem::NativeMethod { using Func = std::function&, llvm::Value*, llvm::Value*)>; Func generator; Variable argument; inline BinaryNativeMethod(std::shared_ptr returnType, std::shared_ptr argumentType, Func&& generator) : NativeMethod{ std::move(returnType) }, generator{ generator }, argument{ std::move(argumentType), "arg" } { Method::arguments = { &argument }; } virtual llvm::Value* generateCode(llvm::IRBuilder<>& builder, std::vector arguments); }; #endif // QLOW_SEM_BUILTIN_H