{"id":15672375,"url":"https://github.com/drom/shift-forth","last_synced_at":"2025-07-17T03:34:32.930Z","repository":{"id":26383097,"uuid":"29832503","full_name":"drom/shift-forth","owner":"drom","description":":aerial_tramway: shift-ast to Forth compiler","archived":false,"fork":false,"pushed_at":"2015-03-07T08:12:30.000Z","size":308,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-10T07:06:20.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/drom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-25T21:42:05.000Z","updated_at":"2024-12-30T17:03:27.000Z","dependencies_parsed_at":"2022-08-21T06:00:47.640Z","dependency_job_id":null,"html_url":"https://github.com/drom/shift-forth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drom/shift-forth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fshift-forth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fshift-forth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fshift-forth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fshift-forth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drom","download_url":"https://codeload.github.com/drom/shift-forth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fshift-forth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264897193,"owners_count":23679991,"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":[],"created_at":"2024-10-03T15:25:02.477Z","updated_at":"2025-07-17T03:34:32.911Z","avatar_url":"https://github.com/drom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/drom/shift-forth.svg?branch=master)](https://travis-ci.org/drom/shift-forth)\n[![NPM version](https://img.shields.io/npm/v/shift-forth.svg)](https://www.npmjs.org/package/shift-forth)\n[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)\n\n# shift-forth\n\n[DEMO](http://drom.github.io/shift-forth/editor.html)\n\n## About\n\nJavaScript Compiler library that takes input in [Shift-AST](https://github.com/shapesecurity/shift-spec)\nformat in\n[SSA form](http://en.wikipedia.org/wiki/Static_single_assignment_form)\nand produces\n[Forth](http://en.wikipedia.org/wiki/Forth_%28programming_language%29)\nprogram.\n\n## Examples\n\n```js\nfunction add42 (a) {             // : add42 42 + exit ;\n  return a + 42;\n}\n\nfunction square (x) {            // : square 0 pick * exit ;\n  \treturn x * x;\n}\n\nfunction sub (a, b) {            // : sub\n  return a - b;                  //     - exit\n}                                // ;\n\n                                 // variable g0\nfunction mul_global (a) {        // : mul_global\n  return a * g0;                 //     g0 @ * exit\n}                                // ;\n\nfunction add3_fast (a, b, c) {   // : add3_fast\n  return b + c + a;              //     + + exit\n}                                // ;\n\nfunction add_var (a, b) {        // : add_var\n  var x;\n  x = a + b;                     //     +\n  return x;                      //     exit\n}                                // ;\n\nfunction cmplx_re (a, b, c, d) { // : cmplx_re\n  var re;                        //     3 pick 2 pick *\n  re = a * c - b * d;            //     3 pick 2 pick * -\n  return re;                     //     nip nip nip nip exit\n}                                // ;\n\nfunction cmplx_im (a, b, c, d) { // : cmplx_im\n  var im;                        //     3 pick *\n  im = a * d + b * c;            //     2 pick 2 pick * +\n  return im;                     //     nip nip nip exit\n}                                // ;\n\nfunction foo (x0, y0) {          // : foo\n  if (x0 \u003c 100) {                //     over 100 \u003c if\n    do {                         //         begin\n      x1 = ф(x0, x2);            //\n      y1 = ф(y0, y2);            //\n      x2 = x1 + 1;               //             swap 1 +\n      y2 = y1 + x2;              //             swap over +\n    } while (x2 \u003c 100);          //         over 100 \u003e= until\n  }                              //     then\n  x3 = ф(x0, x2);\n  y3 = ф(y0, y2);\n  return [x3, y3];               //     exit\n}                                // ;\n```\n\n## Status\n\nInitial code.\n\n## Installation\n\n```\nnpm install shift-forth\n```\n\n## Usage\n\nRequire Parser, Scope analyzer, and Shift-Forth.\n\n```js\nvar parse = require('shift-parser').default,\n    analyze = require('shift-scope').default,\n    forth = require('shift-forth');\n```\n\nParse JavaScript string, analyze scope, emit Forth string.\n\n```js\nvar source, tree, scope;\n\nsource = 'function sub (a, b) { return a - b; }';\ntree = parse(source);  // Shift AST\nforth.naming(tree);    // add names to noname AST nodes\nscope = analyze(tree); // Scoped AST\nforth.dfg(scope);      // add dependency graph\nforth.emit(scope);     // add Forth definition to scoped AST\nconsole.log(scope.forth);\n\n// -\u003e : sub - exit ;\n```\n\nThe library uses:\n[shift-traverse-js](https://github.com/Constellation/shift-traverse-js)\nlibrary for AST traversal.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fshift-forth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrom%2Fshift-forth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fshift-forth/lists"}