Skip to content

Commit

Permalink
Used DataView instead of TypedArray in Analog Clock
Browse files Browse the repository at this point in the history
  • Loading branch information
FlatAssembler committed Mar 8, 2025
1 parent 38771c3 commit 3255ede
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
8 changes: 6 additions & 2 deletions analogClock/analogClock.aec
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Function updateClockToTime(Integer32 hour, Integer32 minute,
(abs(atan2(sin(185), cos(185)) - 185) > 1) or
(abs(atan2(sin(275), cos(275)) - 275) > 1) or
(abs(arcsin(sin(60)) - 60) > 1) or (abs(arccos(cos(60)) - 60) > 1)) Then {
logString("\"atan2\" function seems not to work!\n");
logString("The cyclometric functions seem not to work!\n");
logString("atan2(sin(5), cos(5))=");
logInteger(atan2(sin(5), cos(5)));
logString("\natan2(sin(95),cos(95))=");
Expand All @@ -283,6 +283,10 @@ Function updateClockToTime(Integer32 hour, Integer32 minute,
logInteger(atan2(sin(185), cos(185)));
logString("\natan2(sin(275),cos(275))=");
logInteger(atan2(sin(275), cos(275)));
logString("\narcsin(sin(60))=");
logInteger(arcsin(sin(60)));
logString("\narccos(cos(60))=");
logInteger(arccos(cos(60)));
logString("\n\n");
}
EndIf;
Expand Down Expand Up @@ -585,7 +589,7 @@ j:
strcat(signature, " Teo Samarzija");
logString("Signature has length of: ");
logInteger(strlen(signature));
logString(" \n\n"); // Let's mark the last log of this function like this.
logString("\n\n"); // Let's mark the last log of this function like this.
i:
= windowWidth * (windowHeight - 3);
j:
Expand Down
6 changes: 4 additions & 2 deletions analogClock/analogClock.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ <h1>Analog Clock</h1>
let addressOfOutput = getAddressOfOutput();
let addressOfColors = getAddressOfColors();
let bytes = new Uint8Array(memory.buffer, addressOfOutput, 80 * 23);
let colors = new Uint32Array(memory.buffer, addressOfColors, 80 * 23);
let dataView = new DataView(memory.buffer);
let str = "";
for (let i = 0; i < 80 * 23; i++)
str +=
Expand All @@ -215,7 +215,9 @@ <h1>Analog Clock</h1>
" y=" +
Math.floor(i / 80) * 14.5 +
' fill="' +
getStringAtAddress(colors[i]) +
getStringAtAddress(
dataView.getUint32(addressOfColors + 4 * i, true),
) +
'">' +
String.fromCharCode(bytes[i]) +
"<\/text>";
Expand Down
48 changes: 26 additions & 22 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ AssemblyCode TreeNode::compile(CompilationContext context) const {
AssemblyCode
TreeNode::compileAPointer(const CompilationContext &context) const {
if (text == "ValueAt(")
return children[0].compile(context);
return children.at(0).compile(context);
if (context.localVariables.count(text) and text.back() != '[')
return AssemblyCode(
"(i32.sub\n\t(global.get $stack_pointer)\n\t(i32.const " +
Expand Down Expand Up @@ -1791,7 +1791,8 @@ TreeNode::compileAPointer(const CompilationContext &context) const {
? basicDataTypeSizes.at(typeOfTheCurrentNode)
: context.structureSizes.at(typeOfTheCurrentNode)) +
")\n" +
std::string(convertToInteger32(children[0], context).indentBy(2)) +
std::string(
convertToInteger32(children.at(0), context).indentBy(2)) +
"\n\t)\n)",
AssemblyCode::AssemblyType::i32);
}
Expand All @@ -1818,7 +1819,8 @@ TreeNode::compileAPointer(const CompilationContext &context) const {
? basicDataTypeSizes.at(getType(context))
: context.structureSizes.at(getType(context))) +
")\n" +
std::string(convertToInteger32(children[0], context).indentBy(3)) +
std::string(
convertToInteger32(children.at(0), context).indentBy(3)) +
"\n\t)\n)",
AssemblyCode::AssemblyType::i32);
}
Expand All @@ -1828,46 +1830,48 @@ TreeNode::compileAPointer(const CompilationContext &context) const {
std::find_if(context.structures.begin(), context.structures.end(),
[=](structure str) { return str.name == structureName; });
unsigned offset = iteratorPointingToTheStructure->memberOffsetInBytes.at(
children[1].text);
if (children[1].text.back() == '[') // If it's an array inside of a
// structure
children.at(1).text);
if (children.at(1).text.back() == '[') // If it's an array inside of a
// structure
return AssemblyCode(
"(i32.add\n" + children[0].compileAPointer(context).indentBy(1) +
"(i32.add\n" + children.at(0).compileAPointer(context).indentBy(1) +
"\n\t(i32.add\n\t\t(i32.const " + std::to_string(offset) +
") ;;The offset of the structure member " + structureName + "." +
children[1].text + "\n\t\t(i32.mul\n\t\t\t(i32.const " +
children.at(1).text + "\n\t\t(i32.mul\n\t\t\t(i32.const " +
std::to_string(
isPointerType(iteratorPointingToTheStructure->memberTypes.at(
children[1].text))
children.at(1).text))
? 4
: context.structureSizes.count(
iteratorPointingToTheStructure->memberTypes.at(
children[1].text))
children.at(1).text))
? context.structureSizes.at(
iteratorPointingToTheStructure->memberTypes.at(
children[1].text))
children.at(1).text))
: basicDataTypeSizes.at(
iteratorPointingToTheStructure->memberTypes.at(
children[1].text))) +
children.at(1).text))) +
") ;;Size of the type \"" +
iteratorPointingToTheStructure->memberTypes.at(children[1].text) +
iteratorPointingToTheStructure->memberTypes.at(
children.at(1).text) +
"\"\n" +
convertToInteger32(children[1].children[0], context).indentBy(3) +
convertToInteger32(children.at(1).children.at(0), context)
.indentBy(3) +
"\n\t\t)\n\t)\n)",
AssemblyCode::AssemblyType::i32);
else
return AssemblyCode("(i32.add\n" +
children[0].compileAPointer(context).indentBy(1) +
"\n\t(i32.const " + std::to_string(offset) +
") ;;The offset of the structure member " +
structureName + "." + children[1].text + "\n)",
AssemblyCode::AssemblyType::i32);
return AssemblyCode(
"(i32.add\n" + children.at(0).compileAPointer(context).indentBy(1) +
"\n\t(i32.const " + std::to_string(offset) +
") ;;The offset of the structure member " + structureName + "." +
children.at(1).text + "\n)",
AssemblyCode::AssemblyType::i32);
}
if (text == "->") {
TreeNode dotOperator(".", lineNumber, columnNumber);
TreeNode valueAtOperator("ValueAt(", lineNumber, columnNumber);
valueAtOperator.children.push_back(children[0]);
dotOperator.children = <% valueAtOperator, children[1] %>;
valueAtOperator.children.push_back(children.at(0));
dotOperator.children = <% valueAtOperator, children.at(1) %>;
return dotOperator.compileAPointer(context);
}
std::cerr << "Line " << lineNumber << ", Column " << columnNumber
Expand Down

0 comments on commit 3255ede

Please sign in to comment.