From dc2c9e7f96d18d069f88440280c8aed9f832b5f1 Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Wed, 3 Mar 2021 12:57:14 +0530 Subject: [PATCH 1/2] support 0-arg functions --- src/RuntimeGeneratedFunctions.jl | 2 +- test/runtests.jl | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/RuntimeGeneratedFunctions.jl b/src/RuntimeGeneratedFunctions.jl index 606fe10..122c2f5 100644 --- a/src/RuntimeGeneratedFunctions.jl +++ b/src/RuntimeGeneratedFunctions.jl @@ -46,7 +46,7 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id} <: Functio body::Expr function RuntimeGeneratedFunction(cache_tag, context_tag, ex) def = splitdef(ex) - args, body = normalize_args(def[:args]), def[:body] + args, body = normalize_args(get(def, :args, [])), def[:body] id = expr_to_id(body) cached_body = _cache_body(cache_tag, id, body) new{Tuple(args), cache_tag, context_tag, id}(cached_body) diff --git a/test/runtests.jl b/test/runtests.jl index bcbb486..0ce952a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,10 +27,14 @@ ex3 = :(function (_du::T,_u::Vector{E},_p::P,_t::Any) where {T<:Vector,E,P} nothing end) + +f0 = @RuntimeGeneratedFunction(()->42) f1 = @RuntimeGeneratedFunction(ex1) f2 = @RuntimeGeneratedFunction(ex2) f3 = @RuntimeGeneratedFunction(ex3) +@test f0() === 42 + @test f1 isa Function du = rand(2) From 1b3af21468a73f1aed69a8358fb90c8c68db1548 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 10 Aug 2023 20:14:15 +0200 Subject: [PATCH 2/2] Update runtests.jl --- test/runtests.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 42910c0..53a718b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,8 +28,7 @@ ex3 = :(function (_du::T, _u::Vector{E}, _p::P, _t::Any) where {T <: Vector, E, nothing end) - -f0 = @RuntimeGeneratedFunction(()->42) +f0 = @RuntimeGeneratedFunction(:(()->42)) f1 = @RuntimeGeneratedFunction(ex1) f2 = @RuntimeGeneratedFunction(ex2) f3 = @RuntimeGeneratedFunction(ex3)