From 70314b3303f712a0277b80b23bc3613744e6178e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 1 Jun 2020 19:51:17 +0300 Subject: Add builtin weight Also invent the notion of external builtin (builtin_info::function is NULL). --- libbutl/builtin.mxx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'libbutl/builtin.mxx') diff --git a/libbutl/builtin.mxx b/libbutl/builtin.mxx index 2be2f90..e4dd4f8 100644 --- a/libbutl/builtin.mxx +++ b/libbutl/builtin.mxx @@ -153,19 +153,38 @@ LIBBUTL_MODEXPORT namespace butl const dir_path& cwd, const builtin_callbacks&); - class builtin_map: public std::map + // Builtin function and weight. + // + // The weight between 0 and 2 reflects the builtin's contribution to the + // containing script semantics with 0 being the lowest/ignore. Current + // mapping is as follows: + // + // 0 - non-contributing (true, false) + // 1 - non-creative (rm, rmdir, sleep, test) + // 2 - creative (any builtin that may produce output) + // + // If the function is NULL, then the builtin has an external implementation + // and should be executed by running the program with this name. + // + struct builtin_info + { + builtin_function* function; + uint8_t weight; + }; + + class builtin_map: public std::map { public: - using base = std::map; + using base = std::map; using base::base; // Return NULL if not a builtin. // - builtin_function* + const builtin_info* find (const std::string& n) const { auto i (base::find (n)); - return i != end () ? i->second : nullptr; + return i != end () ? &i->second : nullptr; } }; -- cgit v1.1