Coder Social home page Coder Social logo

iri / forth-gcc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ccurl/forth-gcc

0.0 0.0 0.0 1.23 MB

My personal version of Forth, written in C for GCC

License: GNU General Public License v2.0

C 22.81% Assembly 65.85% Forth 3.73% Batchfile 0.38% AngelScript 7.18% GLSL 0.06%

forth-gcc's Introduction

Forth-GCC

This is a simple token-threaded (byte-code) implementation of Forth, written in C for GCC.

Yes, I know ... ANOTHER Forth implementation. This one creates a "bare metal" Forth virtual machine. The goal of this project is to create a basic, easy to understand, and easily extendable implementation of a Forth virtual machine. To that end, the virtual CPU has less than 50 instructions, which make up the VM's opcodes. They are also the Forth system's primitives. See "Shared.h" for that list.

Any collaboration on this project would be warmly welcomed. :)

The cpu_loop() function in "forth-vm.c" is the implementation of the virtual CPU loop. This is where all the fun is.

To create the initial image for the VM, I created a simple, Forth-like compiler/assembler. It generates an in-memory image of the VM's desired initial state from the -i: file (forth.src). Another program, forth-dis, creates a listing file in the file named by -o:. A casual inspection of the disassembly will show that the entire system is just a Forth dictionary.

The compiler creates a VM with the dictionary and code separated. That way, it would be possible to distribute just the code without the dictionary, if desired.

When the VM boots, its start up code loads the -i: file (forth.bin) to create the initial image of the VM, and then starts executing at address 0, which is just a JUMP to the "main" word. If there is no "main", then it jumps to the last word defined.

There are 3 programs here, and a make.bat to facilitate building them:

forth-compiler.exe - compiles the image for a basic forth vm ...

usage: forth-compiler [args]
	-i:inputFile (full or relative path)
		default inputFile is forth.src
	-o:outputFile (full or relative path)
		default outputFile is forth.bin
	-a:(0|1) - include assembler words
		default value is 1
	-m:<KB> - Memory size in KB
		default value is 64
	-t (set log level to trace)
	-d (set log level to debug)
	-? (prints this message)

forth-dis.exe - dis-assembles a given forth vm ...

usage: forth-compiler [args]
        -i:inputFile (full or relative path)
            default inputFile is forth.bin
        -o:outputFile (full or relative path)
            default outputFile is forth.lst
        -t (set log level to trace)
        -d (set log level to debug)

forth.exe - runs a given forth vm ...

usage: forth [args]
        -i:imagefile (default imageFile is 'forth.bin')
        -l:loglevel (0=off, 1=debug, 2=trace - default is 0)
        -? (prints this message)

To build them, execute:

make fc
make fd
make forth

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.