{"id":18645479,"url":"https://github.com/cscott/php-turtle","last_synced_at":"2025-08-08T05:11:38.739Z","repository":{"id":66063585,"uuid":"237519978","full_name":"cscott/php-turtle","owner":"cscott","description":"TurtleScript runtime in PHP","archived":false,"fork":false,"pushed_at":"2020-02-15T19:15:25.000Z","size":506,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-09T17:08:33.297Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cscott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-01-31T21:34:30.000Z","updated_at":"2020-02-15T19:15:27.000Z","dependencies_parsed_at":"2023-02-21T00:16:45.680Z","dependency_job_id":null,"html_url":"https://github.com/cscott/php-turtle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cscott/php-turtle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fphp-turtle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fphp-turtle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fphp-turtle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fphp-turtle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cscott","download_url":"https://codeload.github.com/cscott/php-turtle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fphp-turtle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269366853,"owners_count":24405250,"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-08-08T02:00:09.200Z","response_time":72,"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":[],"created_at":"2024-11-07T06:16:04.421Z","updated_at":"2025-08-08T05:11:38.707Z","avatar_url":"https://github.com/cscott.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-turtle\n\n`php-turtle` is an implementation of\n[TurtleScript](https://github.com/cscott/turtlescript) in\nPHP.  TurtleScript is a syntactic\n(but not semantic) subset of JavaScript, originally created for\nthe One Laptop per Child project.\n\n## Install, and Run\n\nInstallation with `composer install`, as usual.\n\nTo run a TurtleScript\n[REPL](http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop):\n```\n$ bin/phpturtle\n\u003e\u003e\u003e 2+3\n5\n\u003e\u003e\u003e var fact = function(x) { return (x\u003c2) ? x : (x * fact(x-1)) ; };\nundefined\n\u003e\u003e\u003e fact(42)\n1.4050061177529E+51\n\u003e\u003e\u003e\n```\nUse Control-D (or Control-C) to exit the REPL.  You can also evaluate entire\nTurtleScript scripts by passing the name on the command line:\n```\n$ bin/phpturtle foo.js\n```\n\n## Testing\nThere are quite a few unit tests built into `php-turtle` (although\nnever enough!).  You can build and run them with `composer test`.  See\n`tests/InterpreterTest.php` for a set of script-based tests, which you\ncould manually reproduce in the REPL (if you were so inclined).\n\n## Design\n`php-turtle` is a simple interpreter for the bytecode emitted by\n`bcompile.js` from the TurtleScript project.  It is heavily based on\n`binterp.js` from that project, which is a TurtleScript interpreter written\nin TurtleScript.  The `src/Startup.php` file contains the bytecode for the\nTurtleScript standard library implementation (from `binterp.js`) as\nwell as the tokenizer, parser, and bytecode compiler itself (emitted\nby `write-php-bytecode.js` in the TurtleScript project).  This allows\nthe `php-turtle` REPL to parse and compile the expressions you type\nat it into bytecode modules which it can interpret.\n\nCurrently bytecode is interpreted; a logical next step would be to\ncompile directly to PHP code and eliminate the overhead of the\ninterpretation loop.  The goal of the JavaScript object model implementation\nis to try to map JavaScript operations onto PHP operations as nearly\nas possible, to keep JavaScript execution speed comparable to PHP\nexecution.  For example, property accesses in JavaScript map directly\nto property accesses in PHP.  It wouldn't be too hard to allow the\nJavaScript code to directly interrogate a 'native' PHP object.\nThe vice-versa case is interesting as well: PHP can very easily\naccess properties of native JavaScript objects.  Cross-realm\nfunction invocation is a *little* harder, but not much.\n\n## Future performance improvements\n\nThe representation of arrays at present leaves much to be\ndesired -- they are just objects with keys which are numeric strings.\nThese should be replaced by \"real\" PHP arrays, although that complicates\nsome of the type dispatch code.\n\nStrings are generally represented as UTF-16, which is \"native\" for\nJavaScript, although property names and literals are UTF-8.  This\nseems to strike a good balance between fluent property access in PHP\nusing mostly-ASCII strings, and efficient string manipulation in\nJavaScript.  It may however be interesting to allow strings to switch\nrepresentations on the fly.\n\nCompiling the bytecode could make use of type information, perhaps\npropagated from variable initialization and the types of arguments\nwhen a function is invoked, in order to reduce the amount of dynamic\ntype dispatch.  A small number of specialized versions of any given\nfunction could be compiled, falling back to the present bytecode\ninterpreter if the function turns out to be polyvariant.\n\n## Future research\n\nI would like to explore multilingual JavaScript using this platform.\nThere are some thoughts in\n[Wikimedia phabricator](https://phabricator.wikimedia.org/T230665);\n[Babylscript](http://www.babylscript.com/) also appears very interesting.\n\n## License\n\nTurtleScript and `php-turtle` are (c) 2020 C. Scott Ananian and\nlicensed under the terms of the GNU GPL v2.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcscott%2Fphp-turtle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcscott%2Fphp-turtle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcscott%2Fphp-turtle/lists"}