diff --git a/Project.toml b/Project.toml index fb9a75b..b79a996 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,18 @@ name = "HerbEvaluation" uuid = "eb1bf938-813d-4942-ac0f-b4657a683e76" -authors = ["Jaap de Jong "] +authors = ["Jaap de Jong ", "Tilman Hinnerichs "] version = "0.1.0" [deps] HerbData = "495a3ad3-8034-41b3-a087-aacf2fd71098" HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" +HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" [compat] julia = "1.8" HerbData = "0.1.0" HerbGrammar = "0.1.0" +HerbCore = "0.1.0" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.md b/README.md index 344ad36..9fdb217 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ -# Evaluation.jl +# HerbEvaluation.jl + +This package provides functionality for evaluating (candidate) programs in the Herb Program Synthesis framework. `HerbEvaluation` can handle arbitrary Julia expressions, but also arbitrary other interpretors for which an evaluation function is given. + +For general usage please see the `HerbExamples` and our test suite. -This package provides functionality for evaluating (candidate) programs in the Herb Program Synthesis framework. diff --git a/src/HerbEvaluation.jl b/src/HerbEvaluation.jl index 9e7e0f7..78c1131 100644 --- a/src/HerbEvaluation.jl +++ b/src/HerbEvaluation.jl @@ -1,5 +1,6 @@ module HerbEvaluation +using HerbCore using HerbData using HerbGrammar diff --git a/src/interpreter.jl b/src/interpreter.jl index 8bac8e6..00ce120 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -4,6 +4,8 @@ Runs the interpreter on all examples with the given input table and expression. The symbol table defines everything (functions, symbols) that are not input variables to the program to be synthesised. Returns a list of true/false values indicating if the expression satisfies the corresponding example. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function test_all_examples(tab::SymbolTable, expr::Any, examples::Vector{Example})::Vector{Bool} outcomes = Vector{Bool}(undef, length(examples)) @@ -19,10 +21,16 @@ end Evaluates all examples and returns true iff all examples pass. Shortcircuits as soon as an example is found for which the program doesn't work. +Returns false if one of the examples produces an error. """ function test_examples(tab::SymbolTable, expr::Any, examples::Vector{Example})::Bool for example ∈ filter(e -> e isa IOExample, examples) - if example.out ≠ test_with_input(tab, expr, example.in) + try + output = test_with_input(tab, expr, example.in) + if output ≠ test_with_input(tab, expr, example.in) + return false + end + catch return false end end @@ -34,6 +42,8 @@ end test_with_input(tab::SymbolTable, expr::Any, input::Dict) Interprets an expression or symbol with the given symboltable and the input. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function test_with_input(tab::SymbolTable, expr::Any, input::Dict) # Add input variable values @@ -46,6 +56,8 @@ end execute_on_examples(tab::SymbolTable, expr::Any, example_inputs::Vector{Dict{Symbol, Any}})::Vector{Any} Executes a given expression on a set of inputs and returns the respective outputs. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function execute_on_examples(tab::SymbolTable, expr::Any, example_inputs::Vector{Dict{Symbol, Any}})::Vector{Any} return [test_with_input(tab, expr, example) for example in example_inputs] @@ -53,16 +65,21 @@ end """ + interpret(tab::SymbolTable, ex::Expr) + Evaluates an expression without compiling it. Uses AST and symbol lookups. Only supports :call and :(=) expressions at the moment. -### Example usage +Example usage: ``` tab = SymbolTable(:f => f, :x => x) ex = :(f(x)) interpret(tab, ex) ``` + +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ interpret(tab::SymbolTable, x::Any) = x interpret(tab::SymbolTable, s::Symbol) = tab[s]