Giter Club home page Giter Club logo

fforth's Introduction

fforth

What?

fforth is a small, reasonably fast indirect-threaded Forth written in portable C. It should Just Compile on most Unixy platforms. It's intended as a scripting language for the Fuzix operating system but should work fine on any small system. It's got reasonably complete basic bindings to most Unix ssystem calls --- expect the functions to be there, although any constants probably aren't.

It supports most of the core ANS Forth words, and passes (most of) John Hayes' ANS conformance test. Or at least that of the version I found.

For reference, here is the version of the standard I've been referring to.

Word matching is CaSE INsenSITive, which I normally loathe, but seems to be standard in Forth dialects.

Peculiarities include:

  • DOES>

    ANS Forth decrees that you can call DOES> multiple times on a word, where each time it changes the code part of the word. fforth doesn't support that --- you can only call DOES> once. (Because I haven't figured out how to make this work with fforth's non-traditional word architecture.)

  • READ-FILE filename

    Opens and then executes Forth code supplied in the named file.

There are also a few useful features for debugging, such as slightly useful stack traces when errors occur and optional (at compile time) stack bounds checking. There are probably also lots of exciting bugs.

Where?

It's open source on GitHub!

How?

If you want to use it:

cc -o fforth fforth.c

If you want to change it:

sh fforth.c
cc -o fforth fforth.c

Yes! The source file is both a C program and a shell script (and an awk script, and Forth source). When run as a shell script it byte-compiles the Forth definitions in the C program and regenerates the Forth dictionary --- this is too fragile to do by hand. The comments in the source should explain what does what, but to summarise:

  • //@W: marks a dictionary entry. This will get updated in place to form a linked list.

  • //@C: cheesy™ precompiled Forth. Put semi-Forth code on the following comment lines; the line immediately afterwards will be updated to contain the byte- compiled version. Don't put a trailing semicolon. Only a limited subset of the language is supported (no strings, no immediate word execution).

  • //@E: patches up the attached statement to refer to the last word defined.

In addition, there are some C compilation options:

  • -DFAST: don't bounds check the stack (smaller, faster code).

  • -DMEMORY=xxx: allocate xxx bytes for the memory pool. This is a fixed size and won't be extended if it fills up.

  • -DSBRK: allocate memory with sbrk() rather than a fixed pool. This will be extended if it fills up. If it cannot be extended due to non-contiguous sbrk() memory, the interpeter will panic.

  • -DTRACING: trace almost all details of execution of each instruction; extremely verbose but useful for figuring out why things crash.

No evil was harmed in the making of this file. Probably.

Who?

fforth was written by me, David Given. You may contact me at [email protected], or visit my website at http://www.cowlark.com. There may or may not be anything interesting there.

License?

fforth is © 2015-2019 David Given. It's licensed under the terms of the 2-clause BSD license (tl;dr: do what you like but don't claim you own it). See the LICENSE file in the source distribution for details.

As an exception, the fforth_tests.fth file was written by John Hayes and is © 1995 Johns Hopkins University / Applied Physics Laboratory. It's freely distributable --- see the comment at the top of the file for information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.