diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-01-23 12:14:40 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-01-23 12:14:40 +0000 |
commit | 145659f1d677face587b710726285df872a319c0 (patch) | |
tree | 074eafbf9d3b9ee030ff2ec584667b0386f37618 /eval/src/apps | |
parent | 31690a1baa64d046d7ba25510b4570aa20792134 (diff) |
move code
Diffstat (limited to 'eval/src/apps')
-rw-r--r-- | eval/src/apps/eval_expr/.gitignore | 4 | ||||
-rw-r--r-- | eval/src/apps/eval_expr/CMakeLists.txt | 9 | ||||
-rw-r--r-- | eval/src/apps/eval_expr/eval_expr.cpp | 27 |
3 files changed, 40 insertions, 0 deletions
diff --git a/eval/src/apps/eval_expr/.gitignore b/eval/src/apps/eval_expr/.gitignore new file mode 100644 index 00000000000..04661a7889c --- /dev/null +++ b/eval/src/apps/eval_expr/.gitignore @@ -0,0 +1,4 @@ +/.depend +/Makefile +/eval_expr +vespalib_eval_expr_app diff --git a/eval/src/apps/eval_expr/CMakeLists.txt b/eval/src/apps/eval_expr/CMakeLists.txt new file mode 100644 index 00000000000..f576295717a --- /dev/null +++ b/eval/src/apps/eval_expr/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_eval_expr_app + SOURCES + eval_expr.cpp + INSTALL bin + DEPENDS + vespalib +# vespalib_vespalib_eval +) diff --git a/eval/src/apps/eval_expr/eval_expr.cpp b/eval/src/apps/eval_expr/eval_expr.cpp new file mode 100644 index 00000000000..dc5274cde47 --- /dev/null +++ b/eval/src/apps/eval_expr/eval_expr.cpp @@ -0,0 +1,27 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/fastos/fastos.h> +#include <vespa/vespalib/eval/function.h> +#include <vespa/vespalib/eval/interpreted_function.h> + +using namespace vespalib::eval; + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "usage: %s <expr>\n", argv[0]); + fprintf(stderr, " the expression must be self-contained (no arguments)\n"); + fprintf(stderr, " quote the expression to make it a single parameter\n"); + fprintf(stderr, " use let to simulate parameters: let(x, 1, x + 3)\n"); + return 1; + } + Function function = Function::parse({}, argv[1]); + if (function.has_error()) { + fprintf(stderr, "expression error: %s\n", function.get_error().c_str()); + return 1; + } + InterpretedFunction::Context ctx; + InterpretedFunction interpreted(SimpleTensorEngine::ref(), function, NodeTypes()); + double result = interpreted.eval(ctx).as_double(); + fprintf(stdout, "%.32g\n", result); + return 0; +} |