How Local Variables in Forth Work --- Using Apple’s Open Firmware Implementation

From OpenBIOS
Revision as of 19:32, 25 September 2010 by Programmingkid (talk) (Created page with "<P><FONT SIZE=5><B>How Local Variables in Forth Work --- Using Apple�s Open Firmware Implementation<BR> </B></FONT><BR> <FONT SIZE=3><FONT COLOR="#AA0000"><B><U>Contents:</...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How Local Variables in Forth Work --- Using Apple&#146;s Open Firmware Implementation

How to try out these code examples
Declaring local variables
Setting local variables
Obtaining local variables&#146; values
Booting Mac OS X in OpenBIOS

How to try out these code examples

The following example code may be entered and ran in Apple&#146;s Open Firmware. In order to access Open Firmware, just hold down Command-Option-O-F while you boot your pre-Intel Mac. PowerPC iMacs and PowerBooks, iBooks, PowerMac G3&#146;s, G4&#146;s, and G5&#146;s all have Open Firmware built-in.

Declaring local variables:

Place curly braces next to the word name. The curly braces must be on the same line as the word&#146;s name. The semicolon is optional. The semicolon lets the system know that the variables following it will not be initializing their values to the values that would have been popped from the stack.

Example 1

myword { ; cat dog }

Omitting the semicolon will initialize the local variable&#146;s values to values popped from the stack. Make sure the stack has enough values in it before proceeding.

Setting local variables:

The word &#147;->&#148; (hyphen greater-than) is used to set the values of local variables.

Example 2

myword { ; cat dog }
4 -> cat
5 -> dog

In the above example, the numbers are each pushed into the stack first. Then the -> word pops a value out of the stack and sets each variable&#146;s value to a popped value. If a value is already in the stack, the following code would work as well: -> cat (The 4 has been omitted).

Obtaining a local variable&#146;s value

To push a local variable&#146;s value onto the stack, just enter a local variable&#146;s name in a word.

Example 3

myword { ; cat dog }

4 -> cat
5 -> dog

cat \ cat&#146;s value pushed onto stack ( - cat)
dog \ dog&#146;s value pushed onto stack (cat - cat dog )

.&#148; Total animals = &#147; .

Booting Mac OS X using OpenBIOS.

The reason why OpenBIOS can&#146;t boot Mac OS X is because of missing local variable support. Maybe you can help fix this problem.