{"id":17569078,"url":"https://github.com/riywo/llforth","last_synced_at":"2025-04-28T11:40:49.287Z","repository":{"id":53865316,"uuid":"130938630","full_name":"riywo/llforth","owner":"riywo","description":"Experimental implementation of Forth in LLVM","archived":false,"fork":false,"pushed_at":"2018-12-26T10:20:33.000Z","size":172,"stargazers_count":41,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T09:11:34.216Z","etag":null,"topics":["c-plus-plus-17","forth","llvm","rust"],"latest_commit_sha":null,"homepage":"https://link.medium.com/7YfIIkOyXS ","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/riywo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-25T02:19:35.000Z","updated_at":"2024-12-30T17:08:26.000Z","dependencies_parsed_at":"2022-08-28T06:24:21.223Z","dependency_job_id":null,"html_url":"https://github.com/riywo/llforth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riywo%2Fllforth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riywo%2Fllforth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riywo%2Fllforth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riywo%2Fllforth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riywo","download_url":"https://codeload.github.com/riywo/llforth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251306558,"owners_count":21568289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus-17","forth","llvm","rust"],"created_at":"2024-10-21T17:09:00.363Z","updated_at":"2025-04-28T11:40:49.263Z","avatar_url":"https://github.com/riywo.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLForth [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/riywo/llforth/blob/master/LICENSE.txt)\nExperimental Forth implementation in LLVM.\n\nIntroduction blog post is here: https://medium.com/@riywo/llforth-experimental-implementation-of-forth-in-llvm-2298c76ec3ac\n\n## Summary\nThis software is built for a personal research to understand computer architecture. Implementing stack-based programming language([Forth](https://en.wikipedia.org/wiki/Forth_(programming_language))) using a register-based virtual machine ([LLVM](https://en.wikipedia.org/wiki/LLVM)) is useful to know both machine/language architecture.\n\nLLForth uses following technique:\n\n- Restricted static compiler (`llforthc`) from Forth to LLVM Intermediate Representation (LLVM IR) and Full feature interpreter (`llforth`) written in Forth and compiled by `llforthc`\n- [Indirect Threaded Code (ITC)](https://en.wikipedia.org/wiki/Threaded_code#Indirect_threading) to implement inner interpreter by LLVM IR\n- Naive memory implementation for Stack and Return Stack by LLVM IR\n- Partial memory cell for only word definitions excluding string of name of words\n- [Foreign Function Interface](https://en.wikipedia.org/wiki/Foreign_function_interface) to delegate platform dependent features (e.g. stdio) to [Rust](https://www.rust-lang.org/) and share it between compiler and interpreter\n\n## Getting started\n\n### Prerequisites (versions are tested by the author)\n- CMake (3.13.2)\n- LLVM (7.0.0)\n    - lit (from [PyPI](https://pypi.org/project/lit/) or under LLVM source code)\n- Rust (1.31.1)\n\n### Build\nAll required steps are declared in `CMakeLists.txt` including compiling Rust library, so you just need to execute CMake build:\n\n```sh\n$ mkdir cmake-build-debug\n$ cd cmake-build-debug\n# If you install LLVM outside default path like Homebrew:\n# export LLVM_DIR=/usr/local/opt/llvm/lib/cmake\n$ cmake ..\n$ make llforth\n```\n\n### Execution\n`llforth` is statically linked with required libraries except `libc`:\n\n```sh\n$ otool -L ./llforth\n./llforth:\n\t/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)\n```\n\nTherefore, you can execute it easily:\n\n```sh\n$ ./llforth --help\nllforth 0.1\n\nUSAGE:\n    llforth [FILE]\n\nFLAGS:\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n\nARGS:\n    \u003cFILE\u003e    Source file\n```\n\n## Usage\n`llforth` can read from both stdin and source file. For example, you can run it interectively powered by [Rustyline](https://crates.io/crates/rustyline/) which is Readline like library: \n\n```sh\n$ ./llforth\n\u003e 1 1 + .\n2\n\u003e : hi .\" Hello world!\" ;\n\n\u003e hi\nHello world!\n```\n\nAlso, you can input via stdin non-interectively:\n\n```sh\n$ echo '1 2 + .' | ./llforth\n3\n```\n\nFinally, you can read a source file on your file system:\n\n```sh\n$ echo '1 2 + .' \u003e /tmp/test.fs \u0026\u0026 ./llforth /tmp/test.fs\n3\n```\n\n## Supported words\nSee https://github.com/riywo/llforth/wiki/Supported-words\n\n## Architecture\nSee https://github.com/riywo/llforth/wiki/Architecture\n\n## Acknowledgments\n\n### Low-Level Programming / Forthress\nThis project is heavily inspired from a book [*\"Low-Level Programming\"*](https://amzn.to/2BBYugn) which has a great section for implementing Forth using x86_64 assembly only. The code base is also available from the author's repository called [Forthress](https://github.com/sayon/forthress) under MIT License. Most of architectures of LLForth are borrowed from Forthless, for example ITC, Memory cell, etc.\n\n### Series of posts on the evolution of TransForth\nOn top of the assembly implementation mirrored from Forthress, I implemented some forth words *by* forth, for example `if ... else ... then` or `begin ... until`. Those words are borrowed from [*\"Series of posts on the evolution of TransForth\"*](https://blogs.msdn.microsoft.com/ashleyf/tag/transforth/) which are awesome read to understand Forth architecture. The code base is also available on [TransForth](https://github.com/AshleyF/TransForth) under MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friywo%2Fllforth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friywo%2Fllforth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friywo%2Fllforth/lists"}