(If you don't want to or don't know how to help me, could you upvote this so that it gets seen by more people?)
I was setting up a very simple program in Wasm, using wat2wasm, because Repl's Wasm Repls are not stable, nor are they properly maintained.
The program would contain two loops, one nested in another, that would increment two variables $i and $j by one, until $i is greater than 12. With each iteration then would output the value of $i, $j, and the result of them multiplied together.
To start, I needed a host language; JavaScript is the most common one, and it has native support for Wasm, since Wasm is the fourth language of the Web, and has finally been adopted as a WC3 standard.
I set up a simple import allowing access to console.log:
Here I had put console.log's optional format string parameter to use, allowing me to format my output in these three specific formats.
I would start off by calling start, then call table with every iteration of the outer loop, and then call assign in every iteration of the inner loop, in order to build of the "body" of the table.
It seems that my first loop, line #14, doesn't execute at all, yet I checked the value of the br_if, and it's 1, I tried negating it, and it only iterated once, instead of all 12 times. I made sure to check that $i was properly being updated too.
Is anyone willing to help me that knows knows what I'm doing wrong?
Update
I attached a Repl to show the code in execution on Repl.
equivalent.mjs shows the equivalent JavaScript that the Wasm maps to.
@firefish Because I was bored, and it was a pretty simple idea, so I was thinking that it could be easy to complete. But it turns out that I was wrong.
Figured it out myself
(If you don't want to or don't know how to help me, could you upvote this so that it gets seen by more people?)
I was setting up a very simple program in Wasm, using wat2wasm, because Repl's Wasm Repls are not stable, nor are they properly maintained.
The program would contain two loops, one nested in another, that would increment two variables
$i
and$j
by one, until$i
is greater than 12.With each iteration then would output the value of
$i
,$j
, and the result of them multiplied together.To start, I needed a host language; JavaScript is the most common one, and it has native support for Wasm, since Wasm is the fourth language of the Web, and has finally been adopted as a WC3 standard.
I set up a simple import allowing access to
console.log
:Here I had put
console.log
's optional format string parameter to use, allowing me to format my output in these three specific formats.I would start off by calling
start
, then calltable
with every iteration of the outer loop, and then callassign
in every iteration of the inner loop, in order to build of the "body" of the table.My Wat was as follows:
It seems that my first loop, line #14, doesn't execute at all, yet I checked the value of the
br_if
, and it's1
, I tried negating it, and it only iterated once, instead of all 12 times.I made sure to check that
$i
was properly being updated too.Is anyone willing to help me that knows knows what I'm doing wrong?
Update
I attached a Repl to show the code in execution on Repl.
equivalent.mjs shows the equivalent JavaScript that the Wasm maps to.
@firefish Because I was bored, and it was a pretty simple idea, so I was thinking that it could be easy to complete. But it turns out that I was wrong.