Created
March 1, 2016 17:54
-
-
Save jonathanvdc/1ee676182c4d29777735 to your computer and use it in GitHub Desktop.
Wasm Structs
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
// Compile with `dsc Struct.ds -platform wasm -Wno-build` | |
public struct Vector2 | |
{ | |
public int X; | |
public int Y; | |
public int LengthSquared() | |
{ | |
return X * X + Y * Y; | |
} | |
} | |
public module StructTest | |
{ | |
public int Allocate() | |
{ | |
Vector2 val; | |
val.X = 3; | |
val.Y = 4; | |
Vector2 copy = val; | |
return copy.LengthSquared(); | |
} | |
} |
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
(module | |
(func | |
$Vector2.LengthSquared | |
(param $stacktop i32) | |
(param $this i32) | |
(result i32) | |
(local $frameptr i32) | |
(local $stackptr i32) | |
(block | |
(set_local $frameptr (get_local $stacktop)) | |
(set_local $stackptr (get_local $frameptr)) | |
(return | |
(i32.add | |
(i32.mul | |
(i32.load (i32.add (get_local $this) (i32.const 0))) | |
(i32.load (i32.add (get_local $this) (i32.const 0)))) | |
(i32.mul | |
(i32.load (i32.add (get_local $this) (i32.const 4))) | |
(i32.load (i32.add (get_local $this) (i32.const 4)))))))) | |
(func | |
$StructTest.Allocate | |
(param $stacktop i32) | |
(result i32) | |
(local $frameptr i32) | |
(local $stackptr i32) | |
(local $tmp0 i32) | |
(local $tmp1 i32) | |
(block | |
(set_local $frameptr (get_local $stacktop)) | |
(set_local $stackptr (get_local $frameptr)) | |
(set_local $stackptr (i32.add (get_local $stackptr) (i32.const 16))) | |
(i32.store (i32.add (get_local $frameptr) (i32.const 0)) (i32.const 3)) | |
(i32.store (i32.add (get_local $frameptr) (i32.const 4)) (i32.const 4)) | |
(set_local $tmp0 (i32.add (get_local $frameptr) (i32.const 8))) | |
(set_local $tmp1 (i32.add (get_local $frameptr) (i32.const 0))) | |
(i32.store | |
(i32.add (get_local $tmp1) (i32.const 0)) | |
(i32.load (i32.add (get_local $tmp0) (i32.const 0)))) | |
(i32.store | |
(i32.add (get_local $tmp1) (i32.const 4)) | |
(i32.load (i32.add (get_local $tmp0) (i32.const 4)))) | |
(return | |
(call | |
$Vector2.LengthSquared | |
(get_local $stackptr) | |
(i32.add (get_local $frameptr) (i32.const 8)))))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment