Permalink
Browse files

[v6.pm] complex

git-svn-id: http://svn.pugscode.org/pugs@21648 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 61107ab commit c3952aa3cee6db08f7b2597e5f5fa2305e8a8f7f fglock committed Jul 31, 2008
@@ -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}
@@ -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 => $() ,} }
+ ]
]
|
<Pugs::Grammar::Perl6.sub_decl>
@@ -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;

0 comments on commit c3952aa

Please sign in to comment.