Skip to content

Instantly share code, notes, and snippets.

@kalwalt
Created April 15, 2024 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalwalt/52ae29c324016b5cfaa9226cc1c8d02d to your computer and use it in GitHub Desktop.
Save kalwalt/52ae29c324016b5cfaa9226cc1c8d02d to your computer and use it in GitHub Desktop.
simple example for virgil and wasm
// simple build script to compile the simple.v3 file to wasm
// it is required to have the virgil/bin and virgil/bin/dev in the PATH as described in the official documentation
// https://github.com/titzer/virgil
v3c -target=wasm simple.v3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple example</title>
</head>
<body>
<script>
var instance;
WebAssembly.instantiateStreaming(fetch("simple.wasm"), {}).then(
obj => {
instance = obj.instance;
console.log(instance);
//var c = instance.exports.init();
var n = instance.exports.numberOfPoints();
console.log(n);
var c = instance.exports.init();
console.log(c);
}
).catch(e => console.log(e));
</script>
</body>
</html>
class Point {
var x: u8;
var y: u8;
}
component Test {
var numberPoints: int;
var point: Point;
}
var c = Test.numberPoints = 1;
var p = Point.new();
def init() -> (u8, u8) {
p.x = 2;
p.y = 4;
return (p.x, p.y);
}
def numberOfPoints() -> int {
return Test.numberPoints;
}
def main(){}
export init;
export numberOfPoints;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment