Skip to content
Prev Previous commit
Next Next commit
No commit message
  • Loading branch information
Pannous committed Mar 19, 2018
commit 2d44e59fa6d93b135681db69cc7dd94655e192fd
13 changes: 6 additions & 7 deletions examples/hello-assembly/hello-assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
// node -i -e "log_char = c => process.stdout.write(String.fromCodePoint(c));\
// new WebAssembly.Instance(new WebAssembly.Module(require('fs').readFileSync('test.wasm')),{console:{log_char}})"


namespace console {

// imported helper to print a char in node.js
export declare function log_char(v: i32): void;

function log(text:string):void{
print_pointer(<i32>text);// for now glue 'log' to print each char
}
function log(text:string):void{
print_pointer(<i32>text);// glue 'log' to print each char
}
}

function print_pointer(pointer:i32):void{
let length=load<i16>(pointer) // print char by char
pointer+=2 // first bytes in string struct == length
let length=load<i16>(pointer)
pointer+=2 // first bytes in string struct encode length
while(length-->0){
pointer+=2 // utf-16
pointer+=2 //print utf-16 char by char
console.log_char(load<i16>(pointer))
}
}
Expand Down