{"id":30865102,"url":"https://github.com/eliben/goforth","last_synced_at":"2025-09-07T20:51:01.830Z","repository":{"id":311198078,"uuid":"1006074895","full_name":"eliben/goforth","owner":"eliben","description":"Forth implementations in Go and C","archived":false,"fork":false,"pushed_at":"2025-08-22T17:20:23.000Z","size":213,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-31T00:04:56.806Z","etag":null,"topics":["c","compiler","forth","go","interpreter","stack-based-language"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliben.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-21T12:41:30.000Z","updated_at":"2025-08-28T14:20:05.000Z","dependencies_parsed_at":"2025-08-22T19:59:07.604Z","dependency_job_id":null,"html_url":"https://github.com/eliben/goforth","commit_stats":null,"previous_names":["eliben/goforth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eliben/goforth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fgoforth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fgoforth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fgoforth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fgoforth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliben","download_url":"https://codeload.github.com/eliben/goforth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fgoforth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274095326,"owners_count":25221432,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","compiler","forth","go","interpreter","stack-based-language"],"created_at":"2025-09-07T20:50:58.783Z","updated_at":"2025-09-07T20:51:01.822Z","avatar_url":"https://github.com/eliben.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goforth\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Logo\" src=\"doc/goforth-logo-sm.png\" /\u003e\n\u003c/p\u003e\n\n----\n\nThis repository contains two implementations of the\n[Forth programming language](https://en.wikipedia.org/wiki/Forth_(programming_language)).\n\nThe first is just called `goforth` and lives in the root directory of this\nrepository. The second is called `ctil` and lives in the `ctil` directory.\n\n## goforth: Go implementation of Forth\n\n`goforth` is implemented in Go and takes an unusual approach to Forth. It acts\nas a source-level interpreter. There is no intermediate representation of\nthe program - the source string is interpreted directly. When a word definition\nis encountered, `goforth` links it to the offset in the input string where\nthe word is defined, and when this word is called the interpreter just\nprocesses its string definition word by word.\n\nThis is an interesting experiment but clearly not the best way to implement\nForth; in addition to the performance implications, it makes implementing things\nlike loops quite difficult (having to carefully keep track of nested constructs\nlike `IF` to enable proper `LEAVE`), and it's hard to support Forth's famous\nself-extension mechanisms - for example, implementing `IF...THEN...ELSE` in\nForth itself using lower-level primitives.\n\nTo run `goforth` on a piece of Forth code, simply execute:\n\n```\n$ go run . \u003c testdata/fizzbuzz.4th\n\n... or ...\n$ go build\n$ ./goforth \u003c testdata/fizzbuzz.4th\n```\n\nThere are many small Forth programs in the `testdata` directory that can serve\nas examples to run and play with.\n\n## ctil: lower-level C implementation\n\n`ctil` (stands for \"C [Thread Interpretive Language](https://wiki.c2.com/?ThreadedInterpretiveLanguage)\")\nis a C implementation of Forth. It takes a much more traditional\nForth implementation approach, where the Forth code is actually compiled into\nlinked dictionary entries, and word invocations are replaced with the addresses\nof the dictionary entries for these words.\n\n`ctil` still deviates from the Forth convention of Assembly language\nimplementations, but it should be able to support pretty much everything.\nAs an example, take a look at `ctil/prelude.4th` - it contains implementations\nof the `variable` word, `IF...THEN...ELSE` conditions and `BEGIN...REPEAT`\nloops in Forth itself.\n\nTo run `ctil` on a piece of Forth code, first build `ctil`. A Makefile is\nincluded - `ctil` has no external dependencies other than a standard C compiler.\n\n```\n$ cd ctil\n$ make\n```\n\nTo run realistic Forth programs, the \"prelude\" has to be included first - it's\nan implementation of several Forth primitives in Forth itself. If you're still\nin the `ctil` directory, run:\n\n```\n$ ./ctil -i prelude.4th \u003c ../testdata/fizzbuzz.4th\n```\n\nThe design of `ctil` is inspired by the [jonesforth](http://git.annexia.org/?p=jonesforth.git)\nimplementation, though some things work differently (I tried to stick closer to standard\nForth).\n\n## Testing\n\ngoforth has an extensive automated test harness. Each test consists of a file\nin the `testdata` directory that contains some Forth code and the expected\noutput from that code. The test harness runs the Forth code using each\ninterpreter and compares the output with what's expected.\n\nBoth interpreters are tested using a Go test harness; `goforth_test.go` tests\nthe Go implementation, and `ctil_test.go` tests the C implementation. Since the\nC implementation supports more features, some test files in `testdata` are\nprefixed by `ctil-` and are run only for `ctil`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fgoforth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliben%2Fgoforth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fgoforth/lists"}