Propeller Manual

Table Of Contents
RETURN – Spin Language Reference
Page 196 · Propeller Manual v1.1
RETURN
Command: Exit from PUB/PRI method with optional return Value.
((PUB PRI))
RETURN Value
Returns: Either the current RESULT value, or Value if provided.
Value is an optional expression whose value is to be returned from the PUB or PRI
method.
Explanation
RETURN is one of two commands (ABORT and RETURN) that terminate a PUB or PRI method’s
execution.
RETURN causes a return from a PUB or PRI method with normal status; meaning it
pops the call stack once and returns to the caller of this method, delivering a value in the
process.
Every PUB or PRI method has an implied RETURN at its end, but RETURN can also be manually
entered in one or more places within the method to create multiple exit points.
When
RETURN appears without the optional Value, it returns the current value of the PUB/PRI’s
built-in
RESULT variable. If the Value field was entered, however, the T PUB or PRI returns with
that Value instead.
About the Call Stack
When methods are called, simply by referring to them from other methods, there must be
some mechanism in place to store where to return to once the called method is completed.
This mechanism is a called a “stack” but we’ll use the term “call stack” here. It is simply
RAM memory used to store return addresses, return values, parameters and intermediate
results. As more and more methods are called, the call stack logically gets longer. As more
and more methods are returned from (via
RETURN or by reaching the end of the method) the
call stack gets shorter. This is called “pushing” onto the stack and “popping” off of the stack,
respectively.
The RETURN command pops the most recent data off the call stack to facilitate returning to the
immediate caller; the one who directly called the method that just returned.