[OpenBIOS] Fwd: [PATCH] Adds local variable support to OpenBIOS.
tarl-b2 at tarl.net
Fri Aug 31 20:40:58 CEST 2012
On 2012-Aug-31 09:50 , Programmingkid wrote:
> Are you saying my-variable is better than myVariable?
> How do global variables get you in trouble in recursion? Do you have
> an example?
Not off-hand, we learn to avoid doing that. To construct one - let's
take a method doing recursion properly, and break it:
\ Correct way, using stack manipulation
: fibonacci ( fib -- return ) recursive
dup 2 >= if ( fib )
dup 1- fibonnaci ( fib fib-1 )
swap 2 - fibonnaci ( fib-1 fib-2 )
+ ( fib )
then ( fib )
\ Incorrect way - using variable "fib", which will get overwritten
0 value fib;
: fibonnaci ( fib -- return ) recursive
to fib \ to avoid stack manipulation
fib 2 < if
fib 1- fibonnaci ( fib-1)
fib 2 - fibonnaci ( fib-1 fib-2 )
+ ( fib )
> I am not familiar with this alarm level. Could you explain what it is?
In IEEE 1275, you can set an "alarm" for a device. This will be called
asynchronously when the condition in question triggers (usually a timer
expiring). If you were in the middle of something else using global
variables, you can get in trouble if those global variables area also
used in the alarm code. The Serial driver for openboot uses alarms, for
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the OpenBIOS