From c3952aa3cee6db08f7b2597e5f5fa2305e8a8f7f Mon Sep 17 00:00:00 2001 From: fglock Date: Thu, 31 Jul 2008 11:05:17 +0000 Subject: [PATCH] [v6.pm] complex git-svn-id: http://svn.pugscode.org/pugs@21648 c213334d-75ef-0310-aa23-eaa082d1ae64 --- .../lib/Pugs/Emitter/Perl6/Perl5.pm | 10 ++++++++++ Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm | 14 ++++++++++---- Pugs-Compiler-Perl6/lib/v6.pm | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm b/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm index 4d6d238b..e1cbc8d8 100644 --- a/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm +++ b/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm @@ -247,6 +247,12 @@ sub _emit_pair { return '{' . _emit( $n->{key} ) . '=>' . $value . '}' } +sub _emit_complex { + my $n = shift; + $n =~ s/i/*i/; + "($n)"; +} + sub _emit { my $n = $_[0]; #die "_emit: ", Dumper( $n ); @@ -292,6 +298,9 @@ sub _emit { return $n->{num} if exists $n->{num}; + return _emit_complex( $n->{complex} ) + if exists $n->{complex}; + return _emit_pair( $n->{pair} ) if exists $n->{pair}; @@ -1280,6 +1289,7 @@ sub term { our \@EXPORT; bool->import(); # True, False use Quantum::Superpositions; + use Math::Complex; $attributes "; return ref( $n->{block} ) && exists $n->{block}{bare_block} diff --git a/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm b/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm index ab478853..bd62f95e 100644 --- a/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm +++ b/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm @@ -674,17 +674,23 @@ sub recompile { } } ^ ), q() => Pugs::Compiler::Token->compile( q^ - ### num/int + ### num/int/complex \d+ [ \.\d+ [ <[Ee]> <[+-]>? \d+ ]? - { return { num => $() ,} } + [ i { return { complex => $() ,} } + | { return { num => $() ,} } + ] | <[Ee]> <[+-]>? \d+ - { return { num => $() ,} } + [ i { return { complex => $() ,} } + | { return { num => $() ,} } + ] | - { return { int => $() ,} } + [ i { return { complex => $() ,} } + | { return { int => $() ,} } + ] ] | diff --git a/Pugs-Compiler-Perl6/lib/v6.pm b/Pugs-Compiler-Perl6/lib/v6.pm index e719f871..52fa25c7 100644 --- a/Pugs-Compiler-Perl6/lib/v6.pm +++ b/Pugs-Compiler-Perl6/lib/v6.pm @@ -93,6 +93,7 @@ sub pmc_compile { ) : ''). "use Scalar::Util; use Quantum::Superpositions; + use Math::Complex; use Pugs::Runtime::Perl6; use Pugs::Runtime::Perl6Prelude; use Pugs::Runtime::Perl5Container;