This is my attempt to port the
analogClock.aec from
Linux, Windows and FreeDOS
to WebAssembly, using my new
compiler. This only works in very modern browsers. I'm not too interested in
targeting archaic browsers here. This only works in Firefox 62 and newer or
Chrome 69 and newer (that is, those that support
WebAssembly.Global). After a few years (if not months), all
JavaScript environments will become as capable as they are, rather than like
Internet Explorer.
AEC program output:
You can see the source code of the AEC program
here. I had to implement custom math
functions, because WebAssembly has no fsin and similar
instructions which x86 assembly has.
UPDATE on 18/01/2023: If you want to try out this program in NodeJS, you can
use the following shell script I've written:
if[$(command -v git > /dev/null 2>&1; echo $?)-eq0]then
git clone https://github.com/FlatAssembler/AECforWebAssembly.git
cd AECforWebAssembly
elif[$(command -v wget > /dev/null 2>&1; echo $?)-eq0]then
mkdir AECforWebAssembly
cd AECforWebAssembly
wget https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip
unzip master.zip
cd AECforWebAssembly-master
else
mkdir AECforWebAssembly
cd AECforWebAssembly
curl -o AECforWebAssembly.zip -L https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip# Without the "-L", "curl" will store HTTP Response headers of redirects to the ZIP file instead of the actual ZIP file.
unzip AECforWebAssembly.zip
cd AECforWebAssembly-master
fiif[$(command -v g++ > /dev/null 2>&1; echo $?)-eq0]then
g++ -std=c++11 -o aec AECforWebAssembly.cpp # "-std=c++11" should not be necessary for newer versions of "g++". Let me know if it is, as that probably means I disobeyed some new C++ standard (say, C++23).else
clang++ -o aec AECforWebAssembly.cpp
fi
cd analogClock
../aec analogClock.aec
npx -p wabt wat2wasm analogClock.wat
if["$OS"="Windows_NT"]# https://stackoverflow.com/a/75125384/8902065
# https://www.reddit.com/r/bash/comments/10cip05/comment/j4h9f0x/?utm_source=share&utm_medium=web2x&context=3then
node_version=$(node.exe -v)else# We are presumably running on an UNIX-like system, where storing output of some program into a variable works as expected.
node_version=$(node -v)fi# "node -v" outputs version in the format "v18.12.1"
node_version=${node_version:1}# Remove 'v' at the beginning
node_version=${node_version%\.*}# Remove trailing ".*".
node_version=${node_version%\.*}# Remove trailing ".*".
node_version=$(($node_version))# Convert the NodeJS version number from a string to an integer.if[$node_version -lt11]then
echo "NodeJS version is lower than 11 (it is $node_version), you will probably run into trouble!"fi
node analogClock