{"id":13837384,"url":"https://github.com/thomscoder/luna","last_synced_at":"2025-10-30T19:55:07.060Z","repository":{"id":62475150,"uuid":"559151313","full_name":"thomscoder/luna","owner":"thomscoder","description":"🌙 A really tiny WebAssembly compiler for demonstration and educational purposes. Written in Go and built as one of my quests to conquer the WebAssembly dungeon","archived":false,"fork":false,"pushed_at":"2023-07-20T17:59:50.000Z","size":1234,"stargazers_count":308,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-02-17T09:36:55.823Z","etag":null,"topics":["codemotion","compiler","javascript","learning","learning-by-doing","personal-project","programming-language","runtime","sample-code","tinygo","wasm","wasmer","wasmtime","wat2wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://luna-demo.vercel.app","language":"Go","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/thomscoder.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-29T08:05:28.000Z","updated_at":"2024-02-05T07:52:29.000Z","dependencies_parsed_at":"2024-01-13T17:10:34.631Z","dependency_job_id":"75740dc4-4247-45ca-9d7b-f7119ebca5df","html_url":"https://github.com/thomscoder/luna","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/thomscoder/luna","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomscoder%2Fluna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomscoder%2Fluna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomscoder%2Fluna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomscoder%2Fluna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomscoder","download_url":"https://codeload.github.com/thomscoder/luna/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomscoder%2Fluna/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264631213,"owners_count":23640941,"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":["codemotion","compiler","javascript","learning","learning-by-doing","personal-project","programming-language","runtime","sample-code","tinygo","wasm","wasmer","wasmtime","wat2wasm","webassembly"],"created_at":"2024-08-04T15:01:07.810Z","updated_at":"2025-10-30T19:54:57.034Z","avatar_url":"https://github.com/thomscoder.png","language":"Go","readme":"# Luna 🌙\n\nLuna is a reeeaaally tiny, yet expanding, compiler for WebAssembly Text Format, written in Go and built as one of my quest to conquer the WebAssembly dungeon.\n\n(I just wanted to build something like wat2wasm)\n\n\u003cimg src=\"https://i.ibb.co/hdcV1h0/Screenshot-2022-11-01-alle-17-47-06.png\" alt=\"luna\" /\u003e\n\nIt is so tiny that can only make the four operations (addition, subtraction, multiplication and division) with `i32` type numbers.\n\n# Why ❓\n\nI've built Luna because I wanted to learn how to build a compiler while learning WebAssembly. \n\u003cstrong\u003eSo Luna was built for DEMONSTRATION and EDUCATIONAL purposes first.\u003c/strong\u003e\n\nThe goal of Luna is not to do fancy stuff to replace (in a long distant future) solid tools like \u003ca href=\"https://webassembly.github.io/wabt/demo/wat2wasm/\" target=\"_blank\"\u003ewat2wasm\u003c/a\u003e, \u003ca href=\"https://github.com/wasmerio/wasmer\" target=\"_blank\"\u003ewasmer\u003c/a\u003e or others...\n\nThe goal of this project is to become a `useful landmark` for anyone approaching WebAssembly and/or for anyone that wants to develop a compiled-to-wasm programming language. \n\n\u003e I tried to document each section of the code as much as I could (I'm still doing it) with link to resources I've studied while building this, but if you want to improve it, feel free to open issues and pull requests.\n\n# How it works ❓\n\nFollowed the amazing articles about the \u003ca href=\"https://blog.scottlogic.com/2019/05/17/webassembly-compiler.html\" target=\"_blank\"\u003eChasm compiler\u003c/a\u003e (a WAT compiler written in Typescript for the Chasm language) and a guide to write a \u003ca href=\"https://www.bitfalter.com/webassembly-compiler-building-a-compiler\" target=\"_blank\"\u003eWAT compiler\u003c/a\u003e in Rust \n\n- Luna takes a `.wat` file (or string if used in the browser)\n- Splits it into tokens `./compiler/tokenizer.go`\n- Creates a very simple AST of the tokens `./compiler/parser.go`\n- Compiles `./compiler/compiler.go`\n\n# Use it in the browser 🌐\n\nLuna can also be used in the browsers\n\nDemo: https://luna-demo.vercel.app/\n\nThe\n\n```bash\nmake wasm\n```\n\ncommand will build (or update) with TinyGo the `./example/main.wasm` file to be imported in the browser\nIn the `./example` directory there's a working example of how to do that.\n\n\u003e 💡 - `make update` will simply update/replace the existing main.wasm\n\n\u003e 💡 - Check the console to see the tokenizer and the parser outputs\n\n# Aeon Runtime\n\nLuna also implements a really tiny runtime that can run the exported functions.\nRead more about it in `./runtime/README.md`\n\n# Requirements ✋\n\n- Go\n- Tinygo\n- Make\n- syscall/js set up (or simply comment out the startLuna function and the syscall/js import)\n\n# Roadmap\n\n1. \u003ch3\u003eMore interactivity\u003c/h3\u003e\n    Currently Luna supports only the renaming of the exported function and some order scrumbling\n\n2. \u003ch3\u003eMore arithmetics\u003c/h3\u003e\n    Currently Luna supports only addition\n\n3. \u003ch3\u003eExpansion of Wat syntax\u003c/h3\u003e\n\n# Contributing\n\nTo contribute simply \n- create a branch with the feature or the bug fix\n- open pull requests\n\nLuna is by no means finished there are a lot of things that can be implemented and A LOT of things that can be improved. Any suggestions, pull requests, issues or feedback is greatly welcomed!!!\n\nPer aspera ad astra!","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomscoder%2Fluna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomscoder%2Fluna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomscoder%2Fluna/lists"}