Skip to content

Instantly share code, notes, and snippets.

View Hywan's full-sized avatar
🦀
Oxidising every bit

Ivan Enderlin Hywan

🦀
Oxidising every bit
View GitHub Profile
@Hywan
Hywan / install.sh
Created August 28, 2019 14:15
How to install postgres-ext-wasm
$ # Build the shared library.
$ just build
$ # Install the extension in the Postgres tree.
$ just install
$ # Activate the extension.
$ echo 'CREATE EXTENSION wasm;' | \
psql -h $host -d $database
@Hywan
Hywan / memory.go
Last active May 29, 2019 10:07
Go Wasm example, memory.go
bytes, _ := wasm.ReadBytes("memory.wasm")
instance, _ := wasm.NewInstance(bytes)
defer instance.Close()
// Calls the `return_hello` exported function.
// This function returns a pointer to a string.
result, _ := instance.Exports["return_hello"]()
// Gets the pointer value as an integer.
pointer := result.ToI32()
@Hywan
Hywan / memory.rs
Created May 28, 2019 14:39
Go Wasm example, memory.rs
#[no_mangle]
pub extern fn return_hello() -> *const u8 {
b"Hello, World!\0".as_ptr()
}
@Hywan
Hywan / import.go
Last active May 28, 2019 14:13
Go Wasm example, import.go
package main
// // 1️⃣ Declare the `sum` function signature (see cgo).
//
// #include <stdlib.h>
//
// extern int32_t sum(void *context, int32_t x, int32_t y);
import "C"
import (
@Hywan
Hywan / import.rs
Last active May 28, 2019 14:03
Go Wasm example, import.rs
extern {
fn sum(x: i32, y: i32) -> i32;
}
#[no_mangle]
pub extern fn add1(x: i32, y: i32) -> i32 {
unsafe { sum(x, y) } + 1
}
@Hywan
Hywan / simple.go
Last active May 28, 2019 13:57
Go Wasm example, simple.go
package main
import (
"fmt"
wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)
func main() {
// Reads the WebAssembly module as bytes.
bytes, _ := wasm.ReadBytes("simple.wasm")
@Hywan
Hywan / simple.rs
Created May 28, 2019 13:52
Go Wasm example, simple.rs
#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
x + y
}
@Hywan
Hywan / simple.rs
Last active April 3, 2019 07:46
Wasm examples, Rust part
#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
x + y
}
@Hywan
Hywan / simple.php
Last active April 3, 2019 07:46
Wasm examples, PHP part
<?php
$instance = new Wasm\Instance('simple.wasm');
$result = $instance->sum(1, 2);
var_dump($result); // int(3)
@Hywan
Hywan / gutenberg-post-parser.wasm
Created May 8, 2018 20:30
gutenberg-post-parser experiment
asm=
``````````/. p»»A∞fi m memory
__rg_alloc__rg_oom __rg_dealloc
__rg_realloc __rg_alloc_zeroed allocdeallocroot ŒA « !"((
˛h.Ó ~@#Ak"$ A@k! A4j! Aÿj! A–j! A‘j! A8j!A!
@@@@@@@@ A(j   (("AG (,"rE@ (!A!B+! !A! A!   AËj Aj)7  )7` (! (! (! )!A! ("! ! A0j( ! A j"
AËj" )7  )`7@ E  rr
(!@ ("E
A(l! !@ (@ A(j! AXj"
  Aj