From 6b63921275a7834f6231f92185a2cc23d77c13ba Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 4 Oct 2024 00:28:03 +0100 Subject: command-line-tool: Merge local and remote coerce-expression. coerce-expression and coerce-expression-local share most of their code. So, it makes sense to merge them. * ravanan/command-line-tool.scm (coerce-expression): Add optional context argument. (coerce-expression-local): Delete function. (run-command-line-tool): Call coerce-expression instead of coerce-expression-local. --- ravanan/command-line-tool.scm | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm index 9e70a86..83ccfa2 100644 --- a/ravanan/command-line-tool.scm +++ b/ravanan/command-line-tool.scm @@ -196,39 +196,35 @@ strings." (tokenize str)) " + ")) -(define (coerce-expression expression) +(define* (coerce-expression expression #:optional context) "Coerce @var{expression} into a scheme JSON tree. When @var{expression} is a scheme JSON tree, return it as is. When @var{expression} is a javascript expression, return a G-expression that evaluates it. This G-expression references variables @code{inputs} and -@code{runtime}." - (if (and (string? expression) - (javascript-expression? expression)) - #~(evaluate-parameter-reference #$%worker-node - #$(interpolate-parameter-references expression) - inputs - 'null - runtime - (list)) - expression)) - -(define (coerce-expression-local expression inputs) - "Coerce @var{expression}, which may reference @var{inputs}, into a scheme JSON -tree. +@code{runtime}. -When @var{expression} is a scheme JSON tree, return it as is. When -@var{expression} is a javascript expression, evaluate it and return the result. -This function is similar to @code{coerce-expression-local}, but executes locally -instead of staging onto a G-expression." +If @var{context} is not @code{#f}, evaluate the parameter reference in that +context and return the value. @var{context} must be an association list with +keys @code{input}, @code{self} and @code{runtime}." (if (and (string? expression) (javascript-expression? expression)) - (evaluate-parameter-reference %node - (interpolate-parameter-references expression) - inputs - 'null - (list) - (list)) + (if context + ;; Evaluate immediately. + (evaluate-parameter-reference %node + (interpolate-parameter-references expression) + inputs + 'null + (list) + (list)) + ;; Compile to a G-expression that evaluates expression. + #~(evaluate-parameter-reference #$%worker-node + #$(interpolate-parameter-references expression) + inputs + 'null + runtime + (list))) + ;; Not a javascript expression, but some other JSON tree. Return it as is. expression)) (define (build-command cwl inputs) @@ -445,7 +441,9 @@ path." inexact->exact ceiling (cut coerce-type <> 'number) - (cut coerce-expression-local <> inputs))) + (cut coerce-expression + <> + `(("inputs" . ,inputs))))) 1)) (store-files-directory (script->store-files-directory script store)) (store-data-file (script->store-data-file script store)) -- cgit v1.2.3