Perlito5
view release on metacpan or search on metacpan
lib/Perlito5/XS/Emitter.pm view on Meta::CPAN
my $level = $_[1];
my $cond;
if (ref($self->{cond}) eq 'ARRAY') {
# C-style for
$cond =
( $self->{cond}[0] ? $self->{cond}[0]->emit_javascript($level + 1) . '; ' : '; ' )
. ( $self->{cond}[1] ? $self->{cond}[1]->emit_javascript($level + 1) . '; ' : '; ' )
. ( $self->{cond}[2] ? $self->{cond}[2]->emit_javascript($level + 1) . ' ' : ' ' )
}
else {
$cond = $self->{cond}->emit_xs($level+1)
}
my $sig = '';
my $sig_ast = $self->{body}->sig();
if (!$sig_ast) {
# $_
}
elsif ($sig_ast->{decl}) {
$sig = $sig_ast->{decl} . ' ' . $sig_ast->{type} . ' ' . $sig_ast->{var}->emit_xs($level+1) . ' ';
}
else {
$sig = $sig_ast->emit_xs($level+1) . ' ';
}
return 'for ' . $sig . '(' . $cond . ') {' . "\n"
. join(";\n", map( Perlito5::XS::tab($level+1) . $_->emit_xs( $level + 1 ), @{ $self->{body}->stmts } )) . "\n"
. Perlito5::XS::tab($level) . "}"
}
}
package Perlito5::AST::Decl;
{
sub emit_xs {
my $self = $_[0];
my $level = $_[1];
$self->{type} = 'SV *';
my $decl = $self->{decl};
my $str =
$self->{type} . $self->{var}->emit_xs($level+1);
return $str;
}
}
package Perlito5::AST::Sub;
{
sub emit_xs {
my $self = $_[0];
my $level = $_[1];
my $name = '';
#$name = $self->{namespace} . "::" . $self->{name} . " "
$name = $self->{name} . " "
if $self->{name};
my $sig = $self->{sig};
my $i = 0;
'void ' . $name . "()\n"
. "PPCODE:\n"
. join(";\n", map( Perlito5::XS::tab($level+1) . $_->emit_xs( $level + 1 ), @{$self->{block}} )) . ";\n"
}
}
1;
=begin
=head1 NAME
Perlito5::XS::Emit - Code generator for Perlito5-in-XS
=head1 SYNOPSIS
$program->emit_xs() # generated XS code
=head1 DESCRIPTION
This module generates XS code for the Perlito compiler.
=head1 AUTHORS
Flavio Soibelmann Glock <fglock@gmail.com>.
The Pugs Team.
=head1 SEE ALSO
The Perl 6 homepage at L<http://dev.perl.org/perl6>.
The Pugs homepage at L<http://pugscode.org/>.
=head1 COPYRIGHT
Copyright 2006, 2009, 2011, 2012 by Flavio Soibelmann Glock, Audrey Tang and others.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=end
( run in 0.777 second using v1.01-cache-2.11-cpan-5511b514fd6 )