[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #63268] throw|catch behavior: unexpected items at data stack
From: |
Stephan Rudlof |
Subject: |
[bug #63268] throw|catch behavior: unexpected items at data stack |
Date: |
Tue, 25 Oct 2022 07:40:05 -0400 (EDT) |
Follow-up Comment #4, bug #63268 (project gforth):
Hello Anton,
thanks for further explanation!
coming from a non-Forth experience - C, C++, Javascript, Smalltalk -, where
stack effects are *not* managed by programmer, having access to *unknown*
values there has been the trap which has catched me... (local vars at stack
typically stay at their value).
BTW:
Do you think this is a good place for such discussions, or would it be better
to use some discussion ML (or similar)?
Sharing some learning experience is not a bug report in the narrow sense...
(but I like the discussion experience here!).
Some way to get wished stack behavior for the example below is to move
arguments to throwing word inside try|endtry (all together suited for
copy/paste):
sr@rs:~/Gforth$ cat throw_catch_problem3.fs
: run-thrower_no-arg ( -- )
try
77 throw
restore
endtry
~~
." just before throw"
throw
;
: run-thrower_arg ( c-addr u -- )
2drop
try
77 throw
restore
endtry
~~
." just before throw"
throw
;
: trigger_problem
s" arg" cr 2dup . .
~~
['] run-thrower_arg catch
~~
." after catch: *why* 2 additional stack items at dstack after catching
err throw here?"
assert( 77 = )
;
: trigger_problem_not
~~
['] run-thrower_no-arg catch
~~
." after catch: *no* 2 additional stack items at dstack after catching
err throw here."
assert( 77 = )
;
: trigger_problem_not_arg
try
s" arg" cr 2dup . .
run-thrower_arg 0
restore
endtry
~~
." after catch: *no* additional stack items at dstack after catching err
throw here!"
assert( 77 = )
;
sr@rs:~/Gforth$ gforth throw_catch_problem3.fs
Gforth 0.7.9_20221013
Authors: Anton Ertl, Bernd Paysan, Jens Wilke et al., for more type `authors'
Copyright © 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `help' for basic help
trigger_problem_not_arg
3 139760105353056
throw_catch_problem3.fs:16:5:<1> #77
just before throw
throw_catch_problem3.fs:43:5:<1> #77
after catch: *no* additional stack items at dstack after catching err throw
here! ok
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63268>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/