Skip to content

Commit

Permalink
Merge pull request #361 from CactusPuppy/fix-348-again
Browse files Browse the repository at this point in the history
fix 348 again
  • Loading branch information
CactusPuppy authored Feb 29, 2024
2 parents 5624c48 + 9ba70aa commit cf4381f
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 326 deletions.
328 changes: 167 additions & 161 deletions VS Code Extension/overpy.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions VS Code Extension/overpy.min.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/compiler/functions/__add__.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

Expand Down Expand Up @@ -42,7 +42,7 @@ astParsingFunctions.__add__ = function(content) {
}

//A+A -> 2*A
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return new Ast("__multiply__", [getAstFor2(), content.args[0]]);
}

Expand Down
24 changes: 12 additions & 12 deletions src/compiler/functions/__and__.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__and__ = function(content) {

if (enableOptimization) {
//false and A -> false
if (isDefinitelyFalsy(content.args[0])) {
Expand All @@ -37,15 +37,15 @@ astParsingFunctions.__and__ = function(content) {
return content.args[0];
}
//A and A -> A
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return content.args[0];
}
//A and not A -> false
if (content.args[1].name === "__not__" && areAstsEqual(content.args[0], content.args[1].args[0])) {
if (content.args[1].name === "__not__" && areAstsAlwaysEqual(content.args[0], content.args[1].args[0])) {
return getAstForFalse();
}
//(not A) and A -> false
if (content.args[0].name === "__not__" && areAstsEqual(content.args[0].args[0], content.args[1])) {
if (content.args[0].name === "__not__" && areAstsAlwaysEqual(content.args[0].args[0], content.args[1])) {
return getAstForFalse();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__assignTo__.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

Expand All @@ -29,7 +29,7 @@ astParsingFunctions.__assignTo__ = function(content) {
"__raiseToPower__",
"min",
"max",
].includes(content.args[1].name) && areAstsEqual(content.args[0], content.args[1].args[0])) {
].includes(content.args[1].name) && areAstsAlwaysEqual(content.args[0], content.args[1].args[0])) {
var opName = content.args[1].name;
if (opName === "min" || opName === "max") {
opName = "__"+opName+"__";
Expand All @@ -41,7 +41,7 @@ astParsingFunctions.__assignTo__ = function(content) {
]);
}

if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return getAstForUselessInstruction();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__equals__.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__equals__ = function(content) {

if (enableOptimization) {
//If both arguments are numbers, return their comparison.
if (content.args[0].name === "__number__" && content.args[1].name === "__number__") {
return getAstForBool(content.args[0].args[0].numValue === content.args[1].args[0].numValue);
}

//A == A -> true
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return getAstForTrue();
}

Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__greaterThanOrEquals__.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__greaterThanOrEquals__ = function(content) {

if (enableOptimization) {
//If both arguments are numbers, return their comparison.
if (content.args[0].name === "__number__" && content.args[1].name === "__number__") {
return getAstForBool(content.args[0].args[0].numValue >= content.args[1].args[0].numValue);
}
//A >= A -> true
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return getAstForTrue();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__greaterThan__.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__greaterThan__ = function(content) {

if (enableOptimization) {
//If both arguments are numbers, return their comparison.
if (content.args[0].name === "__number__" && content.args[1].name === "__number__") {
return getAstForBool(content.args[0].args[0].numValue > content.args[1].args[0].numValue);
}
//A > A -> false
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return getAstForFalse();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__ifThenElse__.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__ifThenElse__ = function(content) {

if (enableOptimization) {
//ifThenElse(true, A, B) -> A
if (isDefinitelyTruthy(content.args[0])) {
Expand All @@ -29,7 +29,7 @@ astParsingFunctions.__ifThenElse__ = function(content) {
return content.args[2];
}
//ifThenElse(A, B, B) -> B
if (areAstsEqual(content.args[1], content.args[2])) {
if (areAstsAlwaysEqual(content.args[1], content.args[2])) {
return content.args[1];
}
//ifThenElse(not A, B, C) -> ifThenElse(A, C, B)
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/functions/__indexOfArrayValue__.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

Expand All @@ -23,7 +23,7 @@ astParsingFunctions.__indexOfArrayValue__ = function(content) {
/*if (enableOptimization) {
if (content.args[0].name === "__array__") {
for (var i = 0; i < content.args[0].args.length; i++) {
if (areAstsEqual(content.args[0].args[i], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0].args[i], content.args[1])) {
return getAstForNumber(i);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/functions/__inequals__.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
/*
* This file is part of OverPy (https://github.com/Zezombye/overpy).
* Copyright (c) 2019 Zezombye.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

astParsingFunctions.__inequals__ = function(content) {

if (enableOptimization) {
//If both arguments are numbers, return their comparison.
if (content.args[0].name === "__number__" && content.args[1].name === "__number__") {
return getAstForBool(content.args[0].args[0].numValue !== content.args[1].args[0].numValue);
}

//A != A -> true
if (areAstsEqual(content.args[0], content.args[1])) {
if (areAstsAlwaysEqual(content.args[0], content.args[1])) {
return getAstForFalse();
}

Expand Down
Loading

0 comments on commit cf4381f

Please sign in to comment.