From fa94131ec6384adbc3c2db55fa2cb7d982ee380e Mon Sep 17 00:00:00 2001 From: Francisco Heron de Carvalho Junior Date: Thu, 17 Nov 2022 08:44:51 -0500 Subject: [PATCH] =?UTF-8?q?*=20Simplification=20of=20the=20syntax=20from?= =?UTF-8?q?=20"@platform=20feature=20"=20to?= =?UTF-8?q?=20"@platform=20feature::?= =?UTF-8?q?=E2=80=9D.=20*=20Improved=20error=20handling=20of=20the=20@plat?= =?UTF-8?q?form=20macro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 2 +- src/platform.jl | 67 ++++++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/Project.toml b/Project.toml index 46f65b1..55cbfba 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PlatformAware" uuid = "e7c50b67-2c03-471e-9cf2-69e515d86ecf" authors = ["Francisco Heron de Carvalho Junior and contributors"] -version = "0.5.0" +version = "0.5.1" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" diff --git a/src/platform.jl b/src/platform.jl index 23344e9..c4bc792 100644 --- a/src/platform.jl +++ b/src/platform.jl @@ -191,7 +191,7 @@ function include_platform_feature!(f) keys(state.platform_feature) end -function platform_parameter_macro!(f, x) +function platform_parameter_macro!(f) if (f == :clear) empty_platform_feature!() elseif (f == :all) @@ -200,12 +200,16 @@ function platform_parameter_macro!(f, x) reset_platform_feature!() elseif (f == :default) default_platform_feature!() - elseif (isnothing(x)) + elseif typeof(f) == Symbol check_all(f) include_platform_feature!(f) - else + elseif f.head == :(::) + x = f.args[2] + f = f.args[1] check_all(f) update_platform_feature!(f,getFeature(f, string(x), state.platform_feature_default_all)) + else + platform_syntax_message() end end @@ -250,35 +254,36 @@ function getaddparameter() return can_add_parameter[] end -macro platform(t,f) - if (t == :default) - # @platform default creates an entry function, called from outside, and a (default) kernel function - denyaddparameter!() - e = build_entry_function(f) - k = build_kernel_function(f) - return esc(:($e;$k)) - #return k - elseif (t == :aware) - denyaddparameter!() - return esc(build_kernel_function(f)) - elseif ((t == :parameter || t == :feature) && getaddparameter()) - platform_parameter_macro!(f, nothing) - elseif ((t == :parameter || t == :feature) && !getaddparameter()) - @info "cannot add parameters after including the first kernel method" - elseif (t == :assumption) - assumptions_dict[][f.args[1]] = f.args[2] - return nothing - else - platform_syntax_message() - end - end +macro platform(t, f, ff...) - macro platform(t,f,x) - if ((t == :parameter || t == :feature) && getaddparameter()) - platform_parameter_macro!(f,x) - elseif ((t == :parameter || t == :feature) && !getaddparameter()) - @info "cannot add parameters after including the first kernel method" - else + try + if (length(ff) > 0) + platform_syntax_message() + return + end + + if (t == :default) + # @platform default creates an entry function, called from outside, and a (default) kernel function + denyaddparameter!() + e = build_entry_function(f) + k = build_kernel_function(f) + return esc(:($e;$k)) + #return k + elseif (t == :aware) + denyaddparameter!() + return esc(build_kernel_function(f)) + elseif ((t == :parameter || t == :feature) && getaddparameter()) + platform_parameter_macro!(f) + elseif ((t == :parameter || t == :feature) && !getaddparameter()) + @info "cannot add parameters after including the first kernel method" + elseif (t == :assumption) + assumptions_dict[][f.args[1]] = f.args[2] + return nothing + else + platform_syntax_message() + end + catch e + @error e platform_syntax_message() end end