Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
[v6.pm] complex
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.pugscode.org/pugs@21648 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
fglock committed Jul 31, 2008
1 parent 61107ab commit c3952aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm
Expand Up @@ -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 );
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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}
Expand Down
14 changes: 10 additions & 4 deletions Pugs-Compiler-Perl6/lib/Pugs/Grammar/Term.pm
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions Pugs-Compiler-Perl6/lib/v6.pm
Expand Up @@ -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;
Expand Down

0 comments on commit c3952aa

Please sign in to comment.