And So Forth
Total Page:16
File Type:pdf, Size:1020Kb
bigFORTH+MINOΣ Documentation contains And so Forth. Bernd Paysan J.L. Bezemer (And so Forth. ) c 1991–2003 by Bernd Paysan Copyleft — all rights reversed Dokumentation Introduction III Introduction 1. “Real Programmers don’t Read Manuals” ell, it should be more “Real Programmers don’t Write Manuals”, as there have been some complaints that the free version of bigFORTH doesn’t contain a free Wmanual — the only available manual so far was the German manual for the commercial version. Since bigFORTH is a highly complex system, a manual is necessary. However, to get started, you could as well just start bigFORTH and play around with it. If you then still have questions, the lecture of this manual should clairify the issues. Note however that this is still work in process and the manual is neither complete nor accurate. If you feel able to contribute, do so! We propose to read the documentation part completely and try the examples. If there are questions left, you can use index and reference part to learn more. This manual assumes that you can use your operating system. The final version of the manual should contain a real Forth course and it should be possible to replace a Forth introduction with it; however this is far from complete now. 2. History bigFORTH bases on a 32 bit port of the volksFORTH-83 authors. volksFORTH-83 is a public domain system that is available for Atari ST, IBM PC and C64 (there called UltraForth). It’s a 16 bit implementation with the corresponding limitations like a 64 KByte large address space. volksFORTH bases to some extents on the Perry/Laxen-F83 from the Forth Interest Group. The volksFORTH authors started at the end of 1987 to port the system to 32 bits, and convert the compiler so that it creates real 68k machine code. To some engaged volks- FORTH users they gave running prototypes. The system then was called turboFORTH and should have been distributed commercially, but the project almost died. However, one of these engaged volksFORTH users continued development and after two years of development, bigFORTH 1.0 for the Atari ST was released in summer 1990. In 1992, at the German Forth-Tagung, Ewald Rieger and Friedl Amend asked me for a 386 version of bigFORTH, and Ewald Rieger sponsored the PC. 1995, this version (bigFORTH-DOS 1.20) was released, together with the last Atari ST version. The DOS version contained a object oriented widget toolkit which used VGA textmode to display. To continue development of the 386 version, Ewald Rieger sponsored another PC, with the goal to have bigFORTH run on OS/2, Windows NT, or Linux. I first started porting to OS/2, and after Linux got shared libraries, I ported over to Linux. In august 1996, after finishing my diploma thesis, I started on MINOΣ, the graphical user interface for bigFORTH, a sequel to the text mode UI of bigFORTH-DOS. On the Forth-Tagung 1997, I presented the first results and soon afterwards put a demo on my homepage. Later in 1997, the license has been decided, it’s GPL (see page 247). IV Introduction bigFORTH 3. Returning Thanks I want to thank the volksFORTH authors Dietrich Weineck, Georg Rehfeld and Klaus Schleisiek, since without their work and without their volksFORTH big- FORTH woudn’t exist. Especially I’d like to thank Bernd Pennemann here, for his support cleared all open questions (including those of copyright), and whos recommenda- tions allowed to complete the system. Furthermore he suggested (among a list of other suggestions) the name. Further special thanks to Ewald Rieger, who supported the development over the time, and many thanks to the testers for their bug reports and suggestions. Thanks also to Nikolaus Heusler who lectured the original manual. I’d also like to thank Charles H. Moore, for his wonderful Forth, Donald E. Knuth, for his TEX, Linus Torvalds for Linux, and Richard M. Stallman for the GNU public license and the GNU tools he started to develop. 4. Target Market Forth has traditinally been much more a public domain language, that — unlike COBOL, Fortran, C or ADA — wasn’t supported by neither the industry nor the military, and — unlike Pascal resp. Modula II — also wasn’t developed on universities. Forth’s development lies mostly in the hand of engaged small companies or users, who have some difficulties to match offerings of other languages. bigFORTH should fill this gap and provide a modern development environment, that doesn’t capitulate from large problems and create code that is in speed competitive to other high level languages. 5. Copyleft bigFORTH is copyrighted by Bernd Paysan, and available under GPL. The manual here is also available under GPL, with excempt of the GPL text included here, which may not be modified. M¨unchen, in December 1999 Bernd Paysan Dokumentation Contents V Contents Introduction III 1. “Real Programmers don’t Read Manuals” .................. III 2. History ...................................... III 3. Returning Thanks ................................ IV 4. Target Market .................................. IV 5. Copyleft ..................................... IV Contents V 1 Installation 1 1. Installing on Linux ............................... 1 2. Installation on Windows ............................ 1 3. Editor Commands ................................ 2 4. Notation von Befehlen ............................. 2 5. Zahleneingaben ................................. 3 6. Notation von Sondertasten ........................... 4 2 Tutorial 5 1. Starting the System ............................... 5 2. End of a Session ................................. 5 3. The Line Editor ................................. 6 4. Error Messages ................................. 6 3 And so Forth. 7 1. Preface ...................................... 7 1.1. Copyright ................................ 7 1.2. Introduction ............................... 7 1.3. About this primer ............................ 7 2. Forth fundamentals ............................... 8 2.1. Making calculations without parenthesis ............... 8 2.2. Manipulating the stack ......................... 9 2.3. Deep stack manipulators ........................ 10 2.4. Pass arguments to functions ...................... 11 2.5. Making your own words ........................ 11 2.6. Adding comment ............................ 12 2.7. Text-format of Forth source ...................... 12 2.8. Displaying string constants ....................... 13 2.9. Declaring variables ........................... 13 2.10. Using variables ............................. 13 2.11. Built-in variables ............................ 13 2.12. What is a cell? ............................. 14 2.13. Declaring and using constants ..................... 14 2.14. Built-in constants ............................ 14 2.15. Using booleans ............................. 14 VI CONTENTS bigFORTH 2.16. IF-ELSE constructs ........................... 15 2.17. FOR-NEXT constructs ......................... 15 2.18. WHILE-DO constructs ......................... 16 2.19. REPEAT-UNTIL constructs ...................... 17 2.20. Infinite loops .............................. 17 2.21. Getting a number from the keyboard ................. 17 2.22. Aligning numbers ............................ 18 3. Arrays and strings ............................... 18 3.1. Declaring arrays of numbers ...................... 18 3.2. Using arrays of numbers ........................ 18 3.3. Creating arrays of constants ...................... 19 3.4. Using arrays of constants ........................ 19 3.5. Creating strings ............................. 19 3.6. Initializing strings ............................ 20 3.7. Getting the length of a string ..................... 20 3.8. Printing a string variable ........................ 21 3.9. Copying a string variable ........................ 22 3.10. Slicing strings .............................. 24 3.11. Appending strings ........................... 26 3.12. Comparing strings ........................... 26 3.13. Removing trailing spaces ........................ 27 3.14. String constants and string variables ................. 27 3.15. The count byte ............................. 28 3.16. Printing individual characters ..................... 28 3.17. Getting ASCII values .......................... 28 3.18. When to use [CHAR] or CHAR .................... 28 3.19. Printing spaces ............................. 29 3.20. Fetching individual characters ..................... 30 3.21. Storing individual characters ...................... 30 3.22. Getting a string from the keyboard .................. 32 3.23. What is the TIB? ............................ 33 3.24. What is the PAD? ........................... 33 3.25. How do I use TIB and PAD? ..................... 33 3.26. Temporary string constants ...................... 33 3.27. Simple parsing ............................. 34 3.28. Converting a string to a number .................... 35 3.29. Controlling the radix .......................... 36 3.30. Pictured numeric output ........................ 39 3.31. Converting a number to a string .................... 41 4. Stacks and colon definitions .......................... 42 4.1. The address of a colon-definition ................... 42 4.2. Vectored execution ........................... 42 4.3. Using values ............................... 43 4.4. The stacks ................................ 44 4.5. Saving temporary values ........................ 44 4.6. The Return Stack and the DO..LOOP ................ 46 4.7. Other Return Stack manipulations .................. 47 4.8. Altering the flow with the