{"id":18014819,"url":"https://github.com/zevv/zforth","last_synced_at":"2025-04-08T10:27:04.741Z","repository":{"id":45632669,"uuid":"60991904","full_name":"zevv/zForth","owner":"zevv","description":"zForth: tiny, embeddable, flexible, compact Forth scripting language for embedded systems","archived":false,"fork":false,"pushed_at":"2025-03-30T08:59:30.000Z","size":173,"stargazers_count":373,"open_issues_count":2,"forks_count":52,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-01T09:25:08.649Z","etag":null,"topics":["forth","scripting-language"],"latest_commit_sha":null,"homepage":null,"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/zevv.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}},"created_at":"2016-06-12T22:16:24.000Z","updated_at":"2025-03-30T08:59:33.000Z","dependencies_parsed_at":"2024-01-16T20:29:09.949Z","dependency_job_id":"6d5480ed-80d6-4ce6-80f0-8e79c101698a","html_url":"https://github.com/zevv/zForth","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/zevv%2FzForth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2FzForth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2FzForth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2FzForth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zevv","download_url":"https://codeload.github.com/zevv/zForth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247822579,"owners_count":21001892,"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":["forth","scripting-language"],"created_at":"2024-10-30T04:11:13.489Z","updated_at":"2025-04-08T10:27:04.722Z","avatar_url":"https://github.com/zevv.png","language":"C","readme":"\n![zForth](/zforth.png)\n\nzForth\n======\n\n\nFrom Wikipedia:\n\n   _A Forth environment combines the compiler with an interactive shell, where\n   the user defines and runs subroutines called words. Words can be tested,\n   redefined, and debugged as the source is entered without recompiling or\n   restarting the whole program. All syntactic elements, including variables\n   and basic operators are defined as words. Forth environments vary in how the\n   resulting program is stored, but ideally running the program has the same\n   effect as manually re-entering the source._\n\nzForth is yet another Forth, but with some special features not found in most\nother forths. Note that zForth was written for engineers, not for language\npurists or Forth aficionados. Its main intention is to be a lightweight\nscripting language for extending embedded applications on small\nmicroprocessors. It is not particularly fast, but should be easy to integrate\non any platform with a few kB's of ROM and RAM.\n\nAlso note that zForth is just _a_ forth, but does not specifically implement or\ncare about any of the standards like ANS Forth - the kernel might or might not\nbehave as the standard, and the current standard library is rather limited.\n\nFor a lot of programmers Forth seems to belong to the domain of alien\nlanguages: it does not look like any mainstream language most people encounter,\nand is built on a number of philosophies that takes some time to get used to.\nStill, it is one of the more efficient ways of bringing a interpreter and\ncompiler to a platform with restricted resources.\n\nSome of zForth's highlights:\n\n- **Small dictionary**: instead of relying on a fixed cell size, the dictionary is\n  written in variable length cells: small and common numbers take less space\n  then larger, resulting in 30% to 50% space saving\n\n- **Portable**: zForth is written in 100% ANSI C, and runs on virtually all\n  operating systems and all architectures. Tested on x86 Linux/Win32/MS-DOS\n  (Turbo-C 1.0!), x86_64, ARM, ARM thumb, MIPS, Atmel AVR and the 8051.\n\n- **Small footprint**: the kernel C code compiles to about 3 or 4 kB of machine\n  code, depending on the architecture and chosen cell data types.\n\n- **Support for multiple instances**: The compiler and VM state is stored in a\n  struct, allowing multiple instances of zForth to run in parallel.\n\n- **Tracing**: zForth is able to show a nice trace of what it is doing under the\n  hood, see below for an example.\n\n- **VM**: Implemented as a small virtual machine: not the fastest, but safe and\n  flexible. Instead of having direct access to host memory, the forth VM memory\n  is abstracted, allowing proper boundary checking on memory accesses and stack\n  operations.\n\n- **Flexible data types**: at compile time the user is free to choose what C data\n  type should be used for the dictionary and the stacks. zForth supports signed\n  integer sizes from 16 to 128 bit, but also works seamlessly with floating point\n  types like float and double (or even the C99 'complex' type!)\n\n- **Ease interfacing**: calling C code from forth is easy through a host system\n  call primitive, and code has access to the stack for exchanging data between\n  Forth and C. Calling forth from C is easy, just one function to evaluate forth \n  code.\n\n\nSource layout\n=============\n\n```\n./forth         : core zforth library and various snippets and examples\n./src/zforth    : zfort core source; embed these into your program\n./src/linux     : example linux application\n./src/atmega8   : example AVR atmega8 application\n```\n\n\nUsage\n=====\n\nzForth consists of only two files: zforth.c and zforth.h. Add both to your\nproject and call `zf_init()` and `zf_bootstrap()` during initialisation. Read\nforth statements from a file or terminal and pass the strings to `zf_eval()` to\ninterpret, compile and run the code. Check the embedded documentation in\n`zforth.h` for details.\n\n`zforth.c` depends on a number preprocessor constants for configuration which\nyou can choose to fit your needs. Documentation is included in the file\n`zfconf.h`.\n\nA demo application for running zForth in linux is provided here, simply run `make`\nto build.\n\nTo start zForth and load the core forth code, run:\n\n````\n./src/linux/zforth forth/core.zf\n````\n\nAnd zForth will welcome you with the startup message:\n\n````\nWelcome to zForth, 786 bytes used\n````\n\nzForth is now ready to use. Try some of the following:\n\nAdding one and one or calculate the 144 squared:\n\n````\n1 1 + .\n144 dup * .\n````\n\nPrint the sine of 10 numbers between 0 and PI\n\n````\n: pi 3.141592654 ;\n: demo pi 0 do i sin . pi 10 / loop+ ;\ndemo\n````\n\nLoad and run the demo Mandelbrot fractal:\n\n````\ninclude forth/mandel.zf\n\n.........................----.....................\n.....................----+--......................\n.......................--*-.......................\n........................- --.....--...............\n...........----........--%---------...............\n............-------------#---------...............\n.............------------ ---------...............\n.............------------ ---------...............\n..............---------o   o--------..............\n..............---------o   =----------------------\n.............----o-oo         =o-=--------------..\n...........-------#             *------------.....\n........--------=-=             o-=--------.......\n....--------------=             =---------........\n......-------------+           +---------.........\n.......-------------=#       %=-----------........\n........--------=-               -=--------.......\n.......------=                       =------------\n.....---o   =                         =   =-------\n---------                                 --------\n---------o+                             +o--------\n---------o                               =--------\n---=#=# =                                 = #=#=--\n---=                                           =--\n-=- +                                         + ==\no---oo*==                                 -=*=o---\n---------=                               =--------\n---------#=                             =#--------\n-----------%                           %------....\n---...----=  =%          -          #=  =----.....\n.......---=o----* =+*---------*+- *----o=----.....\n........--------------------------------------....\n````\n\n\nTracing\n=======\n\nzForth can write verbose traces of the code it is compiling and running. To enable\ntracing, run `./zforth` with the `-t` argument. Tracing can be enabled at run time \nby writing `1` in the `trace` variable:\n\n```\n1 trace !\n```\n\nMake sure the feature ZF_ENABLE_TRACING is enabled in zfconf.h to compile in\ntracing support.\n\n\nThe following symbols are used:\n\n- stack operations are prefixed with a double arrow, `«` means pop, `»` means push.\n  for operations on the return stack the arrow is prefixed with an `r`\n\n- the current word being executed is shown in square brackets, the format\n  is `[\u003cname\u003e/\u003caddress\u003e]`\n\n- lines starting with a + show values being added to the dictionary\n\n- lines starting with a space show the current line being executed, format\n  `\u003caddress\u003e \u003cdata\u003e`\n\n- lines starting with `===` show the creation of a new word\n\n\n````\n: square dup * ;\n: test 5 square . ;\ntest\n````\n\nExecuting the word `test`:\n\n````\ntest\n\nr»0 \n[test/0326] \n 0326 0001 ┊  (lit) »5 \n 0328 031c ┊  square/031c r»810 \n 031c 000b ┊  ┊  (dup) «5 »5 »5 \n 031d 0007 ┊  ┊  (*) «5 «5 »25 \n 031e 0000 ┊  ┊  (exit) r«810 \n 032a 0133 ┊  ./0133 r»812 \n 0133 0001 ┊  ┊  (lit) »1 \n 0135 0019 ┊  ┊  (sys) «1 «25 \n 0136 0000 ┊  ┊  (exit) r«812 \n 032c 0000 ┊  (exit) r«0 25 \n````\n\nThis is the trace of the definition of the `square` and `test` words\n\n````\n: square dup * ;\n\nr»0 \n[:/002c] \n 002c 0003 ┊  (:) \n 002c 0003 ┊  (:) \n=== create 'square'\n+0313 0006 ¹ \n+0314 02eb ² \n+0316 0000 s 'square'\n===\n 002d 0000 ┊  (exit) r«0 \n+031c 000b ¹ +dup\n+031d 0007 ¹ +*r»0 \n[;/0031] \n 0031 0004 ┊  (;) \n+031e 0000 ¹ +exit\n===\n 0032 0000 ┊  (exit) r«0 \n\n: test 5 square . ;\n\nr»0 \n[:/002c] \n 002c 0003 ┊  (:) \n 002c 0003 ┊  (:) \n=== create 'test'\n+031f 0004 ¹ \n+0320 0313 ² \n+0322 0000 s 'test'\n===\n 002d 0000 ┊  (exit) r«0 \n+0326 0001 ¹ +lit\n+0327 0005 ¹ \n+0328 031c ² +square\n+032a 0133 ² +.r»0 \n[;/0031] \n 0031 0004 ┊  (;) \n+032c 0000 ¹ +exit\n===\n 0032 0000 ┊  (exit) r«0 \n\n````\n\n### Dependencies\n\nThe zForth core itself has no external dependencies, the linux example depends on libreadline-dev.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzevv%2Fzforth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzevv%2Fzforth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzevv%2Fzforth/lists"}