Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to add interpreters with Metatheory.jl #13

Open
sebdumancic opened this issue Feb 15, 2024 · 2 comments
Open

Make it possible to add interpreters with Metatheory.jl #13

sebdumancic opened this issue Feb 15, 2024 · 2 comments

Comments

@sebdumancic
Copy link
Member

https://juliasymbolics.github.io/Metatheory.jl/dev/tutorials/while_interpreter/

MetaTheory.jl would make it possible to add any interpreter painlessly!

@ReubenJ
Copy link
Member

ReubenJ commented Feb 20, 2024

Super cool!

Just a note of caution here, the execution time seems orders of magnitude slower than our current default interpret function. I'm not certain these comparisons are fair—I did my best to match them to the example at the beginning of the tutorial. It might be that I'm not understanding the correct use of the package.

Comparing times:

julia> [round(median(res.times)) for res in [res_raw, res_meta, res_int]]
3-element Vector{Float64}:
   24.0
 3776.0
   89.0

Code to reproduce

"Raw" version:

some_mem = Dict(:x => 2)
f = (m, v) -> m[v]
res_raw = @benchmark f(some_mem, :x)

MetaTheory.jl version:

Mem = Dict{Symbol,Union{Bool,Int}}
read_mem = @theory v σ begin
  (v::Symbol, σ::Mem) => σ[v]
end

σ₁ = Mem(:x => 2)
program = :(x, $σ₁)
res_meta =  @benchmark rewrite(program, read_mem)

HerbInterpret.jl version:

some_mem = Dict(:x => 2)
tab = Dict(
    :get => get,
    :missing => missing,
    :some_mem => some_mem,
    :f => f,
    :x => x,
)
res_int = @benchmark interpret(tab, :(f(some_mem, x)))
Package versions used
Status `Project.toml`
  [6e4b80f9] BenchmarkTools v1.4.0
  [5bbddadd] HerbInterpret v0.1.1
  [e9d8d322] Metatheory v2.0.2

@sebdumancic
Copy link
Member Author

sebdumancic commented Feb 20, 2024

that is a good catch!
Indeed, I don't think the package intends to be very performant, only to make it easy to write a custom interpreter.

but, we should keep it in mind and see whether we want to make use of it or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants