Difference between revisions of "Forth"

From eLinux.org
Jump to: navigation, search
Line 11: Line 11:
  
 
atlast.html and atlast.pdf is included and an is an extensive atlast-forth manual. Read it online [http://www.fourmilab.ch/atlast/]
 
atlast.html and atlast.pdf is included and an is an extensive atlast-forth manual. Read it online [http://www.fourmilab.ch/atlast/]
 +
 +
It is easy to add your own words, just add a "define GERTBOARD" to atlast.c around line 64. In my case I will add some words for controlling my Gertboard. I will leave it as a skeleton until I've done the implementation myself.
 +
<code><pre>
 +
#define STRING       /* String functions */
 +
#define SYSTEM       /* System command function */
 +
#define GERTBOARD   /* Gertboard command function */
 +
</pre></code>
 +
 +
Then add your own word definitions at the end of the section with word definitions, around line 2700 in atlast.c
 +
<code><pre>
 +
#ifdef GERTBOARD
 +
 +
prim P_gert_setport() // channel state ---
 +
{ // Set a digital io port to a specified state
 +
  Sl(2); // Make sure there is at least two params on the stack
 +
// Your code goes here
 +
}
 +
 +
prim P_gert_getport() // channel  ---
 +
{ // Get the state of a digital port
 +
  Sl(1); // Make sure there is at least one param on the stack
 +
// Your code goes here
 +
}
 +
 +
#endif /* GERTBOARD */
 +
</pre></code>
 +
 +
And finally, add the actual words to the list of defined words right after ifdef EVALUATE at line 3050 or so.
 +
<code><pre>
 +
#ifdef EVALUATE
 +
    {"0EVALUATE", P_evaluate},
 +
#endif /* EVALUATE */
 +
 +
#ifdef GERTBOARD
 +
{"0SETIO", P_gert_setport},
 +
{"0GETIO", P_gert_getport},
 +
#endif /* GERTBOARD */
 +
</pre></code>
 +
 +
Now, save and run "make" again to recompile atlast.c.

Revision as of 05:01, 6 July 2013

Forth on RPi

sudo apt-get install wget
wget http://www.fourmilab.ch/atlast/download/1.2/atlast-1.2.tar.gz
tar -xzvf atlast-1.2.tar.gz
cd atlast-1.2/
make

Start the Forth interpreter with ./atlast and exit with Ctrl-D

atlast.html and atlast.pdf is included and an is an extensive atlast-forth manual. Read it online [1]

It is easy to add your own words, just add a "define GERTBOARD" to atlast.c around line 64. In my case I will add some words for controlling my Gertboard. I will leave it as a skeleton until I've done the implementation myself.

#define STRING			      /* String functions */
#define SYSTEM			      /* System command function */
#define GERTBOARD			   /* Gertboard command function */

Then add your own word definitions at the end of the section with word definitions, around line 2700 in atlast.c

#ifdef GERTBOARD

prim P_gert_setport() // channel state ---
{ // Set a digital io port to a specified state
   Sl(2); // Make sure there is at least two params on the stack
	// Your code goes here
}

prim P_gert_getport() // channel  ---
{ // Get the state of a digital port
   Sl(1); // Make sure there is at least one param on the stack
	// Your code goes here
}

#endif /* GERTBOARD */

And finally, add the actual words to the list of defined words right after ifdef EVALUATE at line 3050 or so.

#ifdef EVALUATE
    {"0EVALUATE", P_evaluate},
#endif /* EVALUATE */

#ifdef GERTBOARD
	 {"0SETIO", P_gert_setport},	
	 {"0GETIO", P_gert_getport},		
#endif /* GERTBOARD */

Now, save and run "make" again to recompile atlast.c.