use gc_arena::Collect; use num_enum::TryFromPrimitive; macro_rules! define_builtins { ($(($name:literal, $variant:ident, $arity:expr)),* $(,)?) => { /// Builtin function registry. /// Array index IS the PrimOp id. (name, arity) pairs. pub const BUILTINS: &[(&str, u8)] = &[ $(($name, $arity),)* ]; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Collect)] #[repr(u8)] #[collect(require_static)] pub enum BuiltinId { $($variant,)* } }; } define_builtins! { ("abort", Abort, 1), ("__add", Add, 2), ("__addErrorContext", AddErrorContext, 2), ("__all", All, 2), ("__any", Any, 2), ("__appendContext", AppendContext, 2), ("__attrNames", AttrNames, 1), ("__attrValues", AttrValues, 1), ("baseNameOf", BaseNameOf, 1), ("__bitAnd", BitAnd, 2), ("__bitOr", BitOr, 2), ("__bitXor", BitXor, 2), ("break", Break, 1), ("__catAttrs", CatAttrs, 2), ("__ceil", Ceil, 1), ("__compareVersions", CompareVersions, 2), ("__concatLists", ConcatLists, 1), ("__concatMap", ConcatMap, 2), ("__concatStringsSep", ConcatStringsSep, 2), ("__convertHash", ConvertHash, 1), ("__deepSeq", DeepSeq, 2), ("derivation", Derivation, 1), ("derivationStrict", DerivationStrict, 1), ("dirOf", DirOf, 1), ("__div", Div, 2), ("__elem", Elem, 2), ("__elemAt", ElemAt, 2), ("fetchGit", FetchGit, 1), ("fetchMercurial", FetchMercurial, 1), ("fetchTarball", FetchTarball, 1), ("fetchTree", FetchTree, 1), ("__fetchurl", FetchUrl, 1), ("__filter", Filter, 2), ("__filterSource", FilterSource, 2), ("__findFile", FindFile, 2), ("__floor", Floor, 1), ("__foldl'", FoldlStrict, 3), ("__fromJSON", FromJSON, 1), ("fromTOML", FromTOML, 1), ("__functionArgs", FunctionArgs, 1), ("__genList", GenList, 2), ("__genericClosure", GenericClosure, 1), ("__getAttr", GetAttr, 2), ("__getContext", GetContext, 1), ("__getEnv", GetEnv, 1), ("__groupBy", GroupBy, 2), ("__hasAttr", HasAttr, 2), ("__hasContext", HasContext, 1), ("__hashFile", HashFile, 2), ("__hashString", HashString, 2), ("__head", Head, 1), ("import", Import, 1), ("__intersectAttrs", IntersectAttrs, 2), ("__isAttrs", IsAttrs, 1), ("__isBool", IsBool, 1), ("__isFloat", IsFloat, 1), ("__isFunction", IsFunction, 1), ("__isInt", IsInt, 1), ("__isList", IsList, 1), ("isNull", IsNull, 1), ("__isPath", IsPath, 1), ("__isString", IsString, 1), ("__length", Length, 1), ("__lessThan", LessThan, 2), ("__listToAttrs", ListToAttrs, 1), ("map", Map, 2), ("__mapAttrs", MapAttrs, 2), ("__match", Match, 2), ("__mul", Mul, 2), ("null", Null, 0), // constant, not a function ("__parseDrvName", ParseDrvName, 1), ("__partition", Partition, 2), ("__path", Path, 1), ("__pathExists", PathExists, 1), ("placeholder", Placeholder, 1), ("__readDir", ReadDir, 1), ("__readFile", ReadFile, 1), ("__readFileType", ReadFileType, 1), ("removeAttrs", RemoveAttrs, 2), ("__replaceStrings", ReplaceStrings, 3), ("scopedImport", ScopedImport, 2), ("__seq", Seq, 2), ("__sort", Sort, 2), ("__split", Split, 2), ("__splitVersion", SplitVersion, 1), ("__storePath", StorePath, 1), ("__stringLength", StringLength, 1), ("__sub", Sub, 2), ("__substring", Substring, 3), ("__tail", Tail, 1), ("throw", Throw, 1), ("__toFile", ToFile, 2), ("__toJSON", ToJSON, 1), ("__toPath", ToPath, 1), ("toString", ToString, 1), ("__toXML", ToXML, 1), ("__trace", Trace, 2), ("__tryEval", TryEval, 1), ("__typeOf", TypeOf, 1), ("__unsafeDiscardStringContext", UnsafeDiscardStringContext, 1), ("__unsafeGetAttrPos", UnsafeGetAttrPos, 2), ("__warn", Warn, 2), ("__zipAttrsWith", ZipAttrsWith, 2), }