{"id":19378161,"url":"https://github.com/almarklein/wasmfun","last_synced_at":"2025-04-23T19:31:45.606Z","repository":{"id":49371351,"uuid":"90985414","full_name":"almarklein/wasmfun","owner":"almarklein","description":"Getting the hang of WASM - generate WASM from Python","archived":false,"fork":false,"pushed_at":"2017-11-01T09:49:06.000Z","size":223,"stargazers_count":37,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T11:45:16.879Z","etag":null,"topics":["python","wasm"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/almarklein.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}},"created_at":"2017-05-11T13:58:23.000Z","updated_at":"2024-04-30T12:48:11.000Z","dependencies_parsed_at":"2022-08-26T10:31:29.437Z","dependency_job_id":null,"html_url":"https://github.com/almarklein/wasmfun","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/almarklein%2Fwasmfun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almarklein%2Fwasmfun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almarklein%2Fwasmfun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almarklein%2Fwasmfun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/almarklein","download_url":"https://codeload.github.com/almarklein/wasmfun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223932161,"owners_count":17227277,"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":["python","wasm"],"created_at":"2024-11-10T09:05:02.535Z","updated_at":"2024-11-10T09:05:03.015Z","avatar_url":"https://github.com/almarklein.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wasmfun\nGetting the hang of WASM\n\nThe repository provides a (pure) Python library to generate WASM, and\nscripts that use it in various ways. The purpose of this code is for\nme to play with WASM, to get a feel for it and seeing if/how I can put\nit to actual use.\n\n\n## How to use this code\n\nYou can browse the code on Github, the readme's of most subdirs have links to\nhtml pages that show a piece of code, run the WASM that was produced\nfrom it, and show the output.\n\nTo play with this yourself, clone the repository and add the root directory\nto your `PYTHONPATH`. Needs Python 3.x, and nothing more. The (limited) docs\nare [here](DOCS.md).\n\n\n## What is WASM?\n\nWASM, short for WebAssembly, is a low level description of a program. It is\nan intermediate representation (IR) that programs can be compiled to, and\nsubsequently be translated to native instuctions by a WASM virual machine, like\nthe browser. It is not dissimilar from LLVM IR, but is targeted to be able to\nrun in browsers.\n\nCheck out the links down below for (much) more info.\n\nWASM comes with a text and binary format. The x.wasm extension is for\nthe binary format, x.wat is the text format. The browser can only read\nthe binary.\n\nThere ought to be a 1-to-1 relationship between the WASM text format\nand the binary format. However, it looks like there are currently multiple\nvariants of the text format floating around in the web. Perhaps its\nstill under change. Also, the relation is not so direct that you can\nmap \"fields\" 1-on-1; there is some compilation/interpretation needed.\nThis is why this code only works with the binary format.\n\n\n## WASM is pretty darn cool\n\nWASM is primarily made to allow programs written in C/C++ to be run on the web.\nThey already could, sort of, via ASM.js, but WASM makes this much more\nwell-defined and faster (in terms of load time and run-time performance).\n\nBut that's not why I find it so interesting. I'm looking at WASM as a\ncompilation target for dynamic languages, like Python, or perhaps new\nlanguages. Because WASM must be able to run in the browser, it has some\ninteresting features w.r.t. ease of distribution, safety, etc.\n\nIt's important to realize that although WASM is designed to be able to\nrun in the browser, it has no dependencies on anything \"web\". Running on \nthe desktop, or mobile devices, or other is an equally important goal of WASM.\nThis means that any language compiled to WASM can basically run anywhere.\nThis means that any language compiled to WASM can basically run anywhere. I\nintentionally repeated that sentence because its really a big thing!\nMost modern browsers already support WASM, and there are already projects\nthat can run it on desktop too, or e.g. in the JVM.\n\nWASM is inherently safe and has no way (by itself) to e.g. access the\nfile system. Functionality like this is provided by the host environment via\nan import mechanism, the same that is used to dynamically link multiple WASM\nmodules together. This makes a clear separation. E.g. code on the web can\naccess the DOM, code on desktop can access the file system. Also, new \nprogramming languages can piggy back on the host environment by letting it\nprovide functionality for e.g. logging, math, regexp, etc.\n\nAnother nice feature (observed by [Rasmus Andersson](https://rsms.me/wasm-intro))\nis that WASM can also be interpreted/emulated instead of being compiled to\nmachince code. Although it will be much slower, it allows for awesome debugging\ncapabilities. Basically, debug like you do with Python, with a language that's\nnearly as fast as C.\n\n\n## In this repo\n\n**wasmfun:**\nI (partly) implemented an internal representation of (binary) WASM that\ncan be exported to a .wasm file. One can write WASM directly (in Python)\nusing the classes of this internal representation. Or one can use it\nas a compilation target (i.e. use it as the target AST) for new/toy\nlanguages.\n\n**play_manual:**\nUsing the above tool, you can manually write apps in \"raw WASM\". A bit\ntedious, but it works!\n\n**play_calc:**\nImplementation of a *real* simple \"programming language\" that basically acts\nlike a calculator, which is compiled to WASM.\n\n**brainfuck**\nA compiler of brainfuck to WASM.\n\n**simplepy:**\nA compiler for a very-strict-subset of Python to WASM.\n\n**zoof:**\nAn experimental language with a very friendly syntax that compiles to WASM.\nThe parsing and compiling is implemented in Python, but it could eventually\nbe self-hosting, which is when it will start to be come real interesting ...\n\n\n## Links\n\nOfficial and most generally useful:\n    \n* Official docs: http://webassembly.org/docs/\n* Official spec: https://webassembly.github.io/spec\n* Curated list of awesome WASM things: https://github.com/mbasso/awesome-wasm\n\nSome posts that I found useful:\n\n* http://blog.mikaellundin.name/2016/06/19/creating-a-webassembly-binary-and-running-it-in-a-browser.html\n* https://rsms.me/wasm-intro\n* https://gist.github.com/cure53/f4581cee76d2445d8bd91f03d4fa7d3b\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmarklein%2Fwasmfun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falmarklein%2Fwasmfun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmarklein%2Fwasmfun/lists"}