aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2024-10-04 00:28:03 +0100
committerArun Isaac2024-10-04 14:48:08 +0100
commit6b63921275a7834f6231f92185a2cc23d77c13ba (patch)
tree03bf8bcb41d3a95ca08509f9a9a49bf7160ab046
parented7cbc2bb9f06c4734acbc4bb1c7ff06499d5707 (diff)
downloadravanan-6b63921275a7834f6231f92185a2cc23d77c13ba.tar.gz
ravanan-6b63921275a7834f6231f92185a2cc23d77c13ba.tar.lz
ravanan-6b63921275a7834f6231f92185a2cc23d77c13ba.zip
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.
-rw-r--r--ravanan/command-line-tool.scm50
1 files 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))