12#ifndef INCLUDE_ARK_TYPECHECKER_HPP
13#define INCLUDE_ARK_TYPECHECKER_HPP
24 template <
typename T,
typename... Ts>
25 using AllSame = std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
28 [[nodiscard]]
bool checkN(
const std::vector<Value>& args)
30 return I >= args.size();
33 template <
int I,
typename T,
typename... Ts>
34 [[nodiscard]]
bool checkN(
const std::vector<Value>& args, T type, Ts... xs)
36 if (I >= args.size() || (type !=
ValueType::Any && args[I].valueType() != type))
52 [[nodiscard]]
bool check(
const std::vector<Value>& args, Ts... types)
54 if (
sizeof...(types) != args.size())
69 Typedef(
const std::string_view& type_name,
const ValueType type,
const bool is_variadic =
false) :
70 name(type_name), types { type }, variadic(is_variadic)
73 Typedef(
const std::string_view& type_name,
const std::vector<ValueType>& type_list,
const bool is_variadic =
false) :
74 name(type_name), types(type_list), variadic(is_variadic)
94 ARK_API void generateError [[noreturn]] (
const std::string_view& funcname,
const std::vector<Contract>& contracts,
const std::vector<Value>& args);
std::enable_if_t< std::conjunction_v< std::is_same< T, Ts >... > > AllSame
bool checkN(const std::vector< Value > &args)
ARK_API void generateError(const std::string_view &funcname, const std::vector< Contract > &contracts, const std::vector< Value > &args)
Generate an error message based on a given set of types contracts provided argument list.
bool check(const std::vector< Value > &args, Ts... types)
Helper to see if a builtin has been given a wanted set of types.
@ Any
Used only for typechecking.
A contract is a list of typed arguments that a function can follow.
std::vector< Typedef > arguments
A type definition within a contract.
Typedef(const std::string_view &type_name, const std::vector< ValueType > &type_list, const bool is_variadic=false)
Typedef(const std::string_view &type_name, const ValueType type, const bool is_variadic=false)
std::vector< ValueType > types