{"id":13743890,"url":"https://github.com/sixsided/Simplified-JavaScript-Interpreter","last_synced_at":"2025-05-09T02:31:45.688Z","repository":{"id":72866667,"uuid":"1596887","full_name":"sixsided/Simplified-JavaScript-Interpreter","owner":"sixsided","description":"AS3-based Javascript interpreter, minus a few features (prototype chain, mainly)","archived":false,"fork":false,"pushed_at":"2014-02-27T05:23:08.000Z","size":299,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-15T15:41:06.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"ActionScript","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/sixsided.png","metadata":{"files":{"readme":"README.markdown","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}},"created_at":"2011-04-11T00:49:44.000Z","updated_at":"2024-07-30T00:49:54.000Z","dependencies_parsed_at":"2023-02-23T13:16:03.614Z","dependency_job_id":null,"html_url":"https://github.com/sixsided/Simplified-JavaScript-Interpreter","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/sixsided%2FSimplified-JavaScript-Interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sixsided%2FSimplified-JavaScript-Interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sixsided%2FSimplified-JavaScript-Interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sixsided%2FSimplified-JavaScript-Interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sixsided","download_url":"https://codeload.github.com/sixsided/Simplified-JavaScript-Interpreter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253177746,"owners_count":21866391,"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-08-03T05:00:59.083Z","updated_at":"2025-05-09T02:31:45.476Z","avatar_url":"https://github.com/sixsided.png","language":"ActionScript","readme":"Simplified JavaScript (SJS) is a JavaScript interpreter you can embed in your Flash ActionScript 3 projects.  \n\nSJS is useful as an embedded scripting language for games or an exploratory debugging tool.\n\nInspirations: \n----------------\nDouglas Crockford's \"Top Down Operator Precedence\"\nhttp://javascript.crockford.com/tdop/tdop.html\n\nRichard W.M. Jones' implementation of FORTH \nhttp://annexia.org/forth\n\nFeatures\n--------\n* can parse and execute most JavaScript.\n* can import AS3 objects by calling interpreter.setGlobal(\"objectNameInJS\", objectNameInAS3)\n* can instantiate native flash objects like MovieClip with the \"new\" operator and manipulate them.\n* async \"await\" statement that pauses the VM until a Promise is fulfilled\n\nOmissions\n-----------\n* prototype chain\n* multiple assignment (i.e. a = b = c)\n* automatic semicolon insertion\n* \"with\" statement\n* for...in, for each in\n\nAwait\n-----------\n\n    protected function waitBriefly() : Promise {\n        var t:Timer = new Timer(1000, 1);\n        var p:Promise = new Promise();\n        t.addEventListener(Timer.TIMER, function(e:TimerEvent) { promise.fulfill(23); } )\n        t.start();\n        return p;\n    }\n    \n    // ... then ....\n    myInterpreter.setGlobal('doSomethingAsync', waitBriefly);\n    \n    myInterpreter.doString(  \"trace(1);                         \"\n                           + \"await x = doSomethingAsync();     \"\n                           + \"trace(x);                         \" );\n\n    // interpreter will trace out \"23\" after one second.\n    \n    \nHow to use RemoteConsole.as:\n===========================\n    #### Best way: \n    Run remote-console-hub.py, which provides a \"chat\" server \n    that stays up across multiple runs of your SWF. Then telnet to it with nc\n    and issue commands to your heart's content. Let's wrap nc with rlwrap so we'll \n    have command-line history (ie up- and down- arrow).\n\n      python org/sixsided/scripting/SJS/remote-console-hub.py\n      rlwrap nc localhost 9000\n  \n\n    Then start your Flash app, which should include code to the effect of:\n    \n      remoteConsole = new RemoteConsole('localhost', 9000);\n      remoteConsole.setInterpreter(new Interpreter());\n\n    Also see the comment at the top of remote-console-hub.py.\n\n    #### Other way:\n    1) serve policy files on Flash's expected port 843 with netcat:    \n        while true ; cat policy.xml | nc -l 843 ; end\n      \n    2) listen for connections from the Flash app with:\n        rlwrap nc -lk 8080\n    \n    \n    \n\n\n* * * Boring internals description * * *\n==============================================\n\nSJS operates on JavasScript in four stages:\n\n1) Tokenize the source code.\n  Lexer.as breaks the source code into a flat array of tokens like '{', 'while', '=', '!=', etc.\n  This is just Douglas Crockford's lexer.\n\n2) Parse the token array.\n  Parser.as converts the token array into a tree of parse node objects, such that a preorder traversal\n  of the tree, printing each node, would emit an arithemetic expression like 2 + 3 * 4\n  in RPN, ie, 2 3 4 * +\n  \n3) Generate VM opcodes from the parse tree\n  Parser.as walks the tree in preorder, calling the codegen method of each parse node, and storing\n  the emitted VM opcodes.\n  \n  The parse tree can be dumped out in a representation that looks like a postfix LISP.\n  This input:\n    1 + 2 * 3 / 4 % 5\n  would appear as:\n    (+ 1 (% (/ (* 2 3) 4) 5))\n  \n4) Execute the opcodes.\n  The VM iterates through the opcode array, modifying its own internal state in response to each one.\n  It can also instantiate and perform method calls on Flash objects like MovieClip if they've been\n  installed in its static member VM.registry:Object\n  \n  I use short human-readable strings to represent the opcodes, so we can easily read the generated\n  code to make sure it's what's expected.\n  \n  This parse tree:\n    (+ 1 (% (/ (* 2 3) 4) 5))\n  Would generate this code:\n    LIT 1 LIT 2 LIT 3 MUL LIT 4 DIV LIT 5 MOD ADD\n\n\n\n\n","funding_links":[],"categories":["File Formats","Runtimes"],"sub_categories":["JavaScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixsided%2FSimplified-JavaScript-Interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsixsided%2FSimplified-JavaScript-Interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixsided%2FSimplified-JavaScript-Interpreter/lists"}