{"id":13590615,"url":"https://github.com/ThakeeNathees/pocketlang","last_synced_at":"2025-04-08T13:31:37.297Z","repository":{"id":37211962,"uuid":"336730906","full_name":"ThakeeNathees/pocketlang","owner":"ThakeeNathees","description":"A lightweight, fast embeddable scripting language.","archived":false,"fork":false,"pushed_at":"2024-09-02T03:31:51.000Z","size":2443,"stargazers_count":1525,"open_issues_count":56,"forks_count":80,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-05T08:09:38.236Z","etag":null,"topics":["bytecode-compiler","c","functional","interpreter","language","programming-language","scripting-language","vm"],"latest_commit_sha":null,"homepage":"https://thakeenathees.github.io/pocketlang/","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/ThakeeNathees.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}},"created_at":"2021-02-07T07:43:55.000Z","updated_at":"2025-03-23T09:20:41.000Z","dependencies_parsed_at":"2022-07-13T16:48:25.666Z","dependency_job_id":null,"html_url":"https://github.com/ThakeeNathees/pocketlang","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/ThakeeNathees%2Fpocketlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Fpocketlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Fpocketlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Fpocketlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThakeeNathees","download_url":"https://codeload.github.com/ThakeeNathees/pocketlang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247851669,"owners_count":21006798,"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":["bytecode-compiler","c","functional","interpreter","language","programming-language","scripting-language","vm"],"created_at":"2024-08-01T16:00:48.811Z","updated_at":"2025-04-08T13:31:37.265Z","avatar_url":"https://github.com/ThakeeNathees.png","language":"C","readme":"\n\u003cp align=\"center\" \u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/41085900/161365989-f3fd47bb-7ea7-4114-8e9b-2224e1193079.png\" width=\"500\" \u003e\n\u003c/p\u003e\n\n**Pocketlang** is a lightweight (~3000 semicolons) and [fast](https://github.com/ThakeeNathees/pocketlang#performance)\nobject oriented, embeddable scripting language written in C. It has a ruby\nflavoured python syntax, that can be learned [within 15 minutes](https://thakeenathees.github.io/pocketlang/docs/v0.1.0/Reference/Cheat-Sheet.html).\nIncluding the compiler, bytecode VM and runtime, it's a standalone executable\nwith zero external dependencies just as it's self descriptive name. The pocketlang\nVM can be embedded in another hosting program very easily.\n\n[Wren Language](https://wren.io/) and their wonderful book [Crafting Interpreters](http://www.craftinginterpreters.com/)\nwere used as a reference to write this language.\n\n## What pocketlang looks like\n\n```ruby\n# Python like import statement.\nfrom time import clock as now\n\n# A recursive fibonacci function.\ndef fib(n)\n  if n \u003c 2 then return n end\n  return fib(n-1) + fib(n-2)\nend\n\n# Prints all fibonacci from 0 to 10 exclusive.\nfor i in 0..10\n  print(\"fib($i) = ${fib(i)}\")\nend\n```\n\n## Try It Now\n\nYou can [try pocketlang on your browser](https://thakeenathees.github.io/pocketlang/try-online.html).\nIt's a [WebAssembly](https://webassembly.org/) build of the VM compiled using [emscripten](https://emscripten.org/).\nNote that in the webassembly version of the language, some features (input, file handling, relative import, etc.)\nhave disabled, has limited memory allocations, and the stdout calls might be slower.\n\n## Documentation\n\nThe pocketlang documentation is hosted at https://thakeenathees.github.io/pocketlang/ which\nis built from the `docs` branch generated by a little python script at `docs/generate.py`.\nNote that the documentations are WIP and might not be up to date.\n\n## Performance\n\nPocketlang uses [NaN-Boxing](https://leonardschuetz.ch/blog/nan-boxing/) which is a memory efficient way to represent\ndynamic types and dealing with them are much faster. It supports [tail call](https://en.wikipedia.org/wiki/Tail_call)\n[optimization](https://wiki.c2.com/?TailCallOptimization). When a function returns a call, the callee can re-use the\ncaller's stack frame, this will optimize memory from O(n) to O(1) and for [tail recursive](https://www.youtube.com/watch?v=-PX0BV9hGZY)\nit'll completely prevent stackoverflows and yet it's faster.\n\nAll benchmarks below were executed on: Windows10 (64bit), ASUS N552VX, Intel Core i7-6700HQ 2.6GHz\nwith 12GB SODIMM Ram. And the language versions are: pocketlang (pre-alpha), wren v0.3.0,\npython v3.7.4, ruby v2.7.2.\n\n![performance](https://user-images.githubusercontent.com/41085900/120123257-6f043280-c1cb-11eb-8c20-a42153268a0f.png)\n\nThe source files used to run benchmarks can be found at `test/benchmarks/`\ndirectory. They were executed using a small python script in the test directory.\n\n## Building From Source\n\nIt can be build from source easily without any dependencies, or additional requirements\nexcept for a c99 compatible compiler. It can be compiled with the following command.\n\n#### GCC / MinGw / Clang (alias with gcc)\n```\ngcc -o pocket cli/*.c src/core/*.c src/libs/*.c -Isrc/include -lm -ldl\n```\n\n#### MSVC\n```\ncl /Fepocket cli/*.c src/core/*.c src/libs/*.c /Isrc/include \u0026\u0026 rm *.obj\n```\n\n#### Makefile\n```\nmake\n```\nTo run the make file on windows with `mingw`, you require the GNU `make` tool which you can get\nfrom [msys2](https://www.msys2.org/) or [cygwin](https://www.cygwin.com/).\n\n#### Windows batch script\n```\nscripts\\build.bat\n```\nYou don't have to run the script from a Visual Studio .NET developer command prompt, It'll search\nfor the MSVS installation path and setup the build environment.\n\n### For other compiler/IDE\n\n1. Create an empty project file / makefile.\n2. Add all C files in the src/core/ directory.\n3. Add all C files in the src/libs/ directory.\n4. Add all C files in the cli/ directory.\n5. Add `src/include` to include path.\n6. If \\*nix link m, dl\n7. Compile.\n\nVisual studio project files can be generated with the premake, see\n[scripts/README](https://github.com/ThakeeNathees/pocketlang/scripts/README.md)\nfor more information. If you weren't able to compile it, please report\nus by [opening an issue](https://github.com/ThakeeNathees/pocketlang/issues/new).\n\n\n## References\n- Bob Nystrom.(2021) *craftinginterpreters* [online] Available at www.craftinginterpreters.com/ (Accessed January 2021)\n\n- Mark W. Bailey, Nathan C. Weston (June 2001) Technical report. *Performance Benefits of Tail Recursion Removal in\nProcedural Languages* [online] Available at http://cs.hamilton.edu/~mbailey/pubs/techreps/TR-2001-2.pdf\n\n- Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes *Closures in Lua* [pdf] Available at\nhttps://www.cs.tufts.edu/~nr/cs257/archive/roberto-ierusalimschy/closures-draft.pdf (Accessed March 2022)\n\n- Leonard schütz.(2020) *Dynamic Typing and NaN Boxing* [online] Available at https://leonardschuetz.ch/blog/nan-boxing/ (Accessed December 2020)\n\n- Bob Nystrom.(2011) *Pratt Parsers: Expression Parsing Made Easy* [online] Avaliable at\nhttp://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/ (Accessed December 2020)\n","funding_links":[],"categories":["C","Uncategorized","Other"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThakeeNathees%2Fpocketlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FThakeeNathees%2Fpocketlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThakeeNathees%2Fpocketlang/lists"}