All Projects → howerj → embed

howerj / embed

Licence: MIT license
An embeddable, tiny Forth interpreter with metacompiler.

Programming Languages

forth
179 projects
c
50402 projects - #5 most used programming language
Roff
2310 projects

Projects that are alternatives of or similar to embed

Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 79 (-1.25%)
Mutual labels:  interpreter, embeddable, virtual-machine
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 101 (+26.25%)
Mutual labels:  interpreter, embeddable, virtual-machine
ol
Otus Lisp (Ol in short) is a purely* functional dialect of Lisp.
Stars: ✭ 157 (+96.25%)
Mutual labels:  interpreter, virtual-machine, tiny
Go.vm
A simple virtual machine - compiler & interpreter - written in golang
Stars: ✭ 178 (+122.5%)
Mutual labels:  interpreter, virtual-machine
Szl
A lightweight, embeddable scripting language
Stars: ✭ 134 (+67.5%)
Mutual labels:  interpreter, embeddable
Kivm
🌟This is a pure C++ implementation of Java Virtual Machine (only Java 8 is supported). Inspired by Hotspot In Action.
Stars: ✭ 137 (+71.25%)
Mutual labels:  interpreter, virtual-machine
Arturo
Simple, expressive & portable programming language for efficient scripting
Stars: ✭ 225 (+181.25%)
Mutual labels:  interpreter, virtual-machine
Cub
The Cub Programming Language
Stars: ✭ 198 (+147.5%)
Mutual labels:  interpreter, virtual-machine
Freeze-OS
An Operating System that runs on top of an interpreter.
Stars: ✭ 24 (-70%)
Mutual labels:  interpreter, virtual-machine
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀
Stars: ✭ 38 (-52.5%)
Mutual labels:  interpreter, virtual-machine
LLVM-JVM
[W.I.P] A Just-In-Time Java Virtual Machine written in Haskell
Stars: ✭ 22 (-72.5%)
Mutual labels:  interpreter, virtual-machine
Simple
The Simple Intelligent and Modular Programming Language and Environment
Stars: ✭ 120 (+50%)
Mutual labels:  interpreter, virtual-machine
Quickjs
The official repo is at bellard/quickjs.
Stars: ✭ 1,429 (+1686.25%)
Mutual labels:  interpreter, virtual-machine
Lioness
The Lioness Programming Language
Stars: ✭ 155 (+93.75%)
Mutual labels:  interpreter, virtual-machine
Libforth
libforth: A small Forth interpreter that can be used as a library written in c99
Stars: ✭ 107 (+33.75%)
Mutual labels:  interpreter, virtual-machine
Swift Lispkit
Interpreter framework for Lisp-based extension and scripting languages on macOS and iOS. LispKit is based on the R7RS standard for Scheme. Its compiler generates bytecode for a virtual machine. LispKit is fully implemented in Swift 5.
Stars: ✭ 228 (+185%)
Mutual labels:  interpreter, virtual-machine
Laythe
A gradually typed language originally based on the crafting interpreters series
Stars: ✭ 58 (-27.5%)
Mutual labels:  interpreter, virtual-machine
Cymbal
Yet another Rust implementation of the Monkey language from "Writing an Interpreter in Go" and "Writing a Compiler in Go"
Stars: ✭ 49 (-38.75%)
Mutual labels:  interpreter, virtual-machine
Lily
This repository has moved: https://gitlab.com/FascinatedBox/lily
Stars: ✭ 1,081 (+1251.25%)
Mutual labels:  interpreter, embeddable
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+3402.5%)
Mutual labels:  interpreter, virtual-machine

embed: A tiny embeddable Forth interpreter

Project Embed Forth VM and eForth Image
Author Richard James Howe
Copyright 2017-2018 Richard James Howe
License MIT
Email [email protected]
Website https://github.com/howerj/embed
  ______           _              _ 
 |  ____|         | |            | |
 | |__   _ __ ___ | |__   ___  __| |
 |  __| | '_ ` _ \| '_ \ / _ \/ _` |
 | |____| | | | | | |_) |  __/ (_| |
 |______|_| |_| |_|_.__/ \___|\__,_|
     ______         _   _           
    |  ____|       | | | |          
    | |__ ___  _ __| |_| |__        
    |  __/ _ \| '__| __| '_ \       
    | | | (_) | |  | |_| | | |      
    |_|  \___/|_|   \__|_| |_|      

This project contains a tiny 16-bit Virtual Machine (VM) optimized to execute Forth. It is powerful and well developed enough to be self hosted, the VM and Forth interpreter image can be used to recreate a new image from source (which is in embed.fth). embed.fth contains a more complete description of the Forth interpreter, the virtual machine (which is only ~400 Lines of C code) and how a Forth "meta-compiler" works.

The virtual machine is available as a library, as well, so it can be embedded into another project, hence the project name. The virtual machine (embed.c and embed.h), the eForth image (image.c), and the metacompiler (embed.fth) are all licensed under the MIT License.

Feel free to email me about any problems, or open up an issue on GitHub.

Program Operation

To build the project you will need a C compiler, and make. The system should build under Linux and Windows (MinGW). After installing make and a C99 compiler, simply type "make" to build the Forth virtual machine. An image containing a working Forth implementation is contained within image.c, which is built into the executable.

Linux/Unixen:

./embed

Windows:

embed.exe

To exit the virtual machine cleanly either type bye and then hit return, or press CTRL+D (on Linux) / CTRL+Z (on Windows) and then return.

The source code for image.c is provided in embed.fth, which contains an explanation on how a Forth cross compiler works (know as a metacompiler in Forth terminology) as well as a specification for the virtual machine and a little about Forth itself.

If you do not have a copy of make, but do have a C99 compiler, the following command should build the project:

cc -std=c99 main.c embed.c image.c util.c -o embed

Generating a new image is easy as well (using the built in image):

./embed -o new.blk embed.fth

We can then use the new image to generate a further image:

./embed -o new2.blk -i new.blk embed.fth

Ad infinitum, the two newly generated images should be byte for byte equal.

Unit tests can be ran typing:

make test                      # Using make
./embed -o unit.blk t/unit.fth # manual invocation

Project Organization

  • embed.c: The Embed Virtual Machine
  • embed.h: The Embed Virtual Machine library interface
  • main.c: Test driver for the Virtual Machine Library
  • image.c: A Forth interpreter image, C code
  • embed.fth: A meta compiler and a Forth interpreter
  • unit.fth: Unit tests for the eForth image

Example Programs and Tests

Example programs and tests exist under the 't/' directory, these include test programs written in C that can extend the virtual machine with new functionality or change the input and out mechanisms to the virtual machine.

  • call.c: Extends the virtual machine with floating point operations
  • unix.c: Unix non-blocking and raw terminal I/O handling test
  • win.c: Windows equivalent of unix.c.

Project Goals

The goal of the project is to create a VM which is tiny, embeddable, customizable through callbacks and most importantly self-hosting. It achieves all of these goals, but might fall short.

  • Self-Hosting Metacompiler
  • Man pages
  • Document project
  • Forth Unit tests
  • C Unit tests, to test the library API
  • C Test programs
    • Test applications for Windows/Unix non-block I/O, and callback extensions.
  • Port the library to a small microcontroller (see https://github.com/howerj/arduino)
  • Create a cross compiler for the H2 Forth CPU (see the 'h2' branch of this project and https://github.com/howerj/forth-cpu).
  • Change the 'embed' virtual machine so it more closely resembles the 'H2 CPU' (see the 'h2' branch for this here https://github.com/howerj/embed/tree/h2). There are some problems with this branch, like the fact that it gets rid of most of the documentation, which should have been reworked instead.
  • Restructure the dictionary so that word names/code are kept separately like in most traditional Forth systems. This should make code reused easier and the implementation of 'FORGET' easier as well. This may also require Run Length Encoding of the image to keep its size down as the code and dictionary would be stored in non-contiguous memory locations.
  • Virtual Machine and eForth Image/Metacompiler that uses 'uintptr_t'
  • Simplify the API. Currently the API is too complex and needs rethinking, it is flexible, but complex, and the user has to think too much about the implementation details.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].