https://github.com/fuzzballcat/milliForth Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips 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. Cancel Create saved search Sign in Sign up 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 / milliForth Public * Notifications * Fork 4 * Star 189 A FORTH in 386 bytes -- the smallest real programming language ever as of yet. 189 stars 4 forks Activity Star Notifications * Code * Issues 4 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights fuzzballcat/milliForth This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/f] Use Git or checkout with SVN using the web URL. [gh repo clone fuzzba] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @fuzzballcat fuzzballcat Update README.md ... e74f15d Nov 6, 2023 Update README.md e74f15d Git stats * 14 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .gitignore First commit. November 5, 2023 15:09 README.md Update README.md November 6, 2023 10:01 hello_world.FORTH Significant size reduction. November 6, 2023 09:49 makefile First commit. November 5, 2023 15:09 py_autotype.py Fix autotype, bin. November 5, 2023 16:06 sector.asm Significant size reduction. November 6, 2023 09:49 sector.bin Significant size reduction. November 6, 2023 09:49 View code milliForth bytes? Language Use References README.md milliForth A FORTH in 386 bytes -- the smallest real programming language ever, as of yet. milliFORTH_justhelloworld 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 successfully fit a FORTH within the boot sector. However, milliFORTH appears to be the smallest "real" programming language implementation ever, beating out sectorLISP^2, a mind-blowing 436 byte implementation of LISP, by 50 bytes. ("real" excludes esolangs and other non-production languages - for example, the sectorLISP author's implementation of BF is just 99 bytes, and their binary lambda calculus implementation is 383 bytes, but neither language is used to any serious capacity.) Language sectorFORTH^1 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 -- Get a value at an address value ) ! ( value Store a value at an address addr -- ) sp@ ( -- sp ) Get pointer to top of the data stack rp@ ( -- rp ) Get pointer to top of the return stack 0= ( value -- Check if a value equals zero (-1 = TRUE, 0 = flag ) FALSE) + ( a b -- Sum two numbers a+b ) nand ( a b -- NAND two numbers aNANDb ) 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 The "state struct" pointer. The cells of this struct are, in order: * state: The state of the interpreter (0 = ( -- state@ compile words, 1 = execute words) state@ ) * >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 (state@). * 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 qemu-system-i386 -fda sector.bin (as found in the makefile), or by using any emulator of your choice. Alternatively, make will reassemble sector.asm, then run the above qemu emulator. Included in this repo is a pyautogui script which can be run to automatically type in the hello_world.FORTH file into your qemu emulator. A very useful tool. It is self-explaining, but usage involves simply starting the QEMU emulator, running the python script, and putting your cursor into the QEMU emulator again. make sizecheck is a utility which assembles sector.asm and then lists files including size. This is useful for checking binary size. Note that it will always return 512, as bootloaders must have a fixed size of 512 bytes; to view the true size, the following two lines must be commented at the end of sector.asm: ; times 510-($-$$) db 0 ; db 0x55, 0xaa References Footnotes 1. The immensely inspirational sectorForth, to which much credit is due: https://github.com/cesarblum/sectorforth/. - -^2 2. Mind-blowing sectorLISP: https://justine.lol/sectorlisp2/, https: //github.com/jart/sectorlisp. - About A FORTH in 386 bytes -- the smallest real programming language ever as of yet. Resources Readme Activity Stars 189 stars Watchers 3 watching Forks 4 forks Report repository Releases No releases published Packages 0 No packages published Languages * Assembly 56.6% * Forth 35.1% * Python 4.9% * Makefile 3.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.