From 3bfcf6614309eb6a30764b160cceef4737f839ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teo=20Samar=C5=BEija?= Date: Sun, 15 Dec 2024 15:43:13 +0100 Subject: [PATCH] Added the TypeOf Test --- CMakeLists.txt | 11 ++++++++++- typeOfTest.aec | 21 +++++++++++++++++++++ typeOfTest.js | 12 ++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 typeOfTest.aec create mode 100644 typeOfTest.js diff --git a/CMakeLists.txt b/CMakeLists.txt index ec0ab3f..df37fd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # https://discord.com/channels/172018499005317120/172018499005317120/807727805080010804 cmake_minimum_required(VERSION 3.10) -project(AECForWebAssembly VERSION 3.0.0) +project(AECForWebAssembly VERSION 3.1.0) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED true) @@ -73,3 +73,12 @@ add_test(NAME chainedComparisonsTestAssembles add_test(NAME chainedComparisonsTestRuns COMMAND node chainedComparisonsTest.js WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_test(NAME typeOfTestCompiles + COMMAND aec typeOfTest.aec + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_test(NAME typeOfTestAssembles + COMMAND npx -q -p wabt wat2wasm typeOfTest.wat + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_test(NAME typeOfTestRuns + COMMAND node typeOfTest.js + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) diff --git a/typeOfTest.aec b/typeOfTest.aec new file mode 100644 index 0000000..544bd99 --- /dev/null +++ b/typeOfTest.aec @@ -0,0 +1,21 @@ +#target WASI + +Function areStringsEqual(PointerToCharacter first, PointerToCharacter second) Which Returns Integer32 Does + While not(ValueAt(first)=0 and ValueAt(second)=0) Loop + If (not(ValueAt(first)=ValueAt(second))) Then + Return 0; + EndIf + first += 1; + second += 1; + EndWhile + Return 1; +EndFunction + +Structure Point Consists Of + Decimal32 x, y, z; +EndStructure + +Function test() Which Returns Integer32 Does + InstantiateStructure Point myPoint; + Return areStringsEqual(TypeOf(myPoint),"Point") and areStringsEqual(TypeOf("Hello world!"),"CharacterPointer"); +EndFunction diff --git a/typeOfTest.js b/typeOfTest.js new file mode 100644 index 0000000..3c07e7e --- /dev/null +++ b/typeOfTest.js @@ -0,0 +1,12 @@ +const fs = require("fs"); +const buffer = fs.readFileSync("typeOfTest.wasm"); +WebAssembly.instantiate(buffer).then((results) => { + const exports = results.instance.exports; + if (exports.test()) { + process.exitCode = 0; + console.log("The TypeOf Test succeeded!"); + } else { + process.exitCode = 1; + console.log("The TypeOf Test failed!"); + } +});