How to compile

C/C++

C++ is a high-level programming language developed by Bjarne Stroustrup at Bell Labs. C++ adds object-oriented features to its predecessor, C. C++ is one of the most popular programming language for graphical applications, such as those that run in Windows and Macintosh environments.

const int* hash; // ascii representation
int main() { }
char* hash_addr() { return &hash[0]; }
int hash_len() { return hash.length(); }
* download [emscripten](https://emscripten.org)
* emcc main.c -s WASM=1 -o out.wasm (or main.cpp)
* out.wasm is your exported contract

RUST

Rust is a multi-paradigm system programming language focused on safety, especially safe concurrency. Rust is syntactically similar to C++, but is designed to provide better memory safety while maintaining high performance.

use std::ffi::CString;
use std::os::raw::c_char;

static HELLO: &'static str = "Yes, it Qan";

#[no_mangle]
pub fn get_hello() -> *mut c_char {
    let s = CString::new(HELLO).unwrap();
    s.into_raw()
}

#[no_mangle]
pub fn get_hello_len(i: i32) -> i32 {
    HELLO.len() as i32
}
* cargo init
* rustup target add wasm32-unknown-unknown
* cargo build --target=wasm32-unknown-unknown

Typescript

TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language. TypeScript is designed for development of large applications and transcompiles to JavaScript.

const hash: Uint8Array = ... ;
export function main(): i32 { }
export function hash_addr(): Uint8Array { return hash }
export function hash_len(): i32 { return hash.length() }
* use [assemblyscript](https://github.com/AssemblyScript/assemblyscript) to compile
* asc main.ts -b main.wasm

https://blog.scottlogic.com/2017/10/17/wasm-mandelbrot.html

Last updated