Created
          September 18, 2025 14:45 
        
      - 
      
- 
        Save garlic0x1/5b08e7f8dfff6dd767e7fb797b84fdec to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (module | |
| (import "console" "write_bytes_utf8" (func $write_bytes_utf8 (param i32 i32))) | |
| (import "console" "write_object" (func $write_object (param i32))) | |
| (import "console" "write_newline" (func $write_newline)) | |
| (import "console" "write_space" (func $write_space)) | |
| (import "js" "mem" (memory 1)) | |
| (data (i32.const 0) "Fizz") | |
| (data (i32.const 10) "Buzz") | |
| (func $main | |
| (local $i i32) | |
| (loop $loop | |
| local.get $i | |
| i32.const 1 | |
| i32.add | |
| local.set $i | |
| local.get $i | |
| call $write_object | |
| call $write_space | |
| local.get $i | |
| i32.const 3 | |
| i32.rem_s | |
| i32.const 0 | |
| i32.eq | |
| (if | |
| (then | |
| i32.const 0 | |
| i32.const 4 | |
| call $write_bytes_utf8 | |
| call $write_space)) | |
| local.get $i | |
| i32.const 5 | |
| i32.rem_s | |
| i32.const 0 | |
| i32.eq | |
| (if | |
| (then | |
| i32.const 10 | |
| i32.const 4 | |
| call $write_bytes_utf8 | |
| call $write_space)) | |
| call $write_newline | |
| local.get $i | |
| i32.const 100 | |
| i32.lt_s | |
| br_if $loop)) | |
| (export "main" (func $main))) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const { readFileSync } = require("fs"); | |
| const memory = new WebAssembly.Memory({ initial: 1 }); | |
| let write_bytes_utf8 = (offset, length) => { | |
| const bytes = new Uint8Array(memory.buffer, offset, length); | |
| const string = new TextDecoder("utf8").decode(bytes); | |
| process.stdout.write(string); | |
| }; | |
| let write_newline = () => { | |
| process.stdout.write("\n"); | |
| }; | |
| let write_space = () => { | |
| process.stdout.write(" "); | |
| }; | |
| let write_object = (object) => { | |
| process.stdout.write(String(object)); | |
| }; | |
| let foreign_object = { | |
| console: { | |
| write_bytes_utf8: write_bytes_utf8, | |
| write_object: write_object, | |
| write_newline: write_newline, | |
| write_space: write_space, | |
| }, | |
| js: { | |
| mem: memory, | |
| }, | |
| }; | |
| const run = async () => { | |
| const buffer = readFileSync("./test.wasm"); | |
| const module = await WebAssembly.compile(buffer); | |
| const instance = await WebAssembly.instantiate(module, foreign_object); | |
| console.log(instance.exports.main()); | |
| }; | |
| run(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment