Created
April 15, 2024 22:00
-
-
Save kalwalt/52ae29c324016b5cfaa9226cc1c8d02d to your computer and use it in GitHub Desktop.
simple example for virgil and wasm
This file contains 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
// 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 |
This file contains 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
<!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> |
This file contains 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
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