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 use Perlito6::AST; 17 { 18 package Python; 19 sub new { shift; bless { @_ }, "Python" } 20 sub tab { 21 my $level = $_[0]; 22 ((' ') x $level) 23 }; 24 ((my $Hash_safe_char = bless {}, 'HASH') = do { 25 (my $Hash_a = bless {}, 'HASH'); 26 ($Hash_a->{'_'} = 1); 27 ($Hash_a->{','} = 1); 28 ($Hash_a->{'.'} = 1); 29 ($Hash_a->{':'} = 1); 30 ($Hash_a->{'-'} = 1); 31 ($Hash_a->{'+'} = 1); 32 ($Hash_a->{'*'} = 1); 33 ($Hash_a->{' '} = 1); 34 ($Hash_a->{'('} = 1); 35 ($Hash_a->{')'} = 1); 36 ($Hash_a->{'<'} = 1); 37 ($Hash_a->{'>'} = 1); 38 ($Hash_a->{'['} = 1); 39 ($Hash_a->{']'} = 1); 40 $Hash_a 41}); 42 sub escape_string { 43 my $s = $_[0]; 44 (my $List_out = bless [], 'ARRAY'); 45 ((my $tmp) = ''); 46 if (($s eq '')) { 47 return scalar (('u' . chr(39) . chr(39))) 48 }; 49 for my $i ( @{(bless [0 .. (Main::chars($s, ) - 1)], 'ARRAY')} ) { 50 ((my $c) = substr($s, $i, 1)); 51 if (((((((($c ge 'a')) && (($c le 'z')))) || (((($c ge 'A')) && (($c le 'Z'))))) || (((($c ge '0')) && (($c le '9'))))) || exists($Hash_safe_char->{$c}))) { 52 ($tmp = ($tmp . $c)) 53 } 54 else { 55 if (($tmp ne '')) { 56 push( @{$List_out}, ('u' . chr(39) . $tmp . chr(39)) ) 57 }; 58 push( @{$List_out}, ('unichr(' . do { 59 ord($c) 60} . ')') ); 61 ($tmp = '') 62 } 63 }; 64 if (($tmp ne '')) { 65 push( @{$List_out}, ('u' . chr(39) . $tmp . chr(39)) ) 66 }; 67 return scalar (Main::join($List_out, ' + ')) 68 } 69 } 70 71; 72 { 73 package Perlito6::Python::AnonSub; 74 sub new { shift; bless { @_ }, "Perlito6::Python::AnonSub" } 75 sub name { $_[0]->{name} }; 76 sub sig { $_[0]->{sig} }; 77 sub block { $_[0]->{block} }; 78 sub handles_return_exception { $_[0]->{handles_return_exception} }; 79 sub emit_python { 80 my $self = $_[0]; 81 $self->emit_python_indented(0) 82 }; 83 sub emit_python_indented { 84 my $self = $_[0]; 85 my $level = $_[1]; 86 ((my $sig) = $self->{sig}); 87 ((my $pos) = $sig->positional()); 88 ((my $args) = do { 89 (my $List_a = bless [], 'ARRAY'); 90 (my $List_v = bless [], 'ARRAY'); 91 $List_a 92}); 93 for my $field ( @{($pos)} ) { 94 push( @{$args}, $field->emit_python_name() ) 95 }; 96 ((my $block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1))); 97 (my $List_s = bless [], 'ARRAY'); 98 push( @{$List_s}, (Python::tab($level) . ('def f_') . $self->{name} . ('(') . Main::join($args, (', ')) . ('):')) ); 99 if ($self->{handles_return_exception}) { 100 push( @{$List_s}, (Python::tab(($level + 1)) . ('try:')) ); 101 push( @{$List_s}, $block->emit_python_indented(($level + 2)) ); 102 push( @{$List_s}, (Python::tab(($level + 1)) . ('except mp6_Return, r:')) ); 103 push( @{$List_s}, (Python::tab(($level + 2)) . ('return r.value')) ) 104 } 105 else { 106 push( @{$List_s}, $block->emit_python_indented(($level + 1)) ) 107 }; 108 return scalar (Main::join($List_s, (chr(10)))) 109 } 110 } 111 112; 113 { 114 package Perlito6::Python::LexicalBlock; 115 sub new { shift; bless { @_ }, "Perlito6::Python::LexicalBlock" } 116 sub block { $_[0]->{block} }; 117 sub needs_return { $_[0]->{needs_return} }; 118 sub top_level { $_[0]->{top_level} }; 119 (my $ident); 120 (my $List_anon_block = bless [], 'ARRAY'); 121 sub push_stmt_python { 122 my $block = $_[0]; 123 push( @{$List_anon_block}, $block ) 124 }; 125 sub get_ident_python { 126 ($ident = ($ident + 1)); 127 return scalar ($ident) 128 }; 129 sub has_my_decl { 130 my $self = $_[0]; 131 for my $decl ( @{(defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))} ) { 132 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'my')))) { 133 return scalar (1) 134 }; 135 if ((((Main::isa($decl, 'Apply') && ($decl->code() eq 'infix:<' . chr(61) . '>')) && Main::isa($decl->arguments()->[0], 'Decl')) && ($decl->arguments()->[0]->decl() eq 'my'))) { 136 return scalar (1) 137 } 138 }; 139 return scalar (0) 140 }; 141 sub emit_python { 142 my $self = $_[0]; 143 $self->emit_python_indented(0) 144 }; 145 sub emit_python_indented { 146 my $self = $_[0]; 147 my $level = $_[1]; 148 (my $List_block = bless [], 'ARRAY'); 149 for ( @{(defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))} ) { 150 if (defined($_)) { 151 push( @{$List_block}, $_ ) 152 } 153 }; 154 if (!(($List_block))) { 155 push( @{$List_block}, Apply->new(('code' => 'Mu')) ) 156 }; 157 (my $List_s = bless [], 'ARRAY'); 158 (my $List_tmp = bless [], 'ARRAY'); 159 for my $stmt ( @{$List_anon_block} ) { 160 push( @{$List_tmp}, $stmt ) 161 }; 162 ((my $has_decl) = do { 163 (my $List_a = bless [], 'ARRAY'); 164 (my $List_v = bless [], 'ARRAY'); 165 $List_a 166}); 167 ((my $block) = do { 168 (my $List_a = bless [], 'ARRAY'); 169 (my $List_v = bless [], 'ARRAY'); 170 $List_a 171}); 172 for my $decl ( @{$List_block} ) { 173 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 174 push( @{$has_decl}, $decl ) 175 } 176 else { 177 if ((((Main::isa($decl, 'Apply') && ($decl->code() eq 'infix:<' . chr(61) . '>')) && Main::isa($decl->arguments()->[0], 'Decl')) && ($decl->arguments()->[0]->decl() eq 'has'))) { 178 push( @{$has_decl}, $decl ) 179 } 180 else { 181 push( @{(($block))}, $decl ) 182 } 183 } 184 }; 185 if ((($has_decl))) { 186 for my $decl ( @{(($has_decl))} ) { 187 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'has')))) { 188 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 189 push( @{$List_s}, (Python::tab($level) . 'def f_' . $label . '(v_self):') ); 190 push( @{$List_s}, (Python::tab(($level + 1)) . 'return v_self.v_' . ($decl->var())->name()) ); 191 push( @{$List_s}, (Python::tab($level) . ('self.__dict__.update(' . chr(123) . chr(39) . 'f_') . $decl->var()->name() . (chr(39) . ':f_') . $label . (chr(125) . ')')) ) 192 }; 193 if ((((Main::isa($decl, 'Apply') && ($decl->code() eq 'infix:<' . chr(61) . '>')) && Main::isa($decl->arguments()->[0], 'Decl')) && ($decl->arguments()->[0]->decl() eq 'has'))) { 194 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 195 push( @{$List_s}, (Python::tab($level) . 'def f_' . $label . '(v_self):') ); 196 push( @{$List_s}, (Python::tab(($level + 1)) . 'return v_self.v_' . $decl->arguments()->[0]->var()->name()) ); 197 push( @{$List_s}, (Python::tab($level) . ('self.__dict__.update(' . chr(123) . chr(39) . 'f_') . $decl->arguments()->[0]->var()->name() . (chr(39) . ':f_') . $label . (chr(125) . ')')) ) 198 } 199 } 200 }; 201 for my $decl ( @{(($block))} ) { 202 if ((Main::isa($decl, 'Decl') && (($decl->decl() eq 'my')))) { 203 push( @{$List_s}, (Python::tab($level) . ($decl->var())->emit_python_name() . ' ' . chr(61) . ' ' . $decl->emit_python_init() . '') ) 204 } 205 else { 206 if ((((Main::isa($decl, 'Apply') && ($decl->code() eq 'infix:<' . chr(61) . '>')) && Main::isa($decl->arguments()->[0], 'Decl')) && ($decl->arguments()->[0]->decl() eq 'my'))) { 207 push( @{$List_s}, (Python::tab($level) . $decl->arguments()->[0]->var()->emit_python_name() . ' ' . chr(61) . ' ' . $decl->arguments()->[0]->emit_python_init() . '') ) 208 } 209 } 210 }; 211 (my $last_statement); 212 if ($self->{needs_return}) { 213 ($last_statement = pop( @{(($block))} )) 214 }; 215 for my $stmt ( @{(($block))} ) { 216 ($List_anon_block = do { 217 (my $List_a = bless [], 'ARRAY'); 218 (my $List_v = bless [], 'ARRAY'); 219 $List_a 220}); 221 ((my $s2) = $stmt->emit_python_indented($level)); 222 for my $stmt ( @{$List_anon_block} ) { 223 push( @{$List_s}, $stmt->emit_python_indented($level) ) 224 }; 225 push( @{$List_s}, $s2 ) 226 }; 227 if (($self->{needs_return} && $last_statement)) { 228 ($List_anon_block = do { 229 (my $List_a = bless [], 'ARRAY'); 230 (my $List_v = bless [], 'ARRAY'); 231 $List_a 232}); 233 (my $s2); 234 if (Main::isa($last_statement, 'If')) { 235 ((my $cond) = $last_statement->cond()); 236 ((my $has_otherwise) = ($last_statement->otherwise() ? 1 : 0)); 237 ($s2 = (Python::tab($level) . 'if mp6_to_bool(' . $cond->emit_python() . ('):' . chr(10)))); 238 ((my $body_block) = Perlito6::Python::LexicalBlock->new(('block' => ($last_statement->body()->stmts())), ('needs_return' => 1))); 239 if ($body_block->has_my_decl()) { 240 ($body_block = Do->new(('block' => ($last_statement->body())))); 241 ($s2 = ($s2 . Python::tab(($level + 1)) . 'return ' . $body_block->emit_python())) 242 } 243 else { 244 ($s2 = ($s2 . $body_block->emit_python_indented(($level + 1)))) 245 }; 246 if (($has_otherwise)) { 247 ($s2 = ($s2 . (chr(10)) . Python::tab($level) . ('else:' . chr(10)))); 248 ((my $otherwise_block) = Perlito6::Python::LexicalBlock->new(('block' => ($last_statement->otherwise()->stmts())), ('needs_return' => 1))); 249 if ($otherwise_block->has_my_decl()) { 250 ($otherwise_block = Do->new(('block' => ($last_statement->otherwise())))); 251 ($s2 = ($s2 . Python::tab(($level + 1)) . 'return ' . $otherwise_block->emit_python())) 252 } 253 else { 254 ($s2 = ($s2 . $otherwise_block->emit_python_indented(($level + 1)))) 255 } 256 } 257 } 258 else { 259 if ((Main::isa($last_statement, 'Apply') && ($last_statement->code() eq 'infix:<' . chr(61) . '>'))) { 260 ($s2 = $last_statement->emit_python_indented($level)); 261 ($s2 = ($s2 . (chr(10)) . Python::tab($level) . ('return ') . $last_statement->arguments()->[0]->emit_python())) 262 } 263 else { 264 if (((Main::isa($last_statement, 'Apply') && ($last_statement->code() eq 'return')) || Main::isa($last_statement, 'For'))) { 265 ($s2 = $last_statement->emit_python_indented($level)) 266 } 267 else { 268 ($s2 = (Python::tab($level) . ('return ') . $last_statement->emit_python())) 269 } 270 } 271 }; 272 for my $stmt ( @{$List_anon_block} ) { 273 push( @{$List_s}, $stmt->emit_python_indented($level) ) 274 }; 275 push( @{$List_s}, $s2 ) 276 }; 277 ($List_anon_block = $List_tmp); 278 return scalar (Main::join($List_s, (chr(10)))) 279 } 280 } 281 282; 283 { 284 package CompUnit; 285 sub new { shift; bless { @_ }, "CompUnit" } 286 sub attributes { $_[0]->{attributes} }; 287 sub methods { $_[0]->{methods} }; 288 sub emit_python { 289 my $self = $_[0]; 290 $self->emit_python_indented(0) 291 }; 292 sub emit_python_indented { 293 my $self = $_[0]; 294 my $level = $_[1]; 295 (my $List_s = bless [], 'ARRAY'); 296 ((my $block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))))); 297 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 298 ((my $name) = Main::to_go_namespace($self->{name})); 299 for my $decl ( @{(defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))} ) { 300 if (Main::isa($decl, 'Use')) { 301 if (($decl->mod() ne 'v6')) { 302 push( @{$List_s}, (Python::tab($level) . 'import ' . Main::to_go_namespace($decl->mod())) ) 303 } 304 } 305 }; 306 push( @{$List_s}, (Python::tab($level) . 'try:') ); 307 push( @{$List_s}, (Python::tab(($level + 1)) . 'type(' . $name . (')')) ); 308 push( @{$List_s}, (Python::tab($level) . 'except NameError:') ); 309 push( @{$List_s}, (Python::tab(($level + 1)) . 'class ' . $name . (':')) ); 310 push( @{$List_s}, (Python::tab(($level + 2)) . ('def __init__(self, **arg):')) ); 311 push( @{$List_s}, (Python::tab(($level + 3)) . ('for k in arg:')) ); 312 push( @{$List_s}, (Python::tab(($level + 4)) . ('self.__dict__[k] ' . chr(61) . ' mp6_Scalar()')) ); 313 push( @{$List_s}, (Python::tab(($level + 4)) . ('self.__dict__[k].f_set(arg[k])')) ); 314 push( @{$List_s}, (Python::tab(($level + 2)) . ('def f__setattr__(self, k, v):')) ); 315 push( @{$List_s}, (Python::tab(($level + 3)) . ('return self.__dict__[k].f_set(v)')) ); 316 push( @{$List_s}, (Python::tab(($level + 2)) . ('def f_isa(self, name):')) ); 317 push( @{$List_s}, (Python::tab(($level + 3)) . ('return name ' . chr(61) . chr(61) . ' u' . chr(39)) . $self->{name} . (chr(39))) ); 318 push( @{$List_s}, (Python::tab(($level + 2)) . ('def f_bool(self):')) ); 319 push( @{$List_s}, (Python::tab(($level + 3)) . ('return 1')) ); 320 push( @{$List_s}, (Python::tab(($level + 2)) . ('def __getattr__(self, attr):')) ); 321 push( @{$List_s}, (Python::tab(($level + 3)) . ('if attr[0:2] ' . chr(61) . chr(61) . ' u' . chr(39) . 'v_' . chr(39) . ':')) ); 322 push( @{$List_s}, (Python::tab(($level + 4)) . ('self.__dict__[attr] ' . chr(61) . ' mp6_Scalar()')) ); 323 push( @{$List_s}, (Python::tab(($level + 4)) . ('return self.__dict__[attr]')) ); 324 push( @{$List_s}, (Python::tab(($level + 3)) . ('raise AttributeError(attr)')) ); 325 push( @{$List_s}, (Python::tab(($level + 1)) . $name . ('_proto ' . chr(61) . ' ') . $name . ('()')) ); 326 push( @{$List_s}, (Python::tab(($level + 1)) . ('__builtin__.') . $name . (' ' . chr(61) . ' ') . $name . '') ); 327 push( @{$List_s}, (Python::tab(($level + 1)) . ('__builtin__.') . $name . ('_proto ' . chr(61) . ' ') . $name . ('_proto')) ); 328 if (($name eq 'GLOBAL')) { 329 push( @{$List_s}, (Python::tab($level) . 'self ' . chr(61) . ' ' . $name) ); 330 push( @{$List_s}, $block->emit_python_indented($level) ) 331 } 332 else { 333 push( @{$List_s}, (Python::tab($level) . 'def ' . $label . ('():')) ); 334 push( @{$List_s}, (Python::tab(($level + 1)) . 'self ' . chr(61) . ' ' . $name) ); 335 push( @{$List_s}, $block->emit_python_indented(($level + 1)) ); 336 push( @{$List_s}, (Python::tab($level) . $label . ('()')) ) 337 }; 338 return scalar (Main::join($List_s, (chr(10)))) 339 } 340 } 341 342; 343 { 344 package Val::Int; 345 sub new { shift; bless { @_ }, "Val::Int" } 346 sub emit_python { 347 my $self = $_[0]; 348 $self->{int} 349 }; 350 sub emit_python_indented { 351 my $self = $_[0]; 352 my $level = $_[1]; 353 (Python::tab($level) . $self->{int}) 354 } 355 } 356 357; 358 { 359 package Val::Bit; 360 sub new { shift; bless { @_ }, "Val::Bit" } 361 sub emit_python { 362 my $self = $_[0]; 363 $self->{bit} 364 }; 365 sub emit_python_indented { 366 my $self = $_[0]; 367 my $level = $_[1]; 368 (Python::tab($level) . $self->{bit}) 369 } 370 } 371 372; 373 { 374 package Val::Num; 375 sub new { shift; bless { @_ }, "Val::Num" } 376 sub emit_python { 377 my $self = $_[0]; 378 $self->{num} 379 }; 380 sub emit_python_indented { 381 my $self = $_[0]; 382 my $level = $_[1]; 383 (Python::tab($level) . $self->{num}) 384 } 385 } 386 387; 388 { 389 package Val::Buf; 390 sub new { shift; bless { @_ }, "Val::Buf" } 391 sub emit_python { 392 my $self = $_[0]; 393 $self->emit_python_indented(0) 394 }; 395 sub emit_python_indented { 396 my $self = $_[0]; 397 my $level = $_[1]; 398 (Python::tab($level) . Python::escape_string($self->{buf})) 399 } 400 } 401 402; 403 { 404 package Lit::Block; 405 sub new { shift; bless { @_ }, "Lit::Block" } 406 sub emit_python { 407 my $self = $_[0]; 408 $self->emit_python_indented(0) 409 }; 410 sub emit_python_indented { 411 my $self = $_[0]; 412 my $level = $_[1]; 413 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 414 ((my $anon_var) = ($self->{sig} || Var->new(('name' => '_'), ('namespace' => ''), ('sigil' => chr(36)), ('twigil' => '')))); 415 ((my $anon_sig) = Sig->new(('invocant' => undef()), ('positional' => do { 416 (my $List_a = bless [], 'ARRAY'); 417 (my $List_v = bless [], 'ARRAY'); 418 push( @{$List_a}, $anon_var ); 419 $List_a 420}), ('named' => do { 421 (my $Hash_a = bless {}, 'HASH'); 422 $Hash_a 423}))); 424 Perlito6::Python::LexicalBlock::push_stmt_python(Perlito6::Python::AnonSub->new(('name' => $label), ('block' => (defined $self->{stmts} ? $self->{stmts} : ($self->{stmts} ||= bless([], 'ARRAY')))), ('sig' => $anon_sig), ('handles_return_exception' => 0))); 425 return scalar ((Python::tab($level) . ('f_') . $label . '')) 426 } 427 } 428 429; 430 { 431 package Lit::Array; 432 sub new { shift; bless { @_ }, "Lit::Array" } 433 sub emit_python { 434 my $self = $_[0]; 435 $self->emit_python_indented(0) 436 }; 437 sub emit_python_indented { 438 my $self = $_[0]; 439 my $level = $_[1]; 440 ((my $ast) = $self->expand_interpolation()); 441 return scalar ($ast->emit_python_indented($level)) 442 } 443 } 444 445; 446 { 447 package Lit::Hash; 448 sub new { shift; bless { @_ }, "Lit::Hash" } 449 sub emit_python { 450 my $self = $_[0]; 451 $self->emit_python_indented(0) 452 }; 453 sub emit_python_indented { 454 my $self = $_[0]; 455 my $level = $_[1]; 456 ((my $ast) = $self->expand_interpolation()); 457 return scalar ($ast->emit_python_indented($level)) 458 } 459 } 460 461; 462 { 463 package Index; 464 sub new { shift; bless { @_ }, "Index" } 465 sub emit_python { 466 my $self = $_[0]; 467 $self->emit_python_indented(0) 468 }; 469 sub emit_python_indented { 470 my $self = $_[0]; 471 my $level = $_[1]; 472 (Python::tab($level) . $self->{obj}->emit_python() . '.f_index(' . $self->{index_exp}->emit_python() . ')') 473 } 474 } 475 476; 477 { 478 package Lookup; 479 sub new { shift; bless { @_ }, "Lookup" } 480 sub emit_python { 481 my $self = $_[0]; 482 $self->emit_python_indented(0) 483 }; 484 sub emit_python_indented { 485 my $self = $_[0]; 486 my $level = $_[1]; 487 (Python::tab($level) . $self->{obj}->emit_python() . '.f_lookup(' . $self->{index_exp}->emit_python() . ')') 488 } 489 } 490 491; 492 { 493 package Var; 494 sub new { shift; bless { @_ }, "Var" } 495 ((my $table) = do { 496 (my $Hash_a = bless {}, 'HASH'); 497 ($Hash_a->{chr(36)} = 'v_'); 498 ($Hash_a->{chr(64)} = 'List_'); 499 ($Hash_a->{chr(37)} = 'Hash_'); 500 ($Hash_a->{chr(38)} = 'Code_'); 501 $Hash_a 502}); 503 sub emit_python { 504 my $self = $_[0]; 505 $self->emit_python_indented(0) 506 }; 507 sub emit_python_indented { 508 my $self = $_[0]; 509 my $level = $_[1]; 510 return scalar ((Python::tab($level) . (((($self->{twigil} eq '.')) ? (('v_self.v_' . $self->{name} . '')) : (((($self->{name} eq chr(47))) ? (($table->{$self->{sigil}} . 'MATCH')) : (($table->{$self->{sigil}} . $self->{name} . '')))))))) 511 }; 512 sub emit_python_name { 513 my $self = $_[0]; 514 return scalar ((((($self->{twigil} eq '.')) ? (('v_self.v_' . $self->{name})) : (((($self->{name} eq chr(47))) ? (($table->{$self->{sigil}} . 'MATCH')) : (($table->{$self->{sigil}} . $self->{name}))))))) 515 } 516 } 517 518; 519 { 520 package Proto; 521 sub new { shift; bless { @_ }, "Proto" } 522 sub emit_python { 523 my $self = $_[0]; 524 $self->emit_python_indented(0) 525 }; 526 sub emit_python_indented { 527 my $self = $_[0]; 528 my $level = $_[1]; 529 if (($self->{name} eq 'self')) { 530 return scalar ((Python::tab($level) . 'v_self')) 531 }; 532 (Python::tab($level) . Main::to_go_namespace($self->{name}) . '_proto') 533 } 534 } 535 536; 537 { 538 package Call; 539 sub new { shift; bless { @_ }, "Call" } 540 ((my $Hash_method_python = bless {}, 'HASH') = do { 541 (my $Hash_a = bless {}, 'HASH'); 542 ($Hash_a->{'id'} = 'id'); 543 ($Hash_a->{'yaml'} = 'yaml'); 544 ($Hash_a->{'join'} = 'join'); 545 ($Hash_a->{'split'} = 'split'); 546 ($Hash_a->{'isa'} = 'isa'); 547 ($Hash_a->{'say'} = 'say'); 548 $Hash_a 549}); 550 sub emit_python { 551 my $self = $_[0]; 552 $self->emit_python_indented(0) 553 }; 554 sub emit_python_indented { 555 my $self = $_[0]; 556 my $level = $_[1]; 557 ((my $invocant) = $self->{invocant}->emit_python()); 558 if (($self->{method} eq 'new')) { 559 (my $List_str = bless [], 'ARRAY'); 560 for my $field ( @{(defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))} ) { 561 if ((Main::isa($field, 'Apply') && ($field->code() eq 'infix:<' . chr(61) . '>>'))) { 562 push( @{$List_str}, ('v_' . $field->arguments()->[0]->buf() . chr(61) . $field->arguments()->[1]->emit_python()) ) 563 } 564 else { 565 die('Error in constructor, field: ', Main::perl($field, )) 566 } 567 }; 568 return scalar ((Python::tab($level) . '__builtin__.' . Main::to_go_namespace($self->{invocant}->name()) . '(' . Main::join($List_str, ', ') . ')')) 569 }; 570 if (exists($Hash_method_python->{$self->{method}})) { 571 if (($self->{hyper})) { 572 return scalar ((Python::tab($level) . 'f_map(' . $invocant . ', lambda x: Main.' . $self->{method} . '(x, ' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . '))')) 573 } 574 else { 575 return scalar ((Python::tab($level) . ('f_') . $self->{method} . '(' . $invocant . ', ' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 576 } 577 }; 578 ((my $meth) = $self->{method}); 579 if (($meth eq 'postcircumfix:<( )>')) { 580 return scalar ((Python::tab($level) . $invocant . '(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 581 }; 582 if (((($meth eq 'values')) || (($meth eq 'keys')))) { 583 return scalar ((Python::tab($level) . $invocant . '.' . $meth . '(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 584 }; 585 if (($meth eq 'chars')) { 586 return scalar ((Python::tab($level) . ('len(') . $invocant . (')'))) 587 }; 588 ((my $call) = ('f_' . $meth . '(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')); 589 if (($self->{hyper})) { 590 return scalar ((Python::tab($level) . 'f_map(' . $invocant . ', lambda x: x.' . $call . ')')) 591 } 592 else { 593 return scalar ((Python::tab($level) . $invocant . '.' . $call)) 594 } 595 } 596 } 597 598; 599 { 600 package Apply; 601 sub new { shift; bless { @_ }, "Apply" } 602 sub emit_python_indented { 603 my $self = $_[0]; 604 my $level = $_[1]; 605 (Python::tab($level) . $self->emit_python()) 606 }; 607 sub emit_python { 608 my $self = $_[0]; 609 ((my $apply) = $self->op_assign()); 610 if ($apply) { 611 return scalar ($apply->emit_python()) 612 }; 613 ((my $code) = $self->{code}); 614 if (Main::isa(((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]), 'Apply')) { 615 ((my $args2) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]->arguments()); 616 if ((Main::isa(($args2->[0]), 'Apply') && ((($args2->[0]->code() eq 'infix:<or>') || ($args2->[0]->code() eq 'infix:<' . chr(124) . chr(124) . '>'))))) { 617 ($args2->[0] = Do->new(('block' => $args2->[0]))) 618 } 619 }; 620 if (Main::isa(((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]), 'Apply')) { 621 ((my $args2) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]->arguments()); 622 if ((Main::isa(($args2->[1]), 'Apply') && ($args2->[1]->code() ne 'infix:<' . chr(61) . '>>'))) { 623 ($args2->[1] = Do->new(('block' => $args2->[1]))) 624 } 625 }; 626 if (Main::isa(((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1]), 'Apply')) { 627 ((my $args2) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1]->arguments()); 628 if ((Main::isa(($args2->[1]), 'Apply') && ($args2->[1]->code() ne 'infix:<' . chr(61) . '>>'))) { 629 ($args2->[1] = Do->new(('block' => $args2->[1]))) 630 } 631 }; 632 if (Main::isa($code, 'Str')) { 633 634 } 635 else { 636 return scalar (('(' . $self->{code}->emit_python() . ').(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 637 }; 638 if (($code eq 'self')) { 639 return scalar ('v_self') 640 }; 641 if (($code eq 'Mu')) { 642 return scalar ('mp6_Mu()') 643 }; 644 if (($code eq 'make')) { 645 return scalar (('v_MATCH.f__setattr__(' . chr(39) . 'v_capture' . chr(39) . ', ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ')')) 646 }; 647 if (($code eq 'False')) { 648 return scalar ('False') 649 }; 650 if (($code eq 'True')) { 651 return scalar ('True') 652 }; 653 if (($code eq 'array')) { 654 return scalar (('[' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . ']')) 655 }; 656 if (($code eq 'Int')) { 657 return scalar (('mp6_to_num(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ')')) 658 }; 659 if (($code eq 'Num')) { 660 return scalar (('mp6_to_num(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ')')) 661 }; 662 if (($code eq 'prefix:<' . chr(126) . '>')) { 663 return scalar (('unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . ')')) 664 }; 665 if (($code eq 'prefix:<' . chr(33) . '>')) { 666 return scalar (('not mp6_to_bool(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . ')')) 667 }; 668 if (($code eq 'prefix:<' . chr(63) . '>')) { 669 return scalar (('not (not mp6_to_bool(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . '))')) 670 }; 671 if (($code eq 'prefix:<' . chr(36) . '>')) { 672 return scalar (('mp6_to_scalar(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . ')')) 673 }; 674 if (($code eq 'prefix:<' . chr(64) . '>')) { 675 return scalar (('(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . ')')) 676 }; 677 if (($code eq 'prefix:<' . chr(37) . '>')) { 678 return scalar ((chr(37) . chr(123) . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ') . chr(125))) 679 }; 680 if (($code eq 'infix:<x>')) { 681 return scalar (('(unicode(' . (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]->emit_python() . ')' . ' * mp6_to_num(' . (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1]->emit_python() . '))')) 682 }; 683 if (($code eq 'list:<' . chr(126) . '>')) { 684 return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') + unicode(') . '))')) 685 }; 686 if (($code eq 'infix:<+>')) { 687 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') + mp6_to_num(') . '))')) 688 }; 689 if (($code eq 'infix:<->')) { 690 return scalar (('(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' - ') . ')')) 691 }; 692 if (($code eq 'infix:<*>')) { 693 return scalar (('(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' * ') . ')')) 694 }; 695 if (($code eq 'infix:<' . chr(47) . '>')) { 696 return scalar (('(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ' ' . chr(47) . ' ') . ')')) 697 }; 698 if ((($code eq 'infix:<' . chr(38) . chr(38) . '>') || ($code eq 'infix:<and>'))) { 699 return scalar (('mp6_and(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ', lambda: ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 700 }; 701 if ((($code eq 'infix:<' . chr(124) . chr(124) . '>') || ($code eq 'infix:<or>'))) { 702 return scalar (('mp6_or(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ', lambda: ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 703 }; 704 if (($code eq 'infix:<' . chr(47) . chr(47) . '>')) { 705 return scalar (('mp6_defined_or(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ', lambda: ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 706 }; 707 if (($code eq 'infix:<eq>')) { 708 return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') ' . chr(61) . chr(61) . ' unicode(') . '))')) 709 }; 710 if (($code eq 'infix:<ne>')) { 711 return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') ' . chr(33) . chr(61) . ' unicode(') . '))')) 712 }; 713 if (($code eq 'infix:<ge>')) { 714 return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') >' . chr(61) . ' unicode(') . '))')) 715 }; 716 if (($code eq 'infix:<le>')) { 717 return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') <' . chr(61) . ' unicode(') . '))')) 718 }; 719 if (($code eq 'infix:<' . chr(61) . chr(61) . '>')) { 720 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') ' . chr(61) . chr(61) . ' mp6_to_num(') . '))')) 721 }; 722 if (($code eq 'infix:<' . chr(33) . chr(61) . '>')) { 723 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') ' . chr(33) . chr(61) . ' mp6_to_num(') . '))')) 724 }; 725 if (($code eq 'infix:<<>')) { 726 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') < mp6_to_num(') . '))')) 727 }; 728 if (($code eq 'infix:<>>')) { 729 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') > mp6_to_num(') . '))')) 730 }; 731 if (($code eq 'infix:<<' . chr(61) . '>')) { 732 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') <' . chr(61) . ' mp6_to_num(') . '))')) 733 }; 734 if (($code eq 'infix:<>' . chr(61) . '>')) { 735 return scalar (('(mp6_to_num(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ') >' . chr(61) . ' mp6_to_num(') . '))')) 736 }; 737 if (($code eq 'infix:<..>')) { 738 return scalar (('mp6_Array(range(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ', 1 + ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . '))')) 739 }; 740 if (($code eq 'infix:<' . chr(61) . chr(61) . chr(61) . '>')) { 741 return scalar (('(f_id(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ') ' . chr(61) . chr(61) . ' f_id(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . '))')) 742 }; 743 if (($code eq 'exists')) { 744 ((my $arg) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]); 745 if (Main::isa($arg, 'Lookup')) { 746 return scalar (('(' . ($arg->obj())->emit_python() . ').has_key(' . ($arg->index_exp())->emit_python() . ')')) 747 } 748 }; 749 if (($code eq 'ternary:<' . chr(63) . chr(63) . ' ' . chr(33) . chr(33) . '>')) { 750 ((my $ast) = Do->new(('block' => If->new(('cond' => ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])), ('body' => Lit::Block->new(('stmts' => do { 751 (my $List_a = bless [], 'ARRAY'); 752 (my $List_v = bless [], 'ARRAY'); 753 push( @{$List_a}, (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1] ); 754 $List_a 755}))), ('otherwise' => Lit::Block->new(('stmts' => do { 756 (my $List_a = bless [], 'ARRAY'); 757 (my $List_v = bless [], 'ARRAY'); 758 push( @{$List_a}, (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[2] ); 759 $List_a 760}))))))); 761 return scalar ($ast->emit_python()) 762 }; 763 if (($code eq 'circumfix:<( )>')) { 764 return scalar (('(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 765 }; 766 if (($code eq 'infix:<' . chr(61) . '>')) { 767 return scalar (emit_python_bind((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0], (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])) 768 }; 769 if (($code eq 'return')) { 770 return scalar (('raise mp6_Return(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 771 }; 772 if (($code eq 'substr')) { 773 return scalar ((((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . '[' . 'mp6_to_num(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')' . ':' . ((defined((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[2]) ? ('mp6_to_num(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ') ' . '+ mp6_to_num(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[2])->emit_python() . ')') : '')) . ']')) 774 }; 775 if (($code eq 'index')) { 776 return scalar (('mp6_index(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . ', ' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 777 }; 778 if (($code eq 'defined')) { 779 return scalar (('not f_isa(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . (',' . chr(39) . 'Mu' . chr(39) . ')'))) 780 }; 781 if (($code eq 'shift')) { 782 return scalar ((((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . '.f_shift()')) 783 }; 784 if (($code eq 'pop')) { 785 return scalar ((((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . '.f_pop()')) 786 }; 787 if (($code eq 'push')) { 788 return scalar ((((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . '.f_push(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 789 }; 790 if (($code eq 'unshift')) { 791 return scalar ((((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0])->emit_python() . '.f_unshift(' . ((defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[1])->emit_python() . ')')) 792 }; 793 if ($self->{namespace}) { 794 return scalar ((Main::to_go_namespace($self->{namespace}) . '_proto.f_' . $self->{code} . '(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')')) 795 }; 796 ('f_' . $self->{code} . '(' . Main::join(([ map { $_->emit_python() } @{( (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY'))) )} ]), ', ') . ')') 797 }; 798 sub emit_python_indented { 799 my $self = $_[0]; 800 my $level = $_[1]; 801 (Python::tab($level) . $self->emit_python()) 802 }; 803 sub emit_python_bind { 804 my $parameters = $_[0]; 805 my $arguments = $_[1]; 806 if (Main::isa($parameters, 'Call')) { 807 return scalar ((($parameters->invocant())->emit_python() . ('.f__setattr__(' . chr(39) . 'v_') . $parameters->method() . (chr(39) . ', ') . $arguments->emit_python() . (')'))) 808 }; 809 if (((Main::isa($parameters, 'Var') && ($parameters->sigil() eq chr(64))) || (Main::isa($parameters, 'Decl') && ($parameters->var()->sigil() eq chr(64))))) { 810 ($arguments = Lit::Array->new(('array1' => do { 811 (my $List_a = bless [], 'ARRAY'); 812 (my $List_v = bless [], 'ARRAY'); 813 push( @{$List_a}, $arguments ); 814 $List_a 815}))) 816 } 817 else { 818 if (((Main::isa($parameters, 'Var') && ($parameters->sigil() eq chr(37))) || (Main::isa($parameters, 'Decl') && ($parameters->var()->sigil() eq chr(37))))) { 819 ($arguments = Lit::Hash->new(('hash1' => do { 820 (my $List_a = bless [], 'ARRAY'); 821 (my $List_v = bless [], 'ARRAY'); 822 push( @{$List_a}, $arguments ); 823 $List_a 824}))) 825 } 826 }; 827 return scalar (($parameters->emit_python() . '.f_set(' . $arguments->emit_python() . ')')) 828 } 829 } 830 831; 832 { 833 package If; 834 sub new { shift; bless { @_ }, "If" } 835 sub emit_python { 836 my $self = $_[0]; 837 $self->emit_python_indented(0) 838 }; 839 sub emit_python_indented { 840 my $self = $_[0]; 841 my $level = $_[1]; 842 ((my $has_body) = ((defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY'))) ? 1 : 0)); 843 ((my $has_otherwise) = ((defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY'))) ? 1 : 0)); 844 ((my $body_block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))->stmts()))); 845 if ($body_block->has_my_decl()) { 846 ($body_block = Do->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))))) 847 }; 848 ((my $s) = (Python::tab($level) . 'if mp6_to_bool(' . $self->{cond}->emit_python() . ('):' . chr(10)) . $body_block->emit_python_indented(($level + 1)))); 849 if (($has_otherwise)) { 850 ((my $otherwise_block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY')))->stmts()))); 851 if ($otherwise_block->has_my_decl()) { 852 ($otherwise_block = Do->new(('block' => (defined $self->{otherwise} ? $self->{otherwise} : ($self->{otherwise} ||= bless([], 'ARRAY')))))) 853 }; 854 ($s = ($s . (chr(10)) . Python::tab($level) . ('else:' . chr(10)) . $otherwise_block->emit_python_indented(($level + 1)))) 855 }; 856 return scalar ($s) 857 } 858 } 859 860; 861 { 862 package While; 863 sub new { shift; bless { @_ }, "While" } 864 sub emit_python { 865 my $self = $_[0]; 866 $self->emit_python_indented(0) 867 }; 868 sub emit_python_indented { 869 my $self = $_[0]; 870 my $level = $_[1]; 871 ((my $body_block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))->stmts()))); 872 if ($body_block->has_my_decl()) { 873 ($body_block = Do->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))))) 874 }; 875 if (($self->{init} && $self->{continue})) { 876 die(('not implemented (While)')) 877 }; 878 (Python::tab($level) . 'while mp6_to_bool(' . $self->{cond}->emit_python() . ('):' . chr(10)) . $body_block->emit_python_indented(($level + 1))) 879 } 880 } 881 882; 883 { 884 package For; 885 sub new { shift; bless { @_ }, "For" } 886 sub emit_python { 887 my $self = $_[0]; 888 $self->emit_python_indented(0) 889 }; 890 sub emit_python_indented { 891 my $self = $_[0]; 892 my $level = $_[1]; 893 ((my $body_block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))->stmts()))); 894 ((my $sig) = 'v__'); 895 if ($self->{body}->sig()) { 896 ($sig = $self->{body}->sig()->emit_python_name()) 897 }; 898 if ($body_block->has_my_decl()) { 899 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 900 ((my $anon_var) = ($self->{body}->sig() || Var->new(('name' => '_'), ('namespace' => ''), ('sigil' => chr(36)), ('twigil' => '')))); 901 ((my $anon_sig) = Sig->new(('invocant' => undef()), ('positional' => do { 902 (my $List_a = bless [], 'ARRAY'); 903 (my $List_v = bless [], 'ARRAY'); 904 push( @{$List_a}, $anon_var ); 905 $List_a 906}), ('named' => do { 907 (my $Hash_a = bless {}, 'HASH'); 908 $Hash_a 909}))); 910 Perlito6::Python::LexicalBlock::push_stmt_python(Perlito6::Python::AnonSub->new(('name' => $label), ('block' => (defined $self->{body} ? $self->{body} : ($self->{body} ||= bless([], 'ARRAY')))->stmts()), ('sig' => $anon_sig), ('handles_return_exception' => 0))); 911 return scalar ((Python::tab($level) . 'for ' . $sig . (' in ') . $self->{cond}->emit_python() . (':' . chr(10)) . Python::tab(($level + 1)) . ('f_') . $label . ('(') . $sig . (')'))) 912 }; 913 (Python::tab($level) . 'for ' . $sig . (' in ') . $self->{cond}->emit_python() . (':' . chr(10)) . $body_block->emit_python_indented(($level + 1))) 914 } 915 } 916 917; 918 { 919 package Decl; 920 sub new { shift; bless { @_ }, "Decl" } 921 sub emit_python { 922 my $self = $_[0]; 923 $self->emit_python_indented(0) 924 }; 925 sub emit_python_indented { 926 my $self = $_[0]; 927 my $level = $_[1]; 928 ((my $decl) = $self->{decl}); 929 ((my $name) = $self->{var}->name()); 930 (Python::tab($level) . (((($decl eq 'has')) ? ('') : $self->{var}->emit_python()))) 931 }; 932 sub emit_python_init { 933 my $self = $_[0]; 934 if ((($self->{var})->sigil() eq chr(37))) { 935 return scalar ('mp6_Hash(' . chr(123) . chr(125) . ')') 936 } 937 else { 938 if ((($self->{var})->sigil() eq chr(64))) { 939 return scalar ('mp6_Array([])') 940 } 941 else { 942 return scalar ('mp6_Scalar()') 943 } 944 }; 945 return scalar ('') 946 } 947 } 948 949; 950 { 951 package Method; 952 sub new { shift; bless { @_ }, "Method" } 953 sub emit_python { 954 my $self = $_[0]; 955 $self->emit_python_indented(0) 956 }; 957 sub emit_python_indented { 958 my $self = $_[0]; 959 my $level = $_[1]; 960 ((my $sig) = $self->{sig}); 961 ((my $invocant) = $sig->invocant()); 962 ((my $pos) = $sig->positional()); 963 ((my $args) = do { 964 (my $List_a = bless [], 'ARRAY'); 965 (my $List_v = bless [], 'ARRAY'); 966 $List_a 967}); 968 ((my $default_args) = do { 969 (my $List_a = bless [], 'ARRAY'); 970 (my $List_v = bless [], 'ARRAY'); 971 $List_a 972}); 973 ((my $meth_args) = do { 974 (my $List_a = bless [], 'ARRAY'); 975 (my $List_v = bless [], 'ARRAY'); 976 $List_a 977}); 978 push( @{$meth_args}, $invocant->emit_python_name() ); 979 for my $field ( @{($pos)} ) { 980 ((my $arg) = $field->emit_python_name()); 981 push( @{$args}, $arg ); 982 push( @{$default_args}, ($arg . chr(61) . 'mp6_Scalar()') ); 983 push( @{$meth_args}, ($arg . chr(61) . 'mp6_Scalar()') ) 984 }; 985 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 986 ((my $block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1))); 987 (my $List_s = bless [], 'ARRAY'); 988 push( @{$List_s}, (Python::tab($level) . 'def f_' . $label . ('(') . Main::join($meth_args, (', ')) . ('):')) ); 989 push( @{$List_s}, (Python::tab(($level + 1)) . ('try:')) ); 990 push( @{$List_s}, $block->emit_python_indented(($level + 2)) ); 991 push( @{$List_s}, (Python::tab(($level + 1)) . ('except mp6_Return, r:')) ); 992 push( @{$List_s}, (Python::tab(($level + 2)) . ('return r.value')) ); 993 push( @{$List_s}, (Python::tab($level) . ('self.__dict__.update(' . chr(123) . chr(39) . 'f_') . $self->{name} . (chr(39) . ':f_') . $label . (chr(125) . ')')) ); 994 return scalar (Main::join($List_s, (chr(10)))) 995 } 996 } 997 998; 999 { 1000 package Sub; 1001 sub new { shift; bless { @_ }, "Sub" } 1002 sub emit_python { 1003 my $self = $_[0]; 1004 $self->emit_python_indented(0) 1005 }; 1006 sub emit_python_indented { 1007 my $self = $_[0]; 1008 my $level = $_[1]; 1009 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 1010 if ((($self->{name} eq ''))) { 1011 Perlito6::Python::LexicalBlock::push_stmt_python(Perlito6::Python::AnonSub->new(('name' => $label), ('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('sig' => $self->{sig}), ('handles_return_exception' => 1))); 1012 return scalar ((Python::tab($level) . 'f_' . $label)) 1013 }; 1014 ((my $sig) = $self->{sig}); 1015 ((my $pos) = $sig->positional()); 1016 ((my $args) = do { 1017 (my $List_a = bless [], 'ARRAY'); 1018 (my $List_v = bless [], 'ARRAY'); 1019 $List_a 1020}); 1021 ((my $default_args) = do { 1022 (my $List_a = bless [], 'ARRAY'); 1023 (my $List_v = bless [], 'ARRAY'); 1024 $List_a 1025}); 1026 ((my $meth_args) = do { 1027 (my $List_a = bless [], 'ARRAY'); 1028 (my $List_v = bless [], 'ARRAY'); 1029 push( @{$List_a}, 'self' ); 1030 $List_a 1031}); 1032 for my $field ( @{($pos)} ) { 1033 ((my $arg) = $field->emit_python_name()); 1034 push( @{$args}, $arg ); 1035 push( @{$default_args}, ($arg . chr(61) . 'mp6_Scalar()') ); 1036 push( @{$meth_args}, ($arg . chr(61) . 'mp6_Scalar()') ) 1037 }; 1038 ((my $block) = Perlito6::Python::LexicalBlock->new(('block' => (defined $self->{block} ? $self->{block} : ($self->{block} ||= bless([], 'ARRAY')))), ('needs_return' => 1))); 1039 ((my $label2) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 1040 (my $List_s = bless [], 'ARRAY'); 1041 push( @{$List_s}, (Python::tab($level) . ('def f_') . $self->{name} . ('(') . Main::join($default_args, (', ')) . ('):')) ); 1042 push( @{$List_s}, (Python::tab(($level + 1)) . ('try:')) ); 1043 push( @{$List_s}, $block->emit_python_indented(($level + 2)) ); 1044 push( @{$List_s}, (Python::tab(($level + 1)) . ('except mp6_Return, r:')) ); 1045 push( @{$List_s}, (Python::tab(($level + 2)) . ('return r.value')) ); 1046 push( @{$List_s}, (Python::tab($level) . ('global ') . $label2) ); 1047 push( @{$List_s}, (Python::tab($level) . $label2 . (' ' . chr(61) . ' f_') . $self->{name}) ); 1048 push( @{$List_s}, (Python::tab($level) . ('def f_') . $label . ('(') . Main::join($meth_args, (', ')) . ('):')) ); 1049 push( @{$List_s}, (Python::tab(($level + 1)) . ('return ') . $label2 . ('(') . Main::join($args, (', ')) . (')')) ); 1050 push( @{$List_s}, (Python::tab($level) . ('self.__dict__.update(' . chr(123) . chr(39) . 'f_') . $self->{name} . (chr(39) . ':f_') . $label . (chr(125) . ')')) ); 1051 return scalar (Main::join($List_s, (chr(10)))) 1052 } 1053 } 1054 1055; 1056 { 1057 package Do; 1058 sub new { shift; bless { @_ }, "Do" } 1059 sub emit_python { 1060 my $self = $_[0]; 1061 $self->emit_python_indented(0) 1062 }; 1063 sub emit_python_indented { 1064 my $self = $_[0]; 1065 my $level = $_[1]; 1066 ((my $label) = ('_anon_' . Perlito6::Python::LexicalBlock::get_ident_python())); 1067 ((my $block) = $self->simplify()->block()); 1068 Perlito6::Python::LexicalBlock::push_stmt_python(Perlito6::Python::AnonSub->new(('name' => $label), ('block' => $block), ('sig' => Sig->new(('invocant' => undef()), ('positional' => do { 1069 (my $List_a = bless [], 'ARRAY'); 1070 (my $List_v = bless [], 'ARRAY'); 1071 $List_a 1072}), ('named' => do { 1073 (my $Hash_a = bless {}, 'HASH'); 1074 $Hash_a 1075}))), ('handles_return_exception' => 0))); 1076 return scalar ((Python::tab($level) . ('f_') . $label . ('()'))) 1077 } 1078 } 1079 1080; 1081 { 1082 package Use; 1083 sub new { shift; bless { @_ }, "Use" } 1084 sub emit_python { 1085 my $self = $_[0]; 1086 $self->emit_python_indented(0) 1087 }; 1088 sub emit_python_indented { 1089 my $self = $_[0]; 1090 my $level = $_[1]; 1091 return scalar ('') 1092 } 1093 } 1094 1095 1096} 1097 10981; 1099