1# Do not edit this file - Generated by Perlito6 9.0 2use v5; 3use utf8; 4use strict; 5use warnings; 6no warnings ('redefine', 'once', 'void', 'uninitialized', 'misc', 'recursion'); 7use Perlito6::Perl5::Runtime; 8use Perlito6::Perl5::Prelude; 9our $MATCH = Perlito6::Match->new(); 10{ 11package GLOBAL; 12 sub new { shift; bless { @_ }, "GLOBAL" } 13 14 # use v6 15; 16 { 17 package Perlito6::Go::LexicalBlock; 18 sub new { shift; bless { @_ }, "Perlito6::Go::LexicalBlock" } 19 sub block { $_[0]->{block} }; 20 sub needs_return { $_[0]->{needs_return} }; 21 sub top_level { $_[0]->{top_level} }; 22 sub emit_go { 23 my $self = $_[0]; 24 if (!(((defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))))) { 25 return scalar ('') 26 }; 27 ((my $str) = ''); 28 (my $Hash_decl_seen = bless {}, 'HASH'); 29 for my $decl1 ( @{(defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))} ) { 30 ((my $decl) = $decl1); 31 if (((Main::isa($decl, 'Bind') && Main::isa(($decl->parameters()), 'Decl')) && ((($decl->parameters())->decl() eq 'my')))) { 32 ($decl = $decl->parameters()) 33 }; 34 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'my')))) { 35 ((my $var_name) = (($decl)->var())->emit_go()); 36 if (!(($Hash_decl_seen->{$var_name}))) { 37 ($str = ($str . $decl->emit_go_init())); 38 ($Hash_decl_seen->{$var_name} = 1) 39 } 40 } 41 }; 42 (my $last_statement); 43 if ($self->{needs_return}) { 44 ($last_statement = pop( @{(defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))} )) 45 }; 46 for my $decl ( @{(defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))} ) { 47 if ((!(((Main::isa($decl, 'Decl') && (($decl->decl() eq 'my'))))))) { 48 ($str = ($str . ($decl)->emit_go() . chr(59))) 49 } 50 }; 51 if (($self->{needs_return} && $last_statement)) { 52 if (Main::isa($last_statement, 'If')) { 53 ((my $cond) = $last_statement->cond()); 54 ((my $body) = $last_statement->body()); 55 ((my $otherwise) = $last_statement->otherwise()); 56 if ((Main::isa($cond, 'Apply') && ($cond->code() eq 'prefix:<' . chr(33) . '>'))) { 57 ($cond = ($cond->arguments())->[0]); 58 ($body = $last_statement->otherwise()); 59 ($otherwise = $last_statement->body()) 60 }; 61 if ((Main::isa($cond, 'Var') && ($cond->sigil() eq chr(64)))) { 62 ($cond = Apply->new(('code' => 'prefix:<' . chr(64) . '>'), ('arguments' => do { 63 (my $List_a = bless [], 'ARRAY'); 64 (my $List_v = bless [], 'ARRAY'); 65 push( @{$List_a}, $cond ); 66 $List_a 67}))) 68 }; 69 ($body = Perlito6::Go::LexicalBlock->new(('block' => $body), ('needs_return' => 1), ('top_level' => $self->{top_level}))); 70 ($otherwise = Perlito6::Go::LexicalBlock->new(('block' => $otherwise), ('needs_return' => 1), ('top_level' => $self->{top_level}))); 71 ($str = ($str . 'if tobool( ' . Call::emit_go_call($cond, 'Bool') . ' ) ' . chr(123) . ' ' . $body->emit_go() . ' ' . chr(125) . ' else ' . chr(123) . ' ' . $otherwise->emit_go() . ' ' . chr(125))) 72 } 73 else { 74 if ((Main::isa($last_statement, 'Return') || Main::isa($last_statement, 'For'))) { 75 ($str = ($str . $last_statement->emit_go())) 76 } 77 else { 78 ($last_statement = Return->new(('result' => $last_statement))); 79 if ($self->{top_level}) { 80 ($str = ($str . $last_statement->emit_go())) 81 } 82 else { 83 ($str = ($str . $last_statement->emit_go_simple())) 84 } 85 } 86 } 87 }; 88 return scalar ($str) 89 } 90 } 91 92; 93 { 94 package CompUnit; 95 sub new { shift; bless { @_ }, "CompUnit" } 96 sub attributes { $_[0]->{attributes} }; 97 sub methods { $_[0]->{methods} }; 98 sub emit_go { 99 my $self = $_[0]; 100 ((my $class_name) = Main::to_go_namespace($self->{name})); 101 ((my $str) = (chr(47) . chr(47) . ' instances of class ' . $self->{name} . (chr(10)) . 'type ' . $class_name . ' struct ' . chr(123) . (chr(10)))); 102 for my $decl ( @{((Main::values(((defined $self->{attributes} ? $self->{attributes} : ($self->{attributes} = bless({}, 'HASH')))), )))} ) { 103 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 104 ($str = ($str . ' ' . 'v_' . ($decl->var())->name() . ' *Any' . chr(59) . (chr(10)))) 105 } 106 }; 107 ($str = ($str . chr(125) . (chr(10)))); 108 ($str = ($str . chr(47) . chr(47) . ' methods in class ' . $self->{name} . (chr(10)) . 'var Method_' . $class_name . ' struct ' . chr(123) . (chr(10)))); 109 for my $decl ( @{((Main::values(((defined $self->{methods} ? $self->{methods} : ($self->{methods} = bless({}, 'HASH')))), )))} ) { 110 if (Main::isa($decl, 'Method')) { 111 ($str = ($str . ' ' . 'f_' . $decl->name() . ' func (*' . $class_name . ', Capture) *Any' . chr(59) . (chr(10)))) 112 } 113 }; 114 for my $decl ( @{((Main::values(((defined $self->{attributes} ? $self->{attributes} : ($self->{attributes} = bless({}, 'HASH')))), )))} ) { 115 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 116 ($str = ($str . ' ' . 'f_' . ($decl->var())->name() . ' func (*' . $class_name . ', Capture) *Any' . chr(59) . (chr(10)))) 117 } 118 }; 119 ($str = ($str . chr(125) . (chr(10)))); 120 ($str = ($str . chr(47) . chr(47) . ' namespace ' . $self->{name} . (chr(10)) . 'var Namespace_' . $class_name . ' struct ' . chr(123) . (chr(10)))); 121 for my $decl ( @{(defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))} ) { 122 if (Main::isa($decl, 'Sub')) { 123 ($str = ($str . ' ' . 'f_' . $decl->name() . ' Function' . chr(59) . (chr(10)))) 124 } 125 }; 126 ($str = ($str . chr(125) . (chr(10)))); 127 ($str = ($str . 'var Run_' . $class_name . ' func ()' . chr(59) . (chr(10)))); 128 ($str = ($str . chr(47) . chr(47) . ' method wrappers for ' . $self->{name} . (chr(10)))); 129 for my $decl ( @{((Main::values(((defined $self->{methods} ? $self->{methods} : ($self->{methods} = bless({}, 'HASH')))), )))} ) { 130 if (Main::isa($decl, 'Method')) { 131 ($str = ($str . 'func (v_self *' . $class_name . ') f_' . $decl->name() . ' (v Capture) *Any ' . chr(123) . (chr(10)) . ' return Method_' . $class_name . '.f_' . $decl->name() . '(v_self, v)' . chr(59) . (chr(10)) . chr(125) . (chr(10)))) 132 } 133 }; 134 for my $decl ( @{((Main::values(((defined $self->{attributes} ? $self->{attributes} : ($self->{attributes} = bless({}, 'HASH')))), )))} ) { 135 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 136 ($str = ($str . 'func (v_self *' . $class_name . ') f_' . ($decl->var())->name() . ' (v Capture) *Any ' . chr(123) . (chr(10)) . ' return Method_' . $class_name . '.f_' . ($decl->var())->name() . '(v_self, v)' . chr(59) . (chr(10)) . chr(125) . (chr(10)))) 137 } 138 }; 139 if (!((((defined $self->{methods} ? $self->{methods} : ($self->{methods} = bless({}, 'HASH'))))->{'isa'}))) { 140 ($str = ($str . 'func (v_self *' . $class_name . ') f_isa (v Capture) *Any ' . chr(123) . ' ' . 'return toBool( ' . chr(34) . $self->{name} . chr(34) . ' ' . chr(61) . chr(61) . ' tostr( v.p[0] ) ) ' . chr(125) . (chr(10)))) 141 }; 142 if (!((((defined $self->{methods} ? $self->{methods} : ($self->{methods} = bless({}, 'HASH'))))->{'perl'}))) { 143 ($str = ($str . 'func (v_self *' . $class_name . ') f_perl (v Capture) *Any ' . chr(123) . ' ' . 'return toStr( ' . chr(34) . '::' . $self->{name} . '(' . chr(34) . ' ')); 144 ((my $sep) = ''); 145 for my $decl ( @{((Main::values(((defined $self->{attributes} ? $self->{attributes} : ($self->{attributes} = bless({}, 'HASH')))), )))} ) { 146 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 147 ($str = ($str . $sep . '+ ' . chr(34) . ($decl->var())->name() . ' ' . chr(61) . '> ' . chr(34) . '+ tostr((*(*v_self).f_' . ($decl->var())->name() . '(Capture' . chr(123) . chr(125) . ')).(perl_er).f_perl(Capture' . chr(123) . chr(125) . ')) ')); 148 ($sep = '+ ' . chr(34) . ', ' . chr(34) . ' ') 149 } 150 }; 151 ($str = ($str . '+ ' . chr(34) . ')' . chr(34) . ' ) ' . chr(125) . (chr(10)))) 152 }; 153 if (((!((((defined $self->{methods} ? $self->{methods} : ($self->{methods} = bless({}, 'HASH'))))->{'Bool'}))) && (!((((defined $self->{attributes} ? $self->{attributes} : ($self->{attributes} = bless({}, 'HASH'))))->{'Bool'}))))) { 154 ($str = ($str . 'func (v_self *' . $class_name . ') f_Bool (v Capture) *Any ' . chr(123) . ' ' . 'return b_true() ' . chr(125) . (chr(10)))) 155 }; 156 ($str = ($str . chr(47) . chr(47) . ' prototype of ' . $self->{name} . (chr(10)) . 'var Proto_' . $class_name . ' *Any' . chr(59) . (chr(10)))); 157 ($str = ($str . 'func Init_' . $class_name . '() ' . chr(123) . (chr(10)))); 158 ($str = ($str . ' this_namespace :' . chr(61) . ' ' . chr(38) . 'Namespace_' . $class_name . chr(59) . (chr(10)) . ' this_namespace ' . chr(61) . ' this_namespace' . chr(59) . (chr(10)))); 159 ($str = ($str . ' Proto_' . $class_name . ' ' . chr(61) . ' ' . 'func() *Any ' . chr(123) . ' ' . 'var m ' . chr(61) . ' new(' . $class_name . ')' . chr(59) . ' ' . 'var m1 Any ' . chr(61) . ' m' . chr(59) . ' ' . 'return ' . chr(38) . 'm1' . chr(59) . ' ' . chr(125) . '()' . chr(59) . (chr(10)))); 160 (my $Hash_decl_seen = bless {}, 'HASH'); 161 for my $decl1 ( @{(defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))} ) { 162 ((my $decl) = $decl1); 163 if (((Main::isa($decl, 'Bind') && Main::isa(($decl->parameters()), 'Decl')) && ((($decl->parameters())->decl() eq 'my')))) { 164 ($decl = $decl->parameters()) 165 }; 166 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'my')))) { 167 ((my $var_name) = (($decl)->var())->emit_go()); 168 if (!(($Hash_decl_seen->{$var_name}))) { 169 ($str = ($str . $decl->emit_go_init())); 170 ($Hash_decl_seen->{$var_name} = 1) 171 } 172 } 173 }; 174 for my $decl ( @{(defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))} ) { 175 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 176 ($str = ($str . ' ' . chr(47) . chr(47) . ' accessor ' . ($decl->var())->name() . (chr(10)) . ' Method_' . $class_name . '.f_' . ($decl->var())->name() . ' ' . chr(61) . ' func (v_self *' . $class_name . ', v Capture) *Any ' . chr(123) . (chr(10)))); 177 ($str = ($str . ' ' . 'if v_self.v_' . ($decl->var())->name() . ' ' . chr(61) . chr(61) . ' nil ' . chr(123) . (chr(10)) . ' ' . (Decl->new(('decl' => 'my'), ('type' => undef()), ('var' => Var->new(('sigil' => ($decl->var())->sigil()), ('twigil' => ''), ('namespace' => ''), ('name' => 'tmp')))))->emit_go_init() . ' ' . 'v_self.v_' . ($decl->var())->name() . ' ' . chr(61) . ' ' . (Var->new(('sigil' => ($decl->var())->sigil()), ('twigil' => ''), ('namespace' => ''), ('name' => 'tmp')))->emit_go() . chr(59) . (chr(10)) . ' ' . chr(125) . (chr(10)))); 178 ($str = ($str . ' ' . 'if *v_self.v_' . ($decl->var())->name() . ' ' . chr(61) . chr(61) . ' nil ' . chr(123) . (chr(10)) . ' ' . (Decl->new(('decl' => 'my'), ('type' => undef()), ('var' => Var->new(('sigil' => ($decl->var())->sigil()), ('twigil' => ''), ('namespace' => ''), ('name' => 'tmp')))))->emit_go_init() . ' ' . 'v_self.v_' . ($decl->var())->name() . ' ' . chr(61) . ' ' . (Var->new(('sigil' => ($decl->var())->sigil()), ('twigil' => ''), ('namespace' => ''), ('name' => 'tmp')))->emit_go() . chr(59) . (chr(10)) . ' ' . chr(125) . (chr(10)))); 179 ($str = ($str . ' ' . 'return v_self.v_' . ($decl->var())->name() . (chr(10)) . ' ' . chr(125) . chr(59) . (chr(10)))) 180 }; 181 if (Main::isa($decl, 'Method')) { 182 ((my $sig) = $decl->sig()); 183 ((my $block) = Perlito6::Go::LexicalBlock->new(('block' => $decl->block()), ('needs_return' => 1), ('top_level' => 1))); 184 ($str = ($str . ' ' . chr(47) . chr(47) . ' method ' . $decl->name() . (chr(10)) . ' Method_' . $class_name . '.f_' . $decl->name() . ' ' . chr(61) . ' func (self *' . $class_name . ', v Capture) *Any ' . chr(123) . (chr(10)))); 185 ($str = ($str . ' var self1 Any ' . chr(61) . ' self' . chr(59) . (chr(10)) . ' var ' . ($sig->invocant())->emit_go() . ' *Any ' . chr(61) . ' ' . chr(38) . 'self1' . chr(59) . (chr(10)) . ' ' . ($sig->invocant())->emit_go() . ' ' . chr(61) . ' ' . ($sig->invocant())->emit_go() . chr(59) . (chr(10)) . ' ' . $sig->emit_go_bind() . (chr(10)))); 186 ($str = ($str . ' p :' . chr(61) . ' make(chan *Any)' . chr(59) . ' go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . $block->emit_go() . chr(59) . ' p <- nil ' . chr(125) . '()' . chr(59) . ' ' . (chr(10)) . ' return <-p' . chr(59) . ' ' . (chr(10)) . ' ' . chr(125) . chr(59) . (chr(10)))) 187 }; 188 if (Main::isa($decl, 'Sub')) { 189 ((my $sig) = $decl->sig()); 190 ((my $block) = Perlito6::Go::LexicalBlock->new(('block' => $decl->block()), ('needs_return' => 1), ('top_level' => 1))); 191 ($str = ($str . ' ' . chr(47) . chr(47) . ' sub ' . $decl->name() . (chr(10)) . ' Namespace_' . $class_name . '.f_' . $decl->name() . ' ' . chr(61) . ' Function( func (v Capture) *Any ' . chr(123) . (chr(10)))); 192 ($str = ($str . ' ' . $sig->emit_go_bind() . (chr(10)) . ' p :' . chr(61) . ' make(chan *Any)' . chr(59) . ' go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . $block->emit_go() . chr(59) . ' p <- nil ' . chr(125) . '()' . chr(59) . ' ' . (chr(10)))); 193 ($str = ($str . ' return <-p' . chr(59) . ' ' . (chr(10)) . ' ' . chr(125) . ' )' . chr(59) . (chr(10)))) 194 } 195 }; 196 ($str = ($str . ' ' . chr(47) . chr(47) . ' main runtime block of ' . $self->{name} . (chr(10)) . ' Run_' . $class_name . ' ' . chr(61) . ' func () ' . chr(123) . (chr(10)))); 197 for my $decl ( @{(defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))} ) { 198 if ((((!(((Main::isa($decl, 'Decl') && (((($decl->decl() eq 'has')) || (($decl->decl() eq 'my')))))))) && (!((Main::isa($decl, 'Method'))))) && (!((Main::isa($decl, 'Sub')))))) { 199 ($str = ($str . ' ' . ($decl)->emit_go() . chr(59) . (chr(10)))) 200 } 201 }; 202 ($str = ($str . ' ' . chr(125) . (chr(10)))); 203 ($str = ($str . chr(125) . (chr(10)))); 204 return scalar ($str) 205 }; 206 sub emit_go_program { 207 my $comp_units = $_[0]; 208 ((my $str) = ''); 209 (my $Hash_unit_seen = bless {}, 'HASH'); 210 (my $List_tmp_comp_unit = bless [], 'ARRAY'); 211 for my $comp_unit ( @{(($comp_units))} ) { 212 ((my $name) = $comp_unit->name()); 213 if ($Hash_unit_seen->{$name}) { 214 for my $stmt ( @{(($comp_unit->body()))} ) { 215 push( @{($Hash_unit_seen->{$name})->body()}, $stmt ) 216 } 217 } 218 else { 219 ($Hash_unit_seen->{$name} = $comp_unit); 220 push( @{$List_tmp_comp_unit}, $comp_unit ) 221 } 222 }; 223 ($comp_units = $List_tmp_comp_unit); 224 for my $comp_unit ( @{(($comp_units))} ) { 225 for my $stmt ( @{(($comp_unit->body()))} ) { 226 if (Main::isa($stmt, 'Method')) { 227 (($comp_unit->methods())->{$stmt->name()} = $stmt) 228 }; 229 if ((Main::isa($stmt, 'Decl') && (($stmt->decl() eq 'has')))) { 230 (($comp_unit->attributes())->{($stmt->var())->name()} = $stmt) 231 } 232 } 233 }; 234 for my $comp_unit ( @{(($comp_units))} ) { 235 ($str = ($str . $comp_unit->emit_go())) 236 }; 237 if (!(($Hash_unit_seen->{('Perlito6::Grammar')}))) { 238 ($str = ($str . ('type Perlito__Grammar struct' . chr(123) . chr(125) . chr(10)))) 239 }; 240 ($str = ($str . (chr(47) . chr(47) . ' interfaces for all methods' . chr(10)))); 241 ((my $Hash_meth_seen = bless {}, 'HASH') = do { 242 (my $Hash_a = bless {}, 'HASH'); 243 ($Hash_a->{'join'} = 1); 244 ($Hash_a->{'perl'} = 1); 245 ($Hash_a->{'scalar'} = 1); 246 ($Hash_a->{'isa'} = 1); 247 ($Hash_a->{'values'} = 1); 248 ($Hash_a->{'keys'} = 1); 249 ($Hash_a->{'exists'} = 1); 250 ($Hash_a->{'bind'} = 1); 251 ($Hash_a->{'int'} = 1); 252 ($Hash_a->{'num'} = 1); 253 ($Hash_a->{'str'} = 1); 254 ($Hash_a->{'Str'} = 1); 255 ($Hash_a->{'bool'} = 1); 256 ($Hash_a->{'Bool'} = 1); 257 ($Hash_a->{'array'} = 1); 258 ($Hash_a->{'hash'} = 1); 259 ($Hash_a->{'push'} = 1); 260 ($Hash_a->{'pop'} = 1); 261 ($Hash_a->{'shift'} = 1); 262 ($Hash_a->{'lookup'} = 1); 263 ($Hash_a->{'index'} = 1); 264 ($Hash_a->{'function'} = 1); 265 $Hash_a 266}); 267 for my $comp_unit ( @{(($comp_units))} ) { 268 for my $stmt ( @{(($comp_unit->body()))} ) { 269 if ((Main::isa($stmt, 'Method') && !(($Hash_meth_seen->{$stmt->name()})))) { 270 ((my $meth) = $stmt->name()); 271 ($str = ($str . ('type ') . $meth . ('_er interface ' . chr(123) . ' f_') . $meth . (' (Capture) *Any ' . chr(125) . chr(10)))); 272 ($Hash_meth_seen->{$meth} = 1) 273 }; 274 if (((Main::isa($stmt, 'Decl') && (($stmt->decl() eq 'has'))) && !(($Hash_meth_seen->{($stmt->var())->name()})))) { 275 ((my $meth) = ($stmt->var())->name()); 276 ($str = ($str . ('type ') . $meth . ('_er interface ' . chr(123) . ' f_') . $meth . (' (Capture) *Any ' . chr(125) . chr(10)))); 277 ($Hash_meth_seen->{$meth} = 1) 278 } 279 } 280 }; 281 ($str = ($str . (chr(10)) . ('func main () ' . chr(123) . chr(10)) . (' Init_Perlito__Match()' . chr(59) . chr(10)))); 282 for my $comp_unit ( @{(($comp_units))} ) { 283 ($str = ($str . (' Init_') . Main::to_go_namespace($comp_unit->name()) . ('()' . chr(59) . chr(10)))) 284 }; 285 ($str = ($str . (' Init_Prelude()' . chr(59) . chr(10)))); 286 for my $comp_unit ( @{(($comp_units))} ) { 287 ($str = ($str . (' Run_') . Main::to_go_namespace($comp_unit->name()) . ('()' . chr(59) . chr(10)))) 288 }; 289 ($str = ($str . chr(125) . (chr(10)))); 290 return scalar ($str) 291 } 292 } 293 294; 295 { 296 package Val::Int; 297 sub new { shift; bless { @_ }, "Val::Int" } 298 sub emit_go { 299 my $self = $_[0]; 300 ('toInt(' . $self->{int} . ')') 301 } 302 } 303 304; 305 { 306 package Val::Bit; 307 sub new { shift; bless { @_ }, "Val::Bit" } 308 sub emit_go { 309 my $self = $_[0]; 310 ($self->{bit} ? 'b_true()' : 'b_false()') 311 } 312 } 313 314; 315 { 316 package Val::Num; 317 sub new { shift; bless { @_ }, "Val::Num" } 318 sub emit_go { 319 my $self = $_[0]; 320 ('toNum(' . $self->{num} . ')') 321 } 322 } 323 324; 325 { 326 package Val::Buf; 327 sub new { shift; bless { @_ }, "Val::Buf" } 328 sub emit_go { 329 my $self = $_[0]; 330 ('toStr(' . chr(34) . $self->{buf} . chr(34) . ')') 331 } 332 } 333 334; 335 { 336 package Lit::Array; 337 sub new { shift; bless { @_ }, "Lit::Array" } 338 sub emit_go { 339 my $self = $_[0]; 340 ((my $ast) = $self->expand_interpolation()); 341 return scalar ($ast->emit_go()) 342 } 343 } 344 345; 346 { 347 package Lit::Hash; 348 sub new { shift; bless { @_ }, "Lit::Hash" } 349 sub emit_go { 350 my $self = $_[0]; 351 ((my $ast) = $self->expand_interpolation()); 352 return scalar ($ast->emit_go()) 353 } 354 } 355 356; 357 { 358 package Index; 359 sub new { shift; bless { @_ }, "Index" } 360 sub emit_go { 361 my $self = $_[0]; 362 ('(*(*' . $self->{obj}->emit_go() . ').(array_er).f_array(Capture' . chr(123) . chr(125) . '))' . '.(index_er).f_index( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . $self->{index_exp}->emit_go() . ' ' . chr(125) . chr(125) . ' )') 363 } 364 } 365 366; 367 { 368 package Lookup; 369 sub new { shift; bless { @_ }, "Lookup" } 370 sub emit_go { 371 my $self = $_[0]; 372 ('(*(*' . $self->{obj}->emit_go() . ').(hash_er).f_hash(Capture' . chr(123) . chr(125) . '))' . '.(lookup_er).f_lookup( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . $self->{index_exp}->emit_go() . ' ' . chr(125) . chr(125) . ' )') 373 } 374 } 375 376; 377 { 378 package Var; 379 sub new { shift; bless { @_ }, "Var" } 380 sub emit_go { 381 my $self = $_[0]; 382 ((my $table) = do { 383 (my $Hash_a = bless {}, 'HASH'); 384 ($Hash_a->{chr(36)} = 'v_'); 385 ($Hash_a->{chr(64)} = 'List_'); 386 ($Hash_a->{chr(37)} = 'Hash_'); 387 ($Hash_a->{chr(38)} = 'Code_'); 388 $Hash_a 389}); 390 ((my $ns) = ''); 391 if ($self->{namespace}) { 392 ($ns = (Main::to_go_namespace($self->{namespace}) . '.')) 393 }; 394 ((($self->{twigil} eq '.')) ? (('(*v_self).(' . $self->{name} . '_er).f_' . $self->{name} . '(Capture' . chr(123) . chr(125) . ')')) : (((($self->{name} eq chr(47))) ? ('v_MATCH') : (($table->{$self->{sigil}} . $ns . $self->{name}))))) 395 }; 396 sub plain_name { 397 my $self = $_[0]; 398 if ($self->{namespace}) { 399 return scalar (($self->{namespace} . '.' . $self->{name})) 400 }; 401 return scalar ($self->{name}) 402 } 403 } 404 405; 406 { 407 package Bind; 408 sub new { shift; bless { @_ }, "Bind" } 409 sub parameters { $_[0]->{parameters} }; 410 sub arguments { $_[0]->{arguments} }; 411 sub emit_go { 412 my $self = $_[0]; 413 if (Main::isa($self->{parameters}, 'Call')) { 414 return scalar (('func () *Any ' . chr(123) . ' ' . 'var tmp ' . chr(61) . ' ' . Call::emit_go_call($self->{parameters}->invocant(), $self->{parameters}->method()) . chr(59) . ' ' . '*tmp ' . chr(61) . ' *( ' . $self->{arguments}->emit_go() . ' )' . chr(59) . ' ' . 'return tmp' . chr(59) . ' ' . chr(125) . '()')) 415 }; 416 ('*' . $self->{parameters}->emit_go() . ' ' . chr(61) . ' *(' . $self->{arguments}->emit_go() . ')') 417 } 418 } 419 420; 421 { 422 package Proto; 423 sub new { shift; bless { @_ }, "Proto" } 424 sub emit_go { 425 my $self = $_[0]; 426 Main::to_go_namespace($self->{name}) 427 } 428 } 429 430; 431 { 432 package Call; 433 sub new { shift; bless { @_ }, "Call" } 434 sub emit_go { 435 my $self = $_[0]; 436 ((my $invocant) = $self->{invocant}->emit_go()); 437 if (Main::isa(($self->{invocant}), 'Proto')) { 438 if (($self->{invocant}->name() eq 'self')) { 439 ($invocant = 'v_self') 440 } 441 else { 442 ($invocant = ('Proto_' . $invocant)) 443 } 444 }; 445 ((my $meth) = $self->{method}); 446 if (($meth eq 'postcircumfix:<( )>')) { 447 if (($self->{hyper})) { 448 ($meth = '') 449 } 450 else { 451 return scalar (('((*' . $invocant . ').(function_er).f_function( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' ))')) 452 } 453 }; 454 if (($self->{hyper})) { 455 return scalar (('func (a_ *Any) *Any ' . chr(123) . ' ' . (chr(10)) . ' var out ' . chr(61) . ' a_array()' . chr(59) . ' ' . (chr(10)) . ' var i ' . chr(61) . ' (*(*a_).(array_er).f_array(Capture' . chr(123) . chr(125) . ')).(*Array)' . chr(59) . ' ' . (chr(10)) . ' for pos :' . chr(61) . ' 0' . chr(59) . ' pos <' . chr(61) . ' i.n' . chr(59) . ' pos++ ' . chr(123) . ' ' . (chr(10)) . ' (*out).(push_er).f_push( Capture' . chr(123) . 'p: []*Any' . chr(123) . ' (*i.v[pos]).(' . $meth . '_er).f_' . $meth . '(Capture' . chr(123) . ' p : []*Any' . chr(123) . chr(125) . ' ' . chr(125) . ') ' . chr(125) . chr(125) . ' )' . (chr(10)) . ' ' . chr(125) . ' ' . (chr(10)) . ' return out' . chr(59) . ' ' . (chr(10)) . chr(125) . '(' . $invocant . ')')) 456 }; 457 return scalar (('(*' . $invocant . ').(' . $meth . '_er).f_' . $meth . '( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 458 }; 459 sub emit_go_call { 460 my $invocant = $_[0]; 461 my $meth_name = $_[1]; 462 ((my $invocant1) = $invocant->emit_go()); 463 if (Main::isa(($invocant), 'Proto')) { 464 ($invocant1 = ('Proto_' . $invocant1)) 465 }; 466 ((my $meth) = $meth_name); 467 return scalar (('(*' . $invocant1 . ').(' . $meth . '_er).f_' . $meth . '(Capture' . chr(123) . chr(125) . ')')) 468 } 469 } 470 471; 472 { 473 package Apply; 474 sub new { shift; bless { @_ }, "Apply" } 475 sub emit_go { 476 my $self = $_[0]; 477 ((my $code) = $self->{code}); 478 if (Main::isa($code, 'Str')) { 479 480 } 481 else { 482 return scalar (('(' . $self->{code}->emit_go() . ')->(' . Main::join(([ map { $_->emit() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 483 }; 484 if (($code eq 'self')) { 485 return scalar ('v_self') 486 }; 487 if (($code eq 'False')) { 488 return scalar ('b_false()') 489 }; 490 if (($code eq 'True')) { 491 return scalar ('b_true()') 492 }; 493 if (($code eq 'make')) { 494 return scalar (('func () *Any ' . chr(123) . ' ' . 'tmp :' . chr(61) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . chr(59) . ' ' . '*(*v_MATCH).(capture_er).f_capture(Capture' . chr(123) . chr(125) . ') ' . chr(61) . ' *tmp' . chr(59) . ' ' . 'return tmp' . chr(59) . ' ' . chr(125) . '()')) 495 }; 496 if (($code eq 'go')) { 497 return scalar (('go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->block()), ('needs_return' => 0), ('top_level' => 1)))->emit_go() . (chr(10)) . ' ' . chr(125) . '()')) 498 }; 499 if (($code eq 'say')) { 500 return scalar (('f_print( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ', toStr(' . chr(34) . chr(92) . 'n' . chr(34) . ') ' . chr(125) . ' ' . chr(125) . ' )')) 501 }; 502 if (($code eq 'print')) { 503 return scalar (('f_print( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 504 }; 505 if (($code eq 'warn')) { 506 return scalar (('f_print_stderr( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ', toStr(' . chr(34) . chr(92) . 'n' . chr(34) . ') ' . chr(125) . ' ' . chr(125) . ' )')) 507 }; 508 if (($code eq 'die')) { 509 return scalar (('f_die( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 510 }; 511 if (($code eq 'defined')) { 512 return scalar (('f_defined( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 513 }; 514 if (($code eq 'pop')) { 515 return scalar (('f_pop( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 516 }; 517 if (($code eq 'push')) { 518 return scalar (('f_push( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 519 }; 520 if (($code eq 'shift')) { 521 return scalar (('f_shift( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 522 }; 523 if (($code eq 'index')) { 524 return scalar (('f_index( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 525 }; 526 if (($code eq 'substr')) { 527 return scalar (('f_substr( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 528 }; 529 if (($code eq 'scalar')) { 530 return scalar (('f_scalar( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 531 }; 532 if (($code eq 'Int')) { 533 return scalar (('toInt(' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ')' . ')')) 534 }; 535 if (($code eq 'Num')) { 536 return scalar (('toNum(' . 'tonum(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ')' . ')')) 537 }; 538 if (($code eq 'exists')) { 539 ((my $arg) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]); 540 if (Main::isa($arg, 'Lookup')) { 541 return scalar (('(*' . ($arg->obj())->emit_go() . ')' . '.(exists_er).f_exists(Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . ($arg->index_exp())->emit_go() . ' ' . chr(125) . ' ' . chr(125) . ' )')) 542 } 543 }; 544 if (($code eq 'prefix:<' . chr(126) . '>')) { 545 return scalar (Call::emit_go_call((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], 'Str')) 546 }; 547 if (($code eq 'prefix:<' . chr(33) . '>')) { 548 return scalar (('toBool(' . chr(33) . 'tobool(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . '))')) 549 }; 550 if (($code eq 'prefix:<' . chr(63) . '>')) { 551 return scalar (Call::emit_go_call((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], 'Bool')) 552 }; 553 if (($code eq 'prefix:<' . chr(36) . '>')) { 554 return scalar (('f_scalar( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )')) 555 }; 556 if (($code eq 'prefix:<' . chr(64) . '>')) { 557 return scalar (Call::emit_go_call((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], 'array')) 558 }; 559 if (($code eq 'prefix:<' . chr(37) . '>')) { 560 return scalar (Call::emit_go_call((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], 'hash')) 561 }; 562 if (($code eq 'infix:<' . chr(126) . '>')) { 563 return scalar (('toStr( ' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') + ' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ') ' . ')')) 564 }; 565 if (($code eq 'infix:<+>')) { 566 return scalar (('f_add( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 567 }; 568 if (($code eq 'infix:<->')) { 569 return scalar (('f_sub( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 570 }; 571 if (($code eq 'infix:<*>')) { 572 return scalar (('f_mul( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 573 }; 574 if (($code eq 'infix:<' . chr(47) . '>')) { 575 return scalar (('f_div( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 576 }; 577 if (($code eq 'infix:<>>')) { 578 return scalar (('f_greater( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 579 }; 580 if (($code eq 'infix:<<>')) { 581 return scalar (('f_smaller( ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 582 }; 583 if (($code eq 'infix:<>' . chr(61) . '>')) { 584 return scalar (('toBool( ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') >' . chr(61) . ' ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ') ' . ')')) 585 }; 586 if (($code eq 'infix:<<' . chr(61) . '>')) { 587 return scalar (('toBool( ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') <' . chr(61) . ' ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ') ' . ')')) 588 }; 589 if (($code eq 'infix:<' . chr(38) . chr(38) . '>')) { 590 return scalar (('f_and( ' . 'func () *Any ' . chr(123) . ' return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ' ' . chr(125) . ', ' . 'func () *Any ' . chr(123) . ' return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ' ' . chr(125) . ' ' . ')')) 591 }; 592 if (($code eq 'infix:<' . chr(124) . chr(124) . '>')) { 593 return scalar (('f_or( ' . 'func () *Any ' . chr(123) . ' return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ' ' . chr(125) . ', ' . 'func () *Any ' . chr(123) . ' return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ' ' . chr(125) . ' ' . ')')) 594 }; 595 if (($code eq 'infix:<eq>')) { 596 return scalar (('toBool(' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') ' . chr(61) . chr(61) . ' ' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ')' . ')')) 597 }; 598 if (($code eq 'infix:<ne>')) { 599 return scalar (('toBool(' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') ' . chr(33) . chr(61) . ' ' . 'tostr(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ')' . ')')) 600 }; 601 if (($code eq 'infix:<' . chr(61) . chr(61) . '>')) { 602 return scalar (('toBool(' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') ' . chr(61) . chr(61) . ' ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ') ' . ')')) 603 }; 604 if (($code eq 'infix:<' . chr(33) . chr(61) . '>')) { 605 return scalar (('toBool(' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_go() . ') ' . chr(33) . chr(61) . ' ' . 'toint(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ') ' . ')')) 606 }; 607 if (($code eq 'ternary:<' . chr(63) . chr(63) . ' ' . chr(33) . chr(33) . '>')) { 608 return scalar (('func () *Any ' . chr(123) . ' ' . 'if tobool( ' . Call::emit_go_call((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], 'Bool') . ' ) ' . chr(123) . ' return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_go() . ' ' . chr(125) . chr(59) . ' ' . 'return ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[2])->emit_go() . ' ' . chr(125) . '()')) 609 }; 610 ($code = ('f_' . $self->{code})); 611 if ($self->{namespace}) { 612 ($code = ('Namespace_' . Main::to_go_namespace($self->{namespace}) . '.' . $code)) 613 } 614 else { 615 ($code = ('this_namespace.' . $code)) 616 }; 617 ($code . '( Capture' . chr(123) . ' p : []*Any' . chr(123) . ' ' . Main::join(([ map { $_->emit_go() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ' ' . chr(125) . ' ' . chr(125) . ' )') 618 } 619 } 620 621; 622 { 623 package Return; 624 sub new { shift; bless { @_ }, "Return" } 625 sub emit_go { 626 my $self = $_[0]; 627 if (Main::isa(($self->{result}), 'Bind')) { 628 ((my $tmp) = ($self->{result})->parameters()); 629 return scalar (('(func () ' . chr(123) . ' ' . ($self->{result})->emit_go() . chr(59) . ' ' . 'p <- ' . $tmp->emit_go() . chr(59) . ' ' . 'runtime.Goexit()' . chr(59) . ' ' . chr(125) . '())')) 630 }; 631 return scalar (('(func () ' . chr(123) . ' ' . 'var tmp *Any ' . chr(61) . ' ' . ($self->{result})->emit_go() . chr(59) . ' ' . 'p <- tmp' . chr(59) . ' ' . 'runtime.Goexit()' . chr(59) . ' ' . chr(125) . '())')) 632 }; 633 sub emit_go_simple { 634 my $self = $_[0]; 635 if (Main::isa(($self->{result}), 'Bind')) { 636 ((my $tmp) = ($self->{result})->parameters()); 637 return scalar (('return (func () *Any ' . chr(123) . ' ' . ($self->{result})->emit_go() . chr(59) . ' ' . 'return ' . $tmp->emit_go() . chr(59) . ' ' . chr(125) . '())')) 638 }; 639 return scalar (('return( ' . $self->{result}->emit_go() . ')')) 640 } 641 } 642 643; 644 { 645 package If; 646 sub new { shift; bless { @_ }, "If" } 647 sub emit_go { 648 my $self = $_[0]; 649 ((my $cond) = $self->{cond}); 650 if ((Main::isa($cond, 'Apply') && ($cond->code() eq 'prefix:<' . chr(33) . '>'))) { 651 ((my $if) = If->new(('cond' => ($cond->arguments())->[0]), ('body' => (defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY')))), ('otherwise' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))))); 652 return scalar ($if->emit_go()) 653 }; 654 if ((Main::isa($cond, 'Var') && ($cond->sigil() eq chr(64)))) { 655 ($cond = Apply->new(('code' => 'prefix:<' . chr(64) . '>'), ('arguments' => do { 656 (my $List_a = bless [], 'ARRAY'); 657 (my $List_v = bless [], 'ARRAY'); 658 push( @{$List_a}, $cond ); 659 $List_a 660}))) 661 }; 662 ((my $s) = ('if tobool( ' . Call::emit_go_call($cond, 'Bool') . ' ) ' . chr(123) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))), ('needs_return' => 0)))->emit_go() . ' ' . chr(125))); 663 if (!(((defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY')))))) { 664 return scalar ($s) 665 }; 666 return scalar (($s . ' else ' . chr(123) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY')))), ('needs_return' => 0)))->emit_go() . ' ' . chr(125))) 667 } 668 } 669 670; 671 { 672 package For; 673 sub new { shift; bless { @_ }, "For" } 674 sub emit_go { 675 my $self = $_[0]; 676 ('func (a_ *Any) ' . chr(123) . ' ' . (chr(10)) . ' var i ' . chr(61) . ' (*(*a_).(array_er).f_array(Capture' . chr(123) . chr(125) . ')).(*Array)' . chr(59) . ' ' . (chr(10)) . ' for pos :' . chr(61) . ' 0' . chr(59) . ' pos <' . chr(61) . ' i.n' . chr(59) . ' pos++ ' . chr(123) . ' ' . (chr(10)) . ' func (' . $self->{topic}->emit_go() . ' *Any) ' . chr(123) . ' ' . (chr(10)) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))), ('needs_return' => 0)))->emit_go() . (chr(10)) . ' ' . chr(125) . '(i.v[pos]) ' . (chr(10)) . ' ' . chr(125) . ' ' . (chr(10)) . chr(125) . '(' . $self->{cond}->emit_go() . ')') 677 } 678 } 679 680; 681 { 682 package When; 683 sub new { shift; bless { @_ }, "When" } 684 sub emit_go { 685 my $self = $_[0]; 686 die(('TODO - When')) 687 } 688 } 689 690; 691 { 692 package While; 693 sub new { shift; bless { @_ }, "While" } 694 sub emit_go { 695 my $self = $_[0]; 696 ((my $cond) = $self->{cond}); 697 if ((Main::isa($cond, 'Var') && ($cond->sigil() eq chr(64)))) { 698 ($cond = Apply->new(('code' => 'prefix:<' . chr(64) . '>'), ('arguments' => do { 699 (my $List_a = bless [], 'ARRAY'); 700 (my $List_v = bless [], 'ARRAY'); 701 push( @{$List_a}, $cond ); 702 $List_a 703}))) 704 }; 705 return scalar (('for ' . (($self->{init} ? ($self->{init}->emit_go() . chr(59) . ' ') : chr(59))) . 'tobool( ' . Call::emit_go_call($cond, 'Bool') . ' )' . chr(59) . ' ' . (($self->{continue} ? ($self->{continue}->emit_go() . ' ') : '')) . chr(123) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))), ('needs_return' => 0)))->emit_go() . ' ' . chr(125))) 706 } 707 } 708 709; 710 { 711 package Decl; 712 sub new { shift; bless { @_ }, "Decl" } 713 sub emit_go { 714 my $self = $_[0]; 715 $self->{var}->emit_go() 716 }; 717 sub emit_go_init { 718 my $self = $_[0]; 719 if (($self->{decl} eq 'my')) { 720 ((my $str) = ''); 721 ($str = ($str . 'var ' . ($self->{var})->emit_go() . ' *Any' . chr(59) . (chr(10)))); 722 ($str = ($str . ($self->{var})->emit_go() . ' ' . chr(61) . ' ' . ($self->{var})->emit_go() . chr(59) . (chr(10)))); 723 if ((($self->{var})->sigil() eq chr(37))) { 724 ($str = ($str . ($self->{var})->emit_go() . ' ' . chr(61) . ' h_hash()' . chr(59) . (chr(10)))) 725 } 726 else { 727 if ((($self->{var})->sigil() eq chr(64))) { 728 ($str = ($str . ($self->{var})->emit_go() . ' ' . chr(61) . ' a_array()' . chr(59) . (chr(10)))) 729 } 730 else { 731 ($str = ($str . ($self->{var})->emit_go() . ' ' . chr(61) . ' u_undef()' . chr(59) . (chr(10)))) 732 } 733 }; 734 return scalar ($str) 735 } 736 else { 737 die(('not implemented: Decl ' . chr(39) . $self->{decl} . (chr(39)))) 738 } 739 } 740 } 741 742; 743 { 744 package Sig; 745 sub new { shift; bless { @_ }, "Sig" } 746 sub emit_go { 747 my $self = $_[0]; 748 '' 749 }; 750 sub emit_go_bind { 751 my $self = $_[0]; 752 ((my $str) = ''); 753 ((my $i) = 0); 754 for my $decl ( @{(($self->{positional}))} ) { 755 ($str = ($str . (' var ') . $decl->emit_go() . (' *Any' . chr(59) . chr(10)) . (' if len(v.p) > ') . $i . (' ' . chr(123) . chr(10)) . (' ') . $decl->emit_go() . (' ' . chr(61) . ' v.p[') . $i . (']' . chr(59) . chr(10)) . (' ' . chr(125) . chr(10)))); 756 ($str = ($str . $decl->emit_go() . ' ' . chr(61) . ' ' . $decl->emit_go() . chr(59) . ' ')); 757 ($i = ($i + 1)) 758 }; 759 return scalar ($str) 760 } 761 } 762 763; 764 { 765 package Method; 766 sub new { shift; bless { @_ }, "Method" } 767 sub emit_go { 768 my $self = $_[0]; 769 ((my $invocant) = ($self->{sig})->invocant()); 770 ('func ' . $self->{name} . '(v Capture) *Any ' . chr(123) . ' ' . ' ' . ($self->{sig})->emit_go_bind() . (chr(10)) . ' p :' . chr(61) . ' make(chan *Any)' . chr(59) . ' go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1), ('top_level' => 1)))->emit_go() . chr(59) . ' p <- nil ' . chr(125) . '()' . chr(59) . ' ' . (chr(10)) . ' return <-p' . chr(59) . ' ' . (chr(10)) . ' ' . chr(125)) 771 } 772 } 773 774; 775 { 776 package Sub; 777 sub new { shift; bless { @_ }, "Sub" } 778 sub emit_go { 779 my $self = $_[0]; 780 if (($self->{name} eq '')) { 781 return scalar (('toFunction( func(v Capture) *Any ' . chr(123) . ' ' . ' ' . ($self->{sig})->emit_go_bind() . (chr(10)) . ' p :' . chr(61) . ' make(chan *Any)' . chr(59) . ' go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1), ('top_level' => 1)))->emit_go() . chr(59) . ' p <- nil ' . chr(125) . '()' . chr(59) . ' ' . (chr(10)) . ' return <-p' . chr(59) . ' ' . (chr(10)) . chr(125) . ' ' . ')')) 782 }; 783 ('func ' . $self->{name} . '(v Capture) *Any ' . chr(123) . ' ' . ' ' . ($self->{sig})->emit_go_bind() . (chr(10)) . ' p :' . chr(61) . ' make(chan *Any)' . chr(59) . ' go func () ' . chr(123) . ' ' . (chr(10)) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1), ('top_level' => 1)))->emit_go() . chr(59) . ' p <- nil ' . chr(125) . '()' . chr(59) . ' ' . (chr(10)) . ' return <-p' . chr(59) . ' ' . (chr(10)) . ' ' . chr(125)) 784 } 785 } 786 787; 788 { 789 package Do; 790 sub new { shift; bless { @_ }, "Do" } 791 sub emit_go { 792 my $self = $_[0]; 793 ('(func () *Any ' . chr(123) . ' ' . (Perlito6::Go::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1)))->emit_go() . chr(59) . ' return u_undef() ' . chr(125) . ')()') 794 } 795 } 796 797; 798 { 799 package Use; 800 sub new { shift; bless { @_ }, "Use" } 801 sub emit_go { 802 my $self = $_[0]; 803 (chr(47) . chr(47) . ' use ' . $self->{mod} . (chr(10))) 804 } 805 } 806 807 808} 809 8101; 811