a6e0645b2a34c19dcd6b0b5fa86dc14107186679
[forth.jl.git] / README.md
1 # forth.jl
2
3 A hobby implementation of a forth system atop the Julia scientific computing
4 language.  It will almost certainly never be useful for any purpose besides
5 that which it has already fulfilled: forcing me to think quite carefully about
6 how forth works. 
7
8 This package owes a massive debt to the existence of the literate programming
9 project [JonesForth](https://rwmj.wordpress.com/2010/08/07/jonesforth-git-repository/),
10 which was an amazing read. To a large degree my package is simply a port of
11 that project from x86 assembly + forth to julia + forth, although the mapping
12 is in a few places non-trivial due to the fact that julia is a high level
13 language.  During the bootstrapping process, a huge proportion (say 80%) of the
14 library code in src/lib.4th was directly copied from JonesForth.  (The fact
15 that it was possible to reuse this code was satisfying in its own right!) Since
16 that time I've added a significant number of core definitions and modified some
17 of the others with the eventual aim of F83 compliance (discussed below).
18
19 There's quite a lot to say about the implementation, especially due to its
20 high-level grounding, but that will have to wait for another time.
21
22 ## Installation
23
24 forth.jl is not (and probably will never be) a registered julia package.  To
25 install it, you will therefore need to use the following command:
26
27     julia> Pkg.clone("https://github.com/tgvaughan/forth.jl")
28
29 Currently, forth.jl **requires** Julia 0.6. (Incompatabilities exist between
30 0.6 and previous versions of julia, particularly the handling of [world age](https://github.com/JuliaLang/julia/pull/17057).)
31
32 ## Usage
33
34 To start the interpreter/compiler running, simply enter the following at
35 the julia prompt:
36
37     julia> import forth
38     julia> forth.run()
39
40 The first thing the interpreter will do is compile the core definitions in
41 the library file.  Once this is complete you can start entering forth commands:
42
43     : star 42 emit ;  ok
44     star * ok
45
46 There's an example Mandelbrot Set drawing program included in the examples
47 directory.  To run it, use the `INCLUDE-LIB` word to open the file and compile its
48 definitions:
49
50     include-lib ../examples/mandelbrot.4th
51     Enter 'mandel' to draw the Mandelbrot Set. ok
52     mandel
53                                                                                 *                   
54                                                                                                     
55                                                                            **                       
56                                                                         ********                    
57                                                                        *********                    
58                                                                          *****                      
59                                                           ***     ********************              
60                                                            ****************************** ****      
61                                                           **********************************        
62                                                        ***************************************      
63                                                      ********************************************   
64                                   **    *            *******************************************    
65                                   *************    *********************************************    
66                                ******************  ********************************************     
67                                ******************* ********************************************     
68          **    *     *  *******************************************************************         
69                                ******************* *******************************************      
70                                 *****************  ********************************************     
71                                   *************     ********************************************    
72                                   **    *           ********************************************    
73                                                      ********************************************   
74                                                         **************************************      
75                                                          ***********************************        
76                                                            ****************************** ****      
77                                                            **     ********************              
78                                                                          *****                      
79                                                                         *******                     
80                                                                        *********                    
81                                                                            **                       
82     ok
83
84 (`INCLUDE-LIB` is exactly like INCLUDE, but includes files relative to thte
85 platform-dependent forth.jl src/ directory.) To exit, enter ^D on a blank line
86 or use the `BYE` word.
87
88 ## FORTH-83 Compliance
89
90 One of my goals has been to have forth.jl contain as much of the
91 [F83 required word set](http://forth.sourceforge.net/standard/fst83/fst83-12.htm) 
92 as makes sense given the underlying VM. (Actually, my main goal goes a bit
93 beyond this: I want to forth.jl to be, with a couple of exceptions, compatible
94 with the description of forth contained in the second edition of Leo Brodie's
95 book "Starting Forth".)  I'm fairly happy with my progress so far.  Of the
96 131 required F83 words, only 20 remain unimplemented.  These words fall into
97 two categories: those I may possibly implement at some point, and those that I
98 do not intend to ever implement for reasons of obsolescence or incompatibility
99 with the design of the VM.
100
101 ### F83 Words that may be implemented someday
102
103     # #> #S -TRAILING <#
104
105 These words all have to do with number to string conversion, something I've
106 not been interested in enough yet to get on top of.
107
108 ### F83 Words that won't be implemented
109
110     D+ D< DNEGATE U< UM* UM/MOD BLOCK BUFFER FLUSH
111     SAVE-BUFFERS UPDATE BLK HOLD LOAD FORTH-83
112
113 These words don't make sense to implement.  The double-length integer words are
114 useless because the smallest unit of memory in our VM is a full 64 bit
115 integer.  For the same reason, there's no point in dealing with unsigned values
116 just to gain access to another bit.  The block I/O words don't make sense because
117 we have access to a filesystem via the OS.
118
119 ## License
120
121 This package is free software and is distributed under version 3.0 of the GNU
122 General Public License, which may be found in the file LICENSE in this
123 directory.