JONESFORTH git repository

A few years ago I wrote a literate FORTH compiler and tutorial called JONESFORTH. It’s a good way, I think, to understand the power and limitations of FORTH, and a good way to learn a completely different and mind-blowing programming language.

If you’ve not heard of FORTH before, cogitate on this: It is possible to write a FORTH program in 2,000 lines. A program which will boot and provide an entire development environment (inc. editor, compiler etc) on bare hardware.

Anyhow, I just uploaded my semi-private CVS repository to git. You can find it here:

http://git.annexia.org/?p=jonesforth.git;a=summary

The original tutorial is in two parts:

About these ads

36 Comments

Filed under Uncategorized

36 responses to “JONESFORTH git repository

  1. Cheng-Chang Wu

    Hi,

    thanks for your fantastic work.

    I’m using it as a starting point in my next project. It will be used as a vm of a compiler.
    http://github.com/chengchangwu/sparkforth
    http://github.com/chengchangwu/gefc

    According to the work of Richard Russell on bb4wforth, version 47 of jonesforth has a bug in /MOD which is easy to fix. The fix proposed by Richard is

    defcode “/MOD”,4,,DIVMOD
    pop %ebx
    pop %eax
    cdq
    idivl %ebx
    push %edx // push remainder
    push %eax // push quotient
    NEXT

    Another fix is the U. in file jonesforth.f which should uses U/MOD instead of /MOD. The proposed change of Richard is to add U/MOD to jonesforth.S and to modify the U. accordingly.

    defcode “U/MOD”,4,,UDIVMOD
    xor %edx, %edx
    pop %ebx
    pop %eax
    divl %ebx
    push %edx // push remainder
    push %eax // push quotient
    NEXT

    : U. ( u — )
    BASE @ U/MOD ( width rem quot )
    ?DUP IF ( if quotient 0 then )
    RECURSE ( print the quotient )
    THEN

    ( print the remainder )
    DUP 10 < IF
    '0' ( decimal digits 0..9 )
    ELSE
    10 – ( hex and beyond digits A..Z )
    'A'
    THEN
    +
    EMIT
    ;

    Will you fix this bugs in the git respository?
    Do you accept any patch?

    Cheng-Chang Wu

  2. Cheng-Chang Wu

    Execute me, the length of U/MOD is 5, not 4.

    According to Richard’s work, jonesforth’s implementations of /MOD and U. have bugs, implementations of DEPTH, .S, HERE, ALLOT, CREATE, VARIABLE, TRUE, FIND, WHILE, REPEAT, WORD, KEY and ‘ are not compliance with ANS Forth. I’m planning to change these and only these, to keep jonesforth’s minimalism and to pave the way for ANS Forth compliance.

    In other words, to make ANS Forth a natural extension of jonesforth.

    If you agree, I can send you my patch after I have finished it.

    • rich

      What I suggest you (and anyone else) do is to set up a git repo and/or website with whatever changes you want to make. Let me know about the new site and I’ll add a link to it on the main website.

  3. Alex Farlie

    Interesting to see your attempts Cheng-Chang Wu,
    do you have a contact e-mail?

  4. Pingback: Daniel’s Stuff » The Funky Clock

  5. Hi Rich. The annexia links are broken.

  6. git://git.annexia.org/git/jonesforth.git <– I can't clone from this URL :(

  7. Clyde W. Phillips Jr.

    Hi guys, just checking in. Glad to see fresh FORTH faces. 40+ years a FORTH-er here. Anyone into colorFORTH and the new greenarrays chip? Hairy stuff! Cheers, Clyde

  8. I’ve been porting JonesForth.S and JonesForth.f to Windows.
    Are you interested in reviewing my work before I publish it?

  9. I suppose I should have been more specific about what I thought Rich might want to review. Specifically, his tutorial prose has been significantly edited and so I wanted Rich to have an opportunity to see those changes before publication. I am still in the process of making the system more ANS compliant, so I’m not yet ready to publish. However, if anyone would like an advance copy, please drop me a note: mailto:jlarson43@juno.com

    • rich

      I’d say just go ahead and publish. It’s public domain after all — designed to be distributed with the least friction possible.

  10. Ok, Forth Fans:
    http://www.dst-corp.com/james/JonesForthInC-V148.html
    This isn’t the finished version, but something I hope will generate some buzz.

  11. Luke

    Excellent tutorial!
    I had some trouble running this, but once I followed the comment by Arto Bendiken posted at http://subvert-the-dominant-paradigm.net/blog/?p=54, “make test” works fine.
    “Note that if you attempt to run this on recent versions of Linux and the program simply aborts and prints out “Killed”, you will need to recompile without the “-Wl,-Ttext,0″ option to GCC.”

    • rich

      Thanks — I wonder what changed. Note that we do assume the text starts at address zero.

      • Ralph

        Hi Rich,

        This behaviour is caused by SELinux. It is trapping the attempted access of zero page. Just ran into it myself. It’s possible to add an exception, or just switch off SELinux… though the path of least resistance is probably to move the start address up.

      • rich

        That’s annoying to say the least! I guess this is related to the new execmem stuff that SELinux is controlling.

      • This may have nothing to do with SELinux. Newer Linux kernels have a feature which allows to protect an area of low virtual memory from userspace allocation (configured by CONFIG_DEFAULT_MMAP_MIN_ADDR), which can help reduce the impact of kernel NULL pointer bugs.
        Get (or change) the current value by reading (or writing) /proc/sys/vm/mmap_min_addr

        Source: http://www.linuxquestions.org/questions/linux-newbie-8/why-exactly-was-my-process-killed-818734/

        On my system, `cat /proc/sys/vm/mmap_min_addr` returns 4096, so I updated the linker options to `-Wl,-Ttext,1000` (note: the address must be specified in hex!), and everything works well.

  12. Pingback: regular expressions - Page 8

  13. Alvin P. Schmitt

    Hi – I am new to FORTH and just found your FORTH the other day. Like how it is commented so well. I would like to implement it on a Microchip PIC24 computer. The PIC series is Harvard architecture with code in flash and data in ram so it may not be possible to implement assembly code in ram as all code goes into flash. I may be all wet in this and have not thought it fully out. I guess since much of FORTH is written in FORTH the assembler instructions could be in flash and the FORTH added words could be in ram. Any ideas you have would be greatly appreciated.

    • rich

      It does look as if this chip was not designed to fetch instructions from RAM, and therefore you’d have trouble compiling assembly or inline words and running them (on any FORTH). I believe that compiled high level words would be OK. It would be fun finding out.

      Good luck anyway!

      • Alvin P. Schmitt

        Being a REAL NEWBIE at this it looks to me that the core forth has words with code modules that can be branched to. Then the rest of the system is in character FORTH words which could be put in ram. Is that true? That may work on a Harvard arch.

      • rich

        Any ordinary words don’t require running machine code from RAM, eg:

        : DOUBLE * 2 ;
        

        However any INLINE or ;CODE words would, eg:

        : 2DROP INLINE DROP INLINE DROP ;CODE
        

        Also any word using C, would be suspicious (but not necessarily a problem).

        This only applies to the interpreted FORTH code. Any primitives are fine because they live in the assembled text segment which would be stored in the Flash ROM.

  14. Kevin Porter

    Hi I’ve just discovered Jonesforth and wanted to say thank you for writing & releasing it, it’s a really great introduction into forth implementation.

    I wanted to make one remark about a comment in the sources: you mention the “strange forth convention” that “the comparison words should return all (binary) 1′s for TRUE and all 0′s for FALSE”.

    I think the reason for this convention is that so that the words AND, OR, XOR and INVERT can function both as logical operators and as bitwise operators.

    By comparison, with the C convention that FALSE = 0 and TRUE = 1, you need two sets of operators: && and &, || and |, etc..

    So there is method to the strangeness.

  15. Hi, thanks for this great work!
    One question, the “standard-fixed” versions also mention that while/repeat were not originally standard compliant. I am curious in what cases the existing implementation was wrong? I have been using it a lot and it seems to work fine for my purposes :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s