From d7dcd5815b528c2d21fc9ec186208be4ee74c0c5 Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Tue, 10 May 2011 10:51:14 +0200 Subject: [PATCH] More exec() refactoring. --- Art5.pm | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/Art5.pm b/Art5.pm index 6d35edb..7423cbd 100644 --- a/Art5.pm +++ b/Art5.pm @@ -227,35 +227,38 @@ sub exec { my $prg = shift; my $ret; - # if it has additonal arguments, - # wrap the call in a stack with them - if (scalar(@_)) { - push(@{$self->{stack}}, [ @_ ]); - - $ret = $self->exec($prg); - - pop(@{$self->{stack}}); - } - elsif (ref($prg) && !$self->{abort}) { - # stream of Artemus5 code - my @stream = @{$prg}; + if (ref($prg) && !$self->{abort}) { + # if it has additonal arguments, + # wrap the call in a stack with them + if (scalar(@_)) { + push(@{$self->{stack}}, [ @_ ]); - # pick opcode - my $op = shift(@stream); + $ret = $self->exec($prg); - # pick code - my $c = $self->code($op); - - if (ref($c) eq 'CODE') { - $ret = $c->(@stream); - } - elsif (ref($c) eq 'ARRAY') { - $ret = $self->exec($c, - map { $self->exec($_) } @stream - ); + pop(@{$self->{stack}}); } else { - croak "Artemus5 opcode not found: $op"; + # stream of Artemus5 code + my @stream = @{$prg}; + + # pick opcode + my $op = shift(@stream); + + # pick code + my $c = $self->code($op); + + if (ref($c) eq 'CODE') { + $ret = $c->(@stream); + } + elsif (ref($c) eq 'ARRAY') { + $ret = $self->exec( + $c, + map { $self->exec($_) } @stream + ); + } + else { + croak "Artemus5 opcode not found: $op"; + } } } -- 2.11.4.GIT