{"id":15684212,"url":"https://github.com/healeycodes/lisp-to-js","last_synced_at":"2025-10-06T11:32:39.533Z","repository":{"id":241291651,"uuid":"806107778","full_name":"healeycodes/lisp-to-js","owner":"healeycodes","description":"🖨 An optimizing compiler for a Lisp variant. Compiles and executes byte code in a VM. Can also output JavaScript.","archived":false,"fork":false,"pushed_at":"2025-03-08T17:06:10.000Z","size":35,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T15:09:21.056Z","etag":null,"topics":["byte-code","compiler","javascript","lisp","optimization","parser-combinators","transpiler","virtual-machine"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/healeycodes.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":"2024-05-26T11:56:58.000Z","updated_at":"2025-03-08T17:06:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"c1157164-7339-40b8-9c49-ea0ad3851dcb","html_url":"https://github.com/healeycodes/lisp-to-js","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"ee3965ee79b9b0f5736eaad468ddc78490c4c433"},"previous_names":["healeycodes/lisp-to-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Flisp-to-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Flisp-to-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Flisp-to-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Flisp-to-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/healeycodes","download_url":"https://codeload.github.com/healeycodes/lisp-to-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902614,"owners_count":21822261,"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":["byte-code","compiler","javascript","lisp","optimization","parser-combinators","transpiler","virtual-machine"],"created_at":"2024-10-03T17:12:58.516Z","updated_at":"2025-10-06T11:32:39.529Z","avatar_url":"https://github.com/healeycodes.png","language":"Rust","readme":"# lisp-to-js\n\n\u003e My blog posts:\n\u003e\n\u003e - [Compiling Lisp to Bytecode and Running It](https://healeycodes.com/compiling-lisp-to-bytecode-and-running-it)\n\u003e - [Lisp Compiler Optimizations](https://healeycodes.com/lisp-compiler-optimizations)\n\u003e - [Lisp to JavaScript Compiler](https://healeycodes.com/lisp-to-javascript-compiler)\n\n\u003cbr\u003e\n\nThis project is an optmizing Lisp compiler and bytecode VM.\n\nIt can compile to JavaScript, or compile to bytecode and execute in a VM.\n\n\u003cbr\u003e\n\nBytecode VM:\n\n```\n./program --vm --debug \u003c fib10.lisp\n   0: push_closure [\"n\"]\n    -\u003e   0: load_var n\n    -\u003e   1: push_const 2.0\n    -\u003e   2: less_than\n    -\u003e   3: jump 6 // go to 6\n    -\u003e   4: load_var n\n    -\u003e   5: jump 17 // exit\n    -\u003e   6: load_var n\n    -\u003e   7: push_const 1.0\n    -\u003e   8: sub 2\n    -\u003e   9: load_var fib\n    -\u003e  10: call_lambda 1\n    -\u003e  11: load_var n\n    -\u003e  12: push_const 2.0\n    -\u003e  13: sub 2\n    -\u003e  14: load_var fib\n    -\u003e  15: call_lambda 1\n    -\u003e  16: add 2\n   1: store_var fib\n   2: push_const 10.0\n   3: load_var fib\n   4: call_lambda 1\n   5: load_var print\n   6: call_lambda 1\n\n55\n```\n\n\u003cbr\u003e\n\nCompile to JavaScript:\n\n```\n./program --js \u003c fib10.lisp\n/* lisp-to-js */\nlet print = console.log;\n\n\n(() =\u003e {\nlet fib =  ((n) =\u003e  n  \u003c 2 ?  n  : ( fib (( n -1), )+ fib (( n -2), ))\n\n)\n; print ( fib (10, ), )\n})()\n```\n\n\u003cbr\u003e\n\nThe implemented optimizations are constant folding and propagation, and dead\ncode elimination:\n\n```lisp\n; before optimization\n(let ((b 2) (c 3))\n  (print\n    (+\n      (+ b 4 c)\n      (- b c 7)\n  )))\n \n; after optimization\n(let () (print 1))\n```\n\n\u003cbr\u003e\n\nThe Lisp variant is very similar to\n[Little Lisp](https://maryrosecook.com/blog/post/little-lisp-interpreter).\n\n```lisp\n; atoms\n1 ; f64 numbers\na ; symbols\n\n; arithmetic expressions\n(+ 1 2) ; 3\n(- 1 2) ; -1\n\n; control flow expressions\n(\u003c 1 2) ; true\n(\u003e 1 2) ; false\n(if (\u003c 1 2) (+ 10 10) (+ 10 5)) ; 20\n\n; lambda expressions\n(lambda (x) (+ x x)) ; function that doubles\n\n; variable definition\n(let ((a 1)) (print a)) ; prints 1\n(let ((double (lambda (x) (+ x x)))) (double 2)) ; 4\n```\n\n\u003cbr\u003e\n\n### Run\n\nRequired (one of):\n\n- `--js` output JavaScript to stdout\n- `--vm` compile to bytecode and execute in VM\n\nOptional:\n\n- `--optimize` for optimization\n- `--debug` show annotated bytecode\n\n\u003cbr\u003e\n\n### Tests\n\n```\ncargo test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Flisp-to-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhealeycodes%2Flisp-to-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Flisp-to-js/lists"}