diff options
author | Morgan Brown <morganbr@users.noreply.github.com> | 2017-09-26 07:16:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 07:16:50 +0300 |
commit | 6622ebe8d8a48e0f7404457bfe0c5bf7b48c81fe (patch) | |
tree | a363e25125db9ccb29c22c402b245eb208d75440 /tests | |
parent | a6eb40c4c0ef9405096f83aa9ef9a64b4876716b (diff) |
Fix strings for WebAssembly (#4592)
Changes that allow loading a printing a frozen string. Includes:
* Implement ldnull and ldind
* Fix brtrue and brfalse for pointers
* Fix the polarity of ceq and friends
* Change functions we can't compile into traps so that they don't break LLVM
* Put call arguments in the right order
* Miscellaneous stack canonicalization fixes (we'll have to revisit this in a more comprehensive way soon)
* Minor diagnosability improvements
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/Simple/HelloWasm/Program.cs | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/tests/src/Simple/HelloWasm/Program.cs b/tests/src/Simple/HelloWasm/Program.cs index 964bb1413..367a23c79 100644 --- a/tests/src/Simple/HelloWasm/Program.cs +++ b/tests/src/Simple/HelloWasm/Program.cs @@ -10,30 +10,22 @@ internal static class Program private static unsafe void Main(string[] args) { Add(1, 2); - TwoCharStr strStruct = new TwoCharStr(); - strStruct.first = (byte)'H'; - strStruct.second = (byte)'\0'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'i'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)' '; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'f'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'r'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'o'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'m'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)' '; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'C'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'#'; - printf((byte*)&strStruct, null); - strStruct.first = (byte)'!'; - printf((byte*)&strStruct, null); + + string s = "Hello from C#!"; + PrintString(s, 14); + } + + private static unsafe void PrintString(string s, int length) + { + fixed (char* curChar = s) + { + for (int i = 0; i < length; i++) + { + TwoByteStr curCharStr = new TwoByteStr(); + curCharStr.first = (byte)(*(curChar + i)); + printf((byte*)&curCharStr, null); + } + } } private static int Add(int a, int b) @@ -45,7 +37,7 @@ internal static class Program private static unsafe extern int printf(byte* str, byte* unused); } -public struct TwoCharStr +public struct TwoByteStr { public byte first; public byte second; |