398 lines
18 KiB
Markdown
398 lines
18 KiB
Markdown
# milliForth
|
||
|
||
**Source:** https://github.com/fuzzballcat/milliForth
|
||
|
||
GitHub - fuzzballcat/milliForth: A FORTH in 340 bytes — the smallest real programming language ever as of yet.
|
||
|
||
|
||
|
||
[Skip to content](#start-of-content)
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
## Navigation Menu
|
||
|
||
Toggle navigation
|
||
|
||
[Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Ffuzzballcat%2FmilliForth)
|
||
|
||
Appearance settings
|
||
|
||
* Platform
|
||
|
||
+ AI CODE CREATION
|
||
- [GitHub CopilotWrite better code with AI](https://github.com/features/copilot)
|
||
- [GitHub SparkBuild and deploy intelligent apps](https://github.com/features/spark)
|
||
- [GitHub ModelsManage and compare prompts](https://github.com/features/models)
|
||
- [MCP RegistryNewIntegrate external tools](https://github.com/mcp)
|
||
+ DEVELOPER WORKFLOWS
|
||
- [ActionsAutomate any workflow](https://github.com/features/actions)
|
||
- [CodespacesInstant dev environments](https://github.com/features/codespaces)
|
||
- [IssuesPlan and track work](https://github.com/features/issues)
|
||
- [Code ReviewManage code changes](https://github.com/features/code-review)
|
||
+ APPLICATION SECURITY
|
||
- [GitHub Advanced SecurityFind and fix vulnerabilities](https://github.com/security/advanced-security)
|
||
- [Code securitySecure your code as you build](https://github.com/security/advanced-security/code-security)
|
||
- [Secret protectionStop leaks before they start](https://github.com/security/advanced-security/secret-protection)
|
||
+ EXPLORE
|
||
- [Why GitHub](https://github.com/why-github)
|
||
- [Documentation](https://docs.github.com)
|
||
- [Blog](https://github.blog)
|
||
- [Changelog](https://github.blog/changelog)
|
||
- [Marketplace](https://github.com/marketplace)
|
||
|
||
[View all features](https://github.com/features)
|
||
* Solutions
|
||
|
||
+ BY COMPANY SIZE
|
||
- [Enterprises](https://github.com/enterprise)
|
||
- [Small and medium teams](https://github.com/team)
|
||
- [Startups](https://github.com/enterprise/startups)
|
||
- [Nonprofits](https://github.com/solutions/industry/nonprofits)
|
||
+ BY USE CASE
|
||
- [App Modernization](https://github.com/solutions/use-case/app-modernization)
|
||
- [DevSecOps](https://github.com/solutions/use-case/devsecops)
|
||
- [DevOps](https://github.com/solutions/use-case/devops)
|
||
- [CI/CD](https://github.com/solutions/use-case/ci-cd)
|
||
- [View all use cases](https://github.com/solutions/use-case)
|
||
+ BY INDUSTRY
|
||
- [Healthcare](https://github.com/solutions/industry/healthcare)
|
||
- [Financial services](https://github.com/solutions/industry/financial-services)
|
||
- [Manufacturing](https://github.com/solutions/industry/manufacturing)
|
||
- [Government](https://github.com/solutions/industry/government)
|
||
- [View all industries](https://github.com/solutions/industry)
|
||
|
||
[View all solutions](https://github.com/solutions)
|
||
* Resources
|
||
|
||
+ EXPLORE BY TOPIC
|
||
- [AI](https://github.com/resources/articles?topic=ai)
|
||
- [Software Development](https://github.com/resources/articles?topic=software-development)
|
||
- [DevOps](https://github.com/resources/articles?topic=devops)
|
||
- [Security](https://github.com/resources/articles?topic=security)
|
||
- [View all topics](https://github.com/resources/articles)
|
||
+ EXPLORE BY TYPE
|
||
- [Customer stories](https://github.com/customer-stories)
|
||
- [Events & webinars](https://github.com/resources/events)
|
||
- [Ebooks & reports](https://github.com/resources/whitepapers)
|
||
- [Business insights](https://github.com/solutions/executive-insights)
|
||
- [GitHub Skills](https://skills.github.com)
|
||
+ SUPPORT & SERVICES
|
||
- [Documentation](https://docs.github.com)
|
||
- [Customer support](https://support.github.com)
|
||
- [Community forum](https://github.com/orgs/community/discussions)
|
||
- [Trust center](https://github.com/trust-center)
|
||
- [Partners](https://github.com/partners)
|
||
* Open Source
|
||
|
||
+ COMMUNITY
|
||
- [GitHub SponsorsFund open source developers](https://github.com/sponsors)
|
||
+ PROGRAMS
|
||
- [Security Lab](https://securitylab.github.com)
|
||
- [Maintainer Community](https://maintainers.github.com)
|
||
- [Accelerator](https://github.com/accelerator)
|
||
- [Archive Program](https://archiveprogram.github.com)
|
||
+ REPOSITORIES
|
||
- [Topics](https://github.com/topics)
|
||
- [Trending](https://github.com/trending)
|
||
- [Collections](https://github.com/collections)
|
||
* Enterprise
|
||
|
||
+ ENTERPRISE SOLUTIONS
|
||
- [Enterprise platformAI-powered developer platform](https://github.com/enterprise)
|
||
+ AVAILABLE ADD-ONS
|
||
- [GitHub Advanced SecurityEnterprise-grade security features](https://github.com/security/advanced-security)
|
||
- [Copilot for BusinessEnterprise-grade AI features](https://github.com/features/copilot/copilot-business)
|
||
- [Premium SupportEnterprise-grade 24/7 support](https://github.com/premium-support)
|
||
* [Pricing](https://github.com/pricing)
|
||
|
||
Search or jump to...
|
||
|
||
|
||
# Search code, repositories, users, issues, pull requests...
|
||
|
||
Search
|
||
|
||
Clear
|
||
|
||
[Search syntax tips](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax)
|
||
|
||
# Provide feedback
|
||
|
||
We read every piece of feedback, and take your input very seriously.
|
||
|
||
|
||
Include my email address so I can be contacted
|
||
|
||
Cancel
|
||
Submit feedback
|
||
|
||
|
||
|
||
|
||
|
||
# Saved searches
|
||
|
||
## Use saved searches to filter your results more quickly
|
||
|
||
Name
|
||
|
||
Query
|
||
|
||
To see all available qualifiers, see our [documentation](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax).
|
||
|
||
Cancel
|
||
Create saved search
|
||
|
||
[Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Ffuzzballcat%2FmilliForth)
|
||
|
||
[Sign up](/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E&source=header-repo&source_repo=fuzzballcat%2FmilliForth)
|
||
|
||
Appearance settings
|
||
|
||
Resetting focus
|
||
|
||
You signed in with another tab or window. Reload to refresh your session.
|
||
You signed out in another tab or window. Reload to refresh your session.
|
||
You switched accounts on another tab or window. Reload to refresh your session.
|
||
|
||
|
||
|
||
Dismiss alert
|
||
|
||
{{ message }}
|
||
|
||
[fuzzballcat](/fuzzballcat)
|
||
/
|
||
**[milliForth](/fuzzballcat/milliForth)**
|
||
Public
|
||
|
||
* [Notifications](/login?return_to=%2Ffuzzballcat%2FmilliForth) You must be signed in to change notification settings
|
||
* [Fork
|
||
28](/login?return_to=%2Ffuzzballcat%2FmilliForth)
|
||
* [Star
|
||
623](/login?return_to=%2Ffuzzballcat%2FmilliForth)
|
||
|
||
A FORTH in 340 bytes — the smallest real programming language ever as of yet.
|
||
|
||
### License
|
||
|
||
[MIT license](/fuzzballcat/milliForth/blob/master/LICENSE)
|
||
|
||
[623
|
||
stars](/fuzzballcat/milliForth/stargazers) [28
|
||
forks](/fuzzballcat/milliForth/forks) [Branches](/fuzzballcat/milliForth/branches) [Tags](/fuzzballcat/milliForth/tags) [Activity](/fuzzballcat/milliForth/activity)
|
||
|
||
[Star](/login?return_to=%2Ffuzzballcat%2FmilliForth)
|
||
|
||
[Notifications](/login?return_to=%2Ffuzzballcat%2FmilliForth) You must be signed in to change notification settings
|
||
|
||
* [Code](/fuzzballcat/milliForth)
|
||
* [Issues
|
||
6](/fuzzballcat/milliForth/issues)
|
||
* [Pull requests
|
||
1](/fuzzballcat/milliForth/pulls)
|
||
* [Actions](/fuzzballcat/milliForth/actions)
|
||
* [Projects
|
||
0](/fuzzballcat/milliForth/projects)
|
||
* [Security
|
||
0](/fuzzballcat/milliForth/security)
|
||
* [Insights](/fuzzballcat/milliForth/pulse)
|
||
|
||
Additional navigation options
|
||
|
||
|
||
* [Code](/fuzzballcat/milliForth)
|
||
* [Issues](/fuzzballcat/milliForth/issues)
|
||
* [Pull requests](/fuzzballcat/milliForth/pulls)
|
||
* [Actions](/fuzzballcat/milliForth/actions)
|
||
* [Projects](/fuzzballcat/milliForth/projects)
|
||
* [Security](/fuzzballcat/milliForth/security)
|
||
* [Insights](/fuzzballcat/milliForth/pulse)
|
||
|
||
# fuzzballcat/milliForth
|
||
|
||
master
|
||
|
||
[Branches](/fuzzballcat/milliForth/branches)[Tags](/fuzzballcat/milliForth/tags)
|
||
|
||
Go to file
|
||
|
||
Code
|
||
|
||
Open more actions menu
|
||
|
||
## Folders and files
|
||
|
||
| Name | | Name | Last commit message | Last commit date |
|
||
| --- | --- | --- | --- | --- |
|
||
| Latest commit History[42 Commits](/fuzzballcat/milliForth/commits/master/) 42 Commits | | |
|
||
| [.gitignore](/fuzzballcat/milliForth/blob/master/.gitignore ".gitignore") | | [.gitignore](/fuzzballcat/milliForth/blob/master/.gitignore ".gitignore") | | |
|
||
| [LICENSE](/fuzzballcat/milliForth/blob/master/LICENSE "LICENSE") | | [LICENSE](/fuzzballcat/milliForth/blob/master/LICENSE "LICENSE") | | |
|
||
| [README.md](/fuzzballcat/milliForth/blob/master/README.md "README.md") | | [README.md](/fuzzballcat/milliForth/blob/master/README.md "README.md") | | |
|
||
| [bf.FORTH](/fuzzballcat/milliForth/blob/master/bf.FORTH "bf.FORTH") | | [bf.FORTH](/fuzzballcat/milliForth/blob/master/bf.FORTH "bf.FORTH") | | |
|
||
| [hello\_world.FORTH](/fuzzballcat/milliForth/blob/master/hello_world.FORTH "hello_world.FORTH") | | [hello\_world.FORTH](/fuzzballcat/milliForth/blob/master/hello_world.FORTH "hello_world.FORTH") | | |
|
||
| [makefile](/fuzzballcat/milliForth/blob/master/makefile "makefile") | | [makefile](/fuzzballcat/milliForth/blob/master/makefile "makefile") | | |
|
||
| [py\_autotype.py](/fuzzballcat/milliForth/blob/master/py_autotype.py "py_autotype.py") | | [py\_autotype.py](/fuzzballcat/milliForth/blob/master/py_autotype.py "py_autotype.py") | | |
|
||
| [sector.asm](/fuzzballcat/milliForth/blob/master/sector.asm "sector.asm") | | [sector.asm](/fuzzballcat/milliForth/blob/master/sector.asm "sector.asm") | | |
|
||
| [sector.bin](/fuzzballcat/milliForth/blob/master/sector.bin "sector.bin") | | [sector.bin](/fuzzballcat/milliForth/blob/master/sector.bin "sector.bin") | | |
|
||
| View all files | | |
|
||
|
||
## Repository files navigation
|
||
|
||
* [README](#)
|
||
* [MIT license](#)
|
||
|
||
# milliForth
|
||
|
||
A FORTH in 336 bytes — the smallest real programming language ever, as of yet.
|
||
|
||
[](https://private-user-images.githubusercontent.com/57006511/280563430-ef3d48cf-1581-4574-8625-8d97b00acaca.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzE1MzU2MzMsIm5iZiI6MTc3MTUzNTMzMywicGF0aCI6Ii81NzAwNjUxMS8yODA1NjM0MzAtZWYzZDQ4Y2YtMTU4MS00NTc0LTg2MjUtOGQ5N2IwMGFjYWNhLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAyMTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMjE5VDIxMDg1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxNDY0NDE3Y2Y5ZDJlNzZjODJmMzg3Y2UxOTc0YzZkMmRkNTAxYzlhNjlmMzY0M2QwNTI1ZmFlNWZmN2I3MzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.i685Rg4zicP8T5zIc3OkurV6p1baueZnnnr_PEWah3c)
|
||
*The code in the above gif, that of [an older version of] `hello_world.FORTH`, is a modified version of the hello world program used by sectorFORTH (see below)*
|
||
|
||
## bytes?
|
||
|
||
Yes, bytes. This is a FORTH so small it fits in a 512-byte boot sector. This isn't new — sectorFORTH[1](#user-content-fn-1-d37e1f81f2eea8c6e7bde869760db32c) successfully fit a FORTH within the boot sector. However, milliFORTH appears to be *the smallest* "real" programming language implementation ever, beating out sectorLISP[2](#user-content-fn-2-d37e1f81f2eea8c6e7bde869760db32c), a mind-blowing 436 byte implementation of LISP, by 96 bytes. ("real" excludes esolangs and other non-production languages - for example, the sectorLISP author's implementation of BF is just 99 bytes, but it clearly isn't used to any serious capacity.) It's now even smaller thanks to some really neat suggestions!
|
||
|
||
## Is it turing-complete?
|
||
|
||
Yes! This project now includes `bf.FORTH`, a compliant brainfuck interpreter, to illlustrate that this is truly a real language.
|
||
|
||
## Language
|
||
|
||
sectorFORTH[1](#user-content-fn-1-d37e1f81f2eea8c6e7bde869760db32c) was an extensive guide throughout the process of implementing milliFORTH, and milliFORTH's design actually converged on sectorFORTH unintentionally in a few areas. That said, the language implemented is intentionally very similar, being the 'minimal FORTH'.
|
||
|
||
FORTH itself will not be explained here (prior understanding assumed). Being so small, milliFORTH contains just a handful of words:
|
||
|
||
| Word | Signature | Function |
|
||
| --- | --- | --- |
|
||
| `@` | `( addr -- value )` | Get a value at an address |
|
||
| `!` | `( value addr -- )` | Store a value at an address |
|
||
| `sp@` | `( -- sp )` | Get pointer to top of the data stack |
|
||
| `rp@` | `( -- rp )` | Get pointer to top of the return stack |
|
||
| `0#` | `( value -- flag )` | Check if a value does not equal zero (-1 = TRUE, 0 = FALSE) |
|
||
| `+` | `( a b -- a+b )` | Sum two numbers |
|
||
| `nand` | `( a b -- aNANDb )` | NAND two numbers |
|
||
| `exit` | `( r:addr -- )` | Pop from the return stack, resume execution at the popped address |
|
||
| `key` | `( -- key )` | Read a keystroke |
|
||
| `emit` | `( char -- )` | Print out an ASCII character |
|
||
| `s@` | `( -- s@ )` | The "state struct" pointer. The cells of this struct are, in order: * `state`: The state of the interpreter (0 = compile words, 1 = execute words) * `>in`: Pointer to the current offset into the terminal input buffer * `latest`: The pointer to the most recent dictionary space * `here`: The pointer to the next available space in the dictionary |
|
||
|
||
On a fundamental level, milliFORTH the same FORTH as implemented by sectorFORTH, with a few modifications:
|
||
|
||
* All of the interpreter state words are bundled into a single struct (`s@`).
|
||
* Words don't get hidden while you are defining them. This doesn't really hinder your actual ability to write programs, but rather makes it possible to hang the interpreter if you do something wrong in this respect.
|
||
* There's no `tib` (terminal input buffer) word, because `tib` always starts at `0x0000`, so you can just use `>in` and don't need to add anything to it.
|
||
* In the small (production) version, the delete key doesn't work. I think this is fair since sectorLISP doesn't handle backspace either; even if you add it back, milliFORTH is still smaller by a few bytes.
|
||
* Error handling is even sparser. Successful input results in nothing (no familiar `ok.`). Erroneous input prints an extra blank line between the previous input and the next prompt.
|
||
|
||
## Use
|
||
|
||
sector.bin is an assembled binary of sector.asm. You can run it using `make emulate`, which invokes (and thus requires) `qemu-system-i386`, or by using any emulator of your choice.
|
||
|
||
Alternatively, `make` will reassemble sector.asm, then run the above qemu emulator.
|
||
|
||
Additionally, you can run an example file easily by running `make runfile file=SOURCE_CODE`. Try out `make runfile file=hello_world.FORTH` or `make runfile file=bf.FORTH`! *NOTE: Files run this way currently do not accept user input from stdin, as the file itself is being piped to qemu. Fix coming shortly.*
|
||
|
||
`make sizecheck` is a utility which assembles sector.asm into sector.bin and then lists out the size of sector.bin for you. Note that this automatically removes the padding from the .bin (as a working bootloader must be exactly 512 bytes).
|
||
|
||
## References
|
||
|
||
## Footnotes
|
||
|
||
1. The immensely inspirational sectorForth, to which much credit is due: <https://github.com/cesarblum/sectorforth/>. [↩](#user-content-fnref-1-d37e1f81f2eea8c6e7bde869760db32c) [↩2](#user-content-fnref-1-2-d37e1f81f2eea8c6e7bde869760db32c)
|
||
2. Mind-blowing sectorLISP: <https://justine.lol/sectorlisp2/>, <https://github.com/jart/sectorlisp>. [↩](#user-content-fnref-2-d37e1f81f2eea8c6e7bde869760db32c)
|
||
|
||
## About
|
||
|
||
A FORTH in 340 bytes — the smallest real programming language ever as of yet.
|
||
|
||
### Resources
|
||
|
||
[Readme](#readme-ov-file)
|
||
|
||
### License
|
||
|
||
[MIT license](#MIT-1-ov-file)
|
||
|
||
### Uh oh!
|
||
|
||
There was an error while loading. Please reload this page.
|
||
|
||
[Activity](/fuzzballcat/milliForth/activity)
|
||
|
||
### Stars
|
||
|
||
[**623**
|
||
stars](/fuzzballcat/milliForth/stargazers)
|
||
|
||
### Watchers
|
||
|
||
[**10**
|
||
watching](/fuzzballcat/milliForth/watchers)
|
||
|
||
### Forks
|
||
|
||
[**28**
|
||
forks](/fuzzballcat/milliForth/forks)
|
||
|
||
[Report repository](/contact/report-content?content_url=https%3A%2F%2Fgithub.com%2Ffuzzballcat%2FmilliForth&report=fuzzballcat+%28user%29)
|
||
|
||
## [Releases](/fuzzballcat/milliForth/releases)
|
||
|
||
No releases published
|
||
|
||
## [Packages 0](/users/fuzzballcat/packages?repo_name=milliForth)
|
||
|
||
No packages published
|
||
|
||
## [Contributors 2](/fuzzballcat/milliForth/graphs/contributors)
|
||
|
||
* [](https://github.com/fuzzballcat)
|
||
|
||
[**fuzzballcat**](https://github.com/fuzzballcat)
|
||
* [](https://github.com/peterferrie)
|
||
|
||
[**peterferrie**
|
||
Peter Ferrie](https://github.com/peterferrie)
|
||
|
||
## Languages
|
||
|
||
* [Forth
|
||
53.5%](/fuzzballcat/milliForth/search?l=forth)
|
||
* [Assembly
|
||
34.9%](/fuzzballcat/milliForth/search?l=assembly)
|
||
* [Makefile
|
||
6.8%](/fuzzballcat/milliForth/search?l=makefile)
|
||
* [Python
|
||
4.8%](/fuzzballcat/milliForth/search?l=python)
|
||
|
||
## Footer
|
||
|
||
© 2026 GitHub, Inc.
|
||
|
||
### Footer navigation
|
||
|
||
* [Terms](https://docs.github.com/site-policy/github-terms/github-terms-of-service)
|
||
* [Privacy](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement)
|
||
* [Security](https://github.com/security)
|
||
* [Status](https://www.githubstatus.com/)
|
||
* [Community](https://github.community/)
|
||
* [Docs](https://docs.github.com/)
|
||
* [Contact](https://support.github.com?tags=dotcom-footer)
|
||
* Manage cookies
|
||
* Do not share my personal information
|
||
|
||
|
||
|
||
You can’t perform that action at this time. |