Skip to content

Commit

Permalink
Refactor &return, &next, &last, &redo.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jul 24, 2010
1 parent f196e88 commit 369f1e0
Showing 1 changed file with 49 additions and 62 deletions.
111 changes: 49 additions & 62 deletions src/builtins/control.pir
Expand Up @@ -11,6 +11,35 @@ src/builtins/control.pir - control flow related functions
.include 'except_types.pasm'
.include 'except_severity.pasm'

=item !control(type, value)

Basic function for throwing an exception of C<type> with
C<value> as the payload. C<value> is assumed to be a
ResizablePMCArray (e.g., from a :slurpy argument), which
is then converted into an appropriate Parcel depending
on the number of elements.

=cut

.sub '!control' :anon
.param pmc type
.param pmc value
$I0 = elements value
if $I0 != 1 goto many
value = value[0]
goto done
many:
value = '&infix:<,>'(value :flat)
done:
.local pmc ex
ex = root_new ['parrot';'Exception']
setattribute ex, 'type', type
setattribute ex, 'payload', value
$P0 = box .EXCEPT_NORMAL
setattribute ex, 'severity', $P0
throw ex
.end

=item die

=cut
Expand Down Expand Up @@ -54,30 +83,32 @@ src/builtins/control.pir - control flow related functions
exit status
.end

=item return

=item return, last, next, redo

=cut

.sub '&return'
.param pmc retvals :slurpy
.local pmc ex, retval
ex = root_new ['parrot';'Exception']
ex['type'] = .CONTROL_RETURN
$I0 = elements retvals
if $I0 == 0 goto nil
if $I0 > 1 goto many
retval = retvals[0]
goto done
nil:
retval = '&Nil'()
goto done
many:
retval = '&infix:<,>'(retvals :flat)
done:
setattribute ex, 'payload', retval
throw ex
.tailcall '!control'(.CONTROL_RETURN, retvals)
.end

.sub '&last'
.param pmc retvals :slurpy
.tailcall '!control'(.CONTROL_LOOP_LAST, retvals)
.end

.sub '&next'
.param pmc retvals :slurpy
.tailcall '!control'(.CONTROL_LOOP_NEXT, retvals)
.end

.sub '&redo'
.param pmc retvals :slurpy
.tailcall '!control'(.CONTROL_LOOP_REDO, retvals)
.end


=item warn

=cut
Expand Down Expand Up @@ -175,51 +206,6 @@ src/builtins/control.pir - control flow related functions
throw e
.end

=item next

=cut

.sub '&next'
.local pmc e, p6ex
e = root_new ['parrot';'Exception']
e['severity'] = .EXCEPT_NORMAL
e['type'] = .CONTROL_LOOP_NEXT
p6ex = new ['Perl6Exception']
setattribute p6ex, '$!exception', e
set_global '$!', p6ex
throw e
.end

=item redo

=cut

.sub '&redo'
.local pmc e, p6ex
e = root_new ['parrot';'Exception']
e['severity'] = .EXCEPT_NORMAL
e['type'] = .CONTROL_LOOP_REDO
p6ex = new ['Perl6Exception']
setattribute p6ex, '$!exception', e
set_global '$!', p6ex
throw e
.end

=item last

=cut

.sub '&last'
.local pmc e, p6ex
e = root_new ['parrot';'Exception']
e['severity'] = .EXCEPT_NORMAL
e['type'] = .CONTROL_LOOP_LAST
p6ex = new ['Perl6Exception']
setattribute p6ex, '$!exception', e
set_global '$!', p6ex
throw e
.end

=item take

=cut
Expand Down Expand Up @@ -389,6 +375,7 @@ find nothing more to call.
clist.'trim_candidate_list'()
.end


=back

=cut

0 comments on commit 369f1e0

Please sign in to comment.