diff --git a/src/Partcl/commands/expr.pm b/src/Partcl/commands/expr.pm index 5c9a775..0756338 100644 --- a/src/Partcl/commands/expr.pm +++ b/src/Partcl/commands/expr.pm @@ -1,25 +1,25 @@ -#sub expr(*@args) { -# my $code := pir::join(' ', @args); -# error("empty expression\nin expression \"\"") -# if $code eq ''; -# -# our %EXPRCACHE; -# my &sub := %EXPRCACHE{$code}; -# unless pir::defined(&sub) { -# my $parse := -# Partcl::Grammar.parse( -# $code, -# :rule('TOP_expr'), -# :actions(Partcl::Actions) -# ); -# if $parse { -# &sub := PAST::Compiler.compile($parse.ast); -# %EXPRCACHE{$code} := ⊂ -# } else { -# error("Invalid expression"); -# } -# } -# &sub(); -#} -# -## vim: expandtab shiftwidth=4 ft=perl6: +sub expr(*@args) { + my $code := nqp::join(' ', @args); + error("empty expression\nin expression \"\"") + if $code eq ''; + + our %EXPRCACHE; + my &sub := %EXPRCACHE{$code}; + unless nqp::defined(&sub) { + my $parse := + Partcl::Grammar.parse( + $code, + :rule('TOP_expr'), + :actions(Partcl::Actions) + ); + if $parse { + &sub := PAST::Compiler.compile($parse.ast); + %EXPRCACHE{$code} := ⊂ + } else { + error("Invalid expression"); + } + } + &sub(); +} + +# vim: expandtab shiftwidth=4 ft=perl6: