Skip to content

Commit

Permalink
Added the TypeOf Test
Browse files Browse the repository at this point in the history
  • Loading branch information
FlatAssembler committed Dec 15, 2024
1 parent d3ad27f commit 3bfcf66
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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})
21 changes: 21 additions & 0 deletions typeOfTest.aec
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions typeOfTest.js
Original file line number Diff line number Diff line change
@@ -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!");
}
});

0 comments on commit 3bfcf66

Please sign in to comment.