| 1 | package VAST::signature; | ||
| 2 | BEGIN { | ||
| 3 | $VAST::signature::VERSION = '0.05'; | ||
| 4 | } | ||
| 5 | use utf8; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use Mildew::AST::Helpers; | ||
| 9 | |||
| 10 | sub emit_m0ld_ahsig_with_invocant { | ||
| 11 | my $m = shift; | ||
| 12 | my @stmts; | ||
| 13 | push @stmts, call BIND => (call 'postcircumfix:{ }' => reg '$scope',[string '$¿self']),[call new => lookupf('Scalar'),[call positional => reg '$capture',[integer 0]]]; | ||
| 14 | |||
| 15 | $m->emit_m0ld_ahsig(1,@stmts); | ||
| 16 | } | ||
| 17 | sub emit_m0ld_ahsig { | ||
| 18 | my $m = shift; | ||
| 19 | |||
| 20 | my $other = shift || 0; | ||
| 21 | my @stmts = @_; | ||
| 22 | |||
| 23 | # TODO invocant | ||
| 24 | |||
| 25 | for my $param (@{$m->{parameter}}) { | ||
| 26 | push @stmts, $param->emit_m0ld_ahsig_BIND($other); | ||
| 27 | $other++; | ||
| 28 | } | ||
| 29 | |||
| 30 | Mildew::AST::Call->new | ||
| 31 | ( identifier => string 'new', | ||
| 32 | capture => Mildew::AST::Capture->new | ||
| 33 | ( invocant => FETCH(lookup('AdhocSignature')), | ||
| 34 | positional => [], | ||
| 35 | named => | ||
| 36 | [ string 'BIND' => Mildew::AST::Block->new | ||
| 37 | ( regs => [qw(interpreter scope capture)], | ||
| 38 | stmts => trailing_return(\@stmts))])); | ||
| 39 | } | ||
| 40 | sub emit_m0ld_with_invocant { | ||
| 41 | my $m = shift; | ||
| 42 | |||
| 43 | if ($Mildew::adhoc_sig) { | ||
| 44 | return $m->emit_m0ld_ahsig_with_invocant(@_); | ||
| 45 | } | ||
| 46 | |||
| 47 | my $invocant = FETCH(call new => lookupf('ReadonlyParam')); | ||
| 48 | $m->emit_m0ld( | ||
| 49 | let $invocant, sub { | ||
| 50 | my $invocant = shift; | ||
| 51 | Mildew::AST::Seq->new(stmts => [ | ||
| 52 | call(STORE => (call variable => $invocant),[ string '$¿self']), | ||
| 53 | $invocant] | ||
| 54 | ); | ||
| 55 | }); | ||
| 56 | } | ||
| 57 | sub emit_m0ld { | ||
| 58 | my ($m,@other) = @_; | ||
| 59 | if ($Mildew::adhoc_sig) { | ||
| 60 | return $m->emit_m0ld_ahsig(@other); | ||
| 61 | } | ||
| 62 | my $sig = FETCH(call new => lookupf('Signature')); | ||
| 63 | let $sig, sub { | ||
| 64 | my $sig = shift; | ||
| 65 | my $stmts = [map ({call register => $_,[$sig]} @other),map ({call register => $_->emit_m0ld,[$sig]} @{$m->{parameter}}),$sig]; | ||
| 66 | Mildew::AST::Seq->new(stmts => $stmts); | ||
| 67 | }; | ||
| 68 | } | ||
| 69 | 1; |