Skip to content

Commit

Permalink
[exceptions] Adds pop_eh and push_eh_p
Browse files Browse the repository at this point in the history
  ** MAKE REALCLEAN REQUIRED DUE TO NEW OPS **


git-svn-id: https://svn.parrot.org/parrot/trunk@22465 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
tewk committed Oct 25, 2007
1 parent 35043e9 commit 5ebf40f
Show file tree
Hide file tree
Showing 91 changed files with 1,019 additions and 260 deletions.
4 changes: 4 additions & 0 deletions DEPRECATED.pod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ deprecated:

=over 4

=item B<clear_eh>.

Use B<pop_eh> instead.

=item B<store_global>

=item B<find_global>
Expand Down
2 changes: 1 addition & 1 deletion compilers/json/JSON/pge2pir.tg
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ transform pir (string) {
loop:
push_eh loop_end
child = shift iter
clear_eh
pop_eh
unless child goto loop_end
$S0 = child
$I0 = length $S0
Expand Down
2 changes: 1 addition & 1 deletion compilers/json/postalcodes.pir
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ END:
code_loop:
push_eh code_end
code = shift iter
clear_eh
pop_eh
unless code goto code_end

$S0 = code['placeName']
Expand Down
2 changes: 1 addition & 1 deletion compilers/past-pm/POST/Grammar.tg
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ transform try (PAST::Op) :language('PIR') {
endlabel = post.'new'('POST::Label', 'result'=>$S0)
post.'push_pirop'('push_eh', traplabel)
post.'push'(trypost)
post.'push_pirop'('clear_eh')
post.'push_pirop'('pop_eh')
post.'push_pirop'('goto', endlabel)
post.'push'(traplabel)
.local pmc catchnode, catchpast
Expand Down
2 changes: 1 addition & 1 deletion compilers/pct/src/HLLCompiler.pir
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ specifies the encoding to use for the input (e.g., "utf8").
unless code goto interactive_loop
push_eh interactive_trap
$P0 = self.'eval'(code, adverbs :flat :named)
clear_eh
pop_eh
if null $P0 goto interactive_loop
unless target goto interactive_loop
if target == 'pir' goto target_pir
Expand Down
2 changes: 1 addition & 1 deletion compilers/pct/src/POST/Grammar.tg
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ transform try (PAST::Op) :language('PIR') {
endlabel = $P0.'new'('result'=>$S0)
post.'push_pirop'('push_eh', traplabel)
post.'push'(trypost)
post.'push_pirop'('clear_eh')
post.'push_pirop'('pop_eh')
post.'push_pirop'('goto', endlabel)
post.'push'(traplabel)
.local pmc catchnode, catchpast
Expand Down
2 changes: 1 addition & 1 deletion compilers/pge/PGE/Exp.pir
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ C<target> adverbs.
make_grammar:
push_eh end
$P0 = subclass 'PGE::Grammar', grammar
clear_eh
pop_eh
end:
.return ($P1)

Expand Down
2 changes: 1 addition & 1 deletion compilers/pirc/src/pirutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static char const *parrot_ops[] = {
"clearp",
"clearn",
"cleari",
"clear_eh",
"pop_eh",
"classoffset",
"classname",
"class",
Expand Down
2 changes: 1 addition & 1 deletion compilers/tge/TGE/Compiler.pir
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ loop_end:
code .= "', '"
code .= type
code .= "'\n"
code .= " clear_eh\n"
code .= " pop_eh\n"
code .= " class_loaded:\n"
code .= "\n.end\n\n"
.return (code)
Expand Down
4 changes: 2 additions & 2 deletions docs/compiler_faq.pod
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Use C<push_eh> to push an exception handler onto the stack.
push_eh handler
$P0 = new 'Exception' # or any other code ...
throw $P0 # ... that might throw
clear_eh
pop_eh
exit 0

An exception handler is called with two arguments: the exception and the
Expand Down Expand Up @@ -494,7 +494,7 @@ Rethrow the exception if it has a severity of C<EXCEPT_EXIT>.
$P0 = new 'Exception'
$P0['_message'] = 'something happened'
throw $P0
clear_eh
pop_eh
exit 0

handler:
Expand Down
30 changes: 27 additions & 3 deletions docs/pdds/pdd23_exceptions.pod
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ handlers, invoking each one in turn, but still in the dynamic context of the
exception (i.e. the call stack is I<not> unwound first). See below for more
detail.

If a I<LABEL> is provided, Parrot creates and pushes a continuation that
If a I<LABEL> or is provided, Parrot creates and pushes a continuation that
resumes execution at I<LABEL> if invoked, which has the effect of
unconditionally handling all errors, and unwinding the stack to that label.

If a I<INVOCABLE_PMC> is provided, Parrot pushes the pmc which will execute
if invoked, which has the effect of unconditionally handling all errors,
replacing the stack with that execution context of the invocable pmc.

=item B<pop_eh>

Pop the most recently pushed exception handler off the exception handler stack.

{{ TODO: Provide exception handler stack introspection. }}

=item B<throw I<EXCEPTION>>

Throw an exception consisting of the given I<EXCEPTION> PMC. Active exception
Expand Down Expand Up @@ -131,6 +133,28 @@ exception handler's way of telling Parrot that it has handled the exception.

=back

=head2 Exception Introspection Opcodes
{{ TODO: Provide exception handler stack introspection. }}

These are the opcodes relevant to introspection of the exception handler stack:

=over

=item B<count_eh>

Return the quantity of currently active exception handlers.

=item B<get_eh I<index>>

Return the exception handler at I<index>

=item B<get_all_eh>

Return a resizable pmc array of all current exception handlers.

=back


=head2 Order of Operations in Exception Handling

When B<throw> or B<throwcc> is called, for all active exception
Expand Down
2 changes: 1 addition & 1 deletion editor/pir-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ newline or semicolon after an end keyword."
"wrapper__" "prederef__" "reserved" "load_bytecode" "branch"
"branch_cs" "bsr" "ret" "jsr" "jump" "enternative" "if" "unless" "invoke"
"invokecc" "updatecc" "set_addr" "get_addr" "newsub" "set_eh"
"clear_eh" "throw" "rethrow" "die_hard" "exit" "debug" "bounds"
"pop_eh" "throw" "rethrow" "die_hard" "exit" "debug" "bounds"
"profile" "trace" "gc_debug" "interpinfo" "warningson"
"warningsoff" "errorson" "errorsoff" "runinterp" "getinterp"
"setline" "getline" "setfile" "getfile" "setpackage" "getpackage"
Expand Down
2 changes: 1 addition & 1 deletion languages/APL/src/parse2past.tg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ END_INLINE
past.'push'(cpast)
goto iter_loop
iter_end:
$P0 = past.'push_new'('PAST::Op', 'pirop'=>'inline', 'inline'=> ' clear_eh # %r')
$P0 = past.'push_new'('PAST::Op', 'pirop'=>'inline', 'inline'=> ' pop_eh # %r')
.return (past)
}

Expand Down
2 changes: 1 addition & 1 deletion languages/PIR/docs/PROPOSALS
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ NEW FEATURE PROPOSALS GO HERE:
...
push_eh on_error
# do some scary stuff
clear_eh
pop_eh
goto after_handler
on_error:
# exception handling
Expand Down
2 changes: 1 addition & 1 deletion languages/PIR/lib/pasm_core.pg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rule core_op {
| get_addr <arg_hack> #<target> \, <target>
# exception handling
| push_eh <arg_hack> #<id>
| clear_eh <arg_hack> #
| pop_eh <arg_hack> #
| throw <arg_hack> #<target>
| rethrow <arg_hack> #<target>
| die <arg_hack> #<int_constant> \, <int_constant>
Expand Down
2 changes: 1 addition & 1 deletion languages/PIR/lib/pasm_instr.pg
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ token pasm_instruction {
| clearp
| clearn
| cleari
| clear_eh
| pop_eh
| classoffset
| classname
| class
Expand Down
2 changes: 1 addition & 1 deletion languages/WMLScript/src/wmlsstdlibs.pir
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ helper for CALL_URL* opcodes.
pbc_out = pir_comp(gen_pir)
$P0 = pbc_out[0]
$P0()
clear_eh
pop_eh
# push_eh _handler_2
.local pmc entry
$S0 = url
Expand Down
2 changes: 1 addition & 1 deletion languages/cardinal/src/OSTGrammar.tg
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ transform post (Cardinal::PAST::Rescue_Stmt) :language('PIR') {
ops.'add_child'($P0)

op = new 'Cardinal::POST::Op'
op.'init'('node'=>node, 'name'=>'clear_eh')
op.'init'('node'=>node, 'name'=>'pop_eh')
ops.'add_child'(op)

op = new 'Cardinal::POST::Op'
Expand Down
2 changes: 1 addition & 1 deletion languages/dotnet/doc/constructs/exceptions.pod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The Parrot exception system is based around an exception stack. Handlers are
simply represented as offsets in a given context, and are created at runtime
by using the push_eh instruction and supplying a label located at the start
of the handler. The last exception handler that was placed on the stack can
be popped off using the clear_eh instruction.
be popped off using the pop_eh instruction.

Exceptions themselves are PMCs; more specifically, an exception must be an
instance of the built-in Exception PMC. This PMC provides a keyed interface
Expand Down
2 changes: 1 addition & 1 deletion languages/dotnet/src/translator.pir
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ NO_EH:
pir_output = concat src
inc done_types
if continue == 0 goto RESUME
clear_eh
pop_eh
RESUME:
inc i
goto CLOOP
Expand Down
2 changes: 1 addition & 1 deletion languages/forth/forth.pir
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ loop:
# push_eh exception
$P0 = forth($S0)
$P0()
# clear_eh
# pop_eh

print " ok\n"
goto loop
Expand Down
2 changes: 1 addition & 1 deletion languages/forth/test.pir
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ missing_output:
push_eh exception
$P0 = forth(input)
stack = $P0()
clear_eh
pop_eh
output = readline stdout
$S0 = pop stdout
if output != "" goto compare
Expand Down
6 changes: 3 additions & 3 deletions languages/lisp/internals.pir
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internals.pir - lexical and global variables, function call

push_eh PACKAGE_NOT_FOUND # Set an error handler
find_global package, "PACKAGES", pkgname # Look for the package
clear_eh
pop_eh

retv = package._lookup_symbol(symname) # Lookup the symbol

Expand All @@ -47,7 +47,7 @@ DONE:
push_eh LEXICAL_NOT_FOUND # Set an error handler
.local pmc retv
find_lex retv, symname # Look for the lexical symbol
clear_eh
pop_eh

goto DONE

Expand Down Expand Up @@ -202,7 +202,7 @@ DONE:

push_eh PACKAGE_NOT_CREATED
find_global package, "PACKAGES", pkgname
clear_eh
pop_eh

symbol = package._intern_symbol(symname)
symbol._set_package(package) # Set the home package
Expand Down
2 changes: 1 addition & 1 deletion languages/lisp/system.pir
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ DONE:
.local pmc retv
retv = find_global "PACKAGES", pkgname_str
if_null retv, PACKAGE_NOT_FOUND
clear_eh
pop_eh

goto DONE

Expand Down
2 changes: 1 addition & 1 deletion languages/lua/lib/lfs.pir
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ optimal file system I/O blocksize; (Unix only)
new $P0, 'OS'
push_eh _handler
$P1 = $P0.'stat'($S1)
clear_eh
pop_eh
if null aname goto L1
$I0 = isa aname, 'LuaString'
unless $I0 goto L2
Expand Down
2 changes: 1 addition & 1 deletion languages/perl6/perl6.pir
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ to the Perl6 compiler.
push_eh exit_handler
$P1 = $P0.'command_line'(args)
clear_eh
pop_eh
goto do_END_blocks
Expand Down
2 changes: 1 addition & 1 deletion languages/pheme/lib/PhemeSymbols.pir
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
push_eh return_list
function = find_global symbol_name
unless function goto return_list
clear_eh
pop_eh

.local pmc result
result = function( args :flat )
Expand Down
2 changes: 1 addition & 1 deletion languages/pheme/pheme.pir
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Start compilation by passing any command line C<args> to the Pheme compiler.

push_eh exit_handler
$P1 = $P0.'command_line'(args)
clear_eh
pop_eh
goto done

exit_handler:
Expand Down
2 changes: 1 addition & 1 deletion languages/tcl/runtime/builtin/append.pir
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
setter:
push_eh new_variable
$P1 = read(name)
clear_eh
pop_eh

value = $P1
goto loop
Expand Down
2 changes: 1 addition & 1 deletion languages/tcl/runtime/builtin/catch.pir
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$P2 = __script(code, 'ns' => ns)
code_retval = $P2()
retval = TCL_OK # no exception => TCL_OK
clear_eh
pop_eh

goto got_retval

Expand Down
Loading

0 comments on commit 5ebf40f

Please sign in to comment.