diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs index 3cb632bb..5708ddeb 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs @@ -2,6 +2,7 @@ using MrKWatkins.Ast.Listening; using Socordia.CodeAnalysis.AST; using Socordia.CodeAnalysis.AST.Statements; +using Socordia.Compilation; namespace SocordiaC.Compilation.Listeners.Body; diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/AssignmentsLowerer.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/AssignmentsLowerer.cs index 72502a5d..b0d6d280 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/AssignmentsLowerer.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/AssignmentsLowerer.cs @@ -18,9 +18,14 @@ public class AssignmentsLowerer : Replacer { if (!ShortAssignmentOperators.Contains(node.Operator)) return node; + var left = node.Left; + var right = node.Right; + node.Left.RemoveFromParent(); + node.Right.RemoveFromParent(); + var newOperator = node.Operator.Replace("=", ""); - return new BinaryOperatorExpression("=", node.Left, - new BinaryOperatorExpression(newOperator, node.Left, node.Right) + return new BinaryOperatorExpression("=", left, + new BinaryOperatorExpression(newOperator, left, right) ); } } diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs index 7d557f66..0cd3f7b0 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs @@ -1,6 +1,8 @@ using MrKWatkins.Ast.Processing; using Socordia.CodeAnalysis.AST; using Socordia.CodeAnalysis.AST.Expressions; +using Socordia.CodeAnalysis.AST.Statements; +using Socordia.CodeAnalysis.AST.TypeNames; namespace SocordiaC.Compilation.Listeners.Body.Lowering; @@ -10,12 +12,15 @@ public class SwapLowerer : Replacer { if (node.Operator != "<->") return node; + var leftId = (Identifier)node.Left; + var rightId = (Identifier)node.Right; + //todo: implement a swap by introducting a new temp variable and test it var tmpName = Utils.GenerateIdentifier(); - var tmp = new VariableStatement(tmpName, node.Left.Type, node.Left, false); + var tmp = new VariableStatement(tmpName, new NoTypeName(), new Identifier(leftId.Name), false); - var left = new BinaryOperatorExpression("=", node.Left, node.Right); - var right = new BinaryOperatorExpression("=", node.Right, new Identifier(tmpName)); + var left = new BinaryOperatorExpression("=", new Identifier(leftId.Name), new Identifier(rightId.Name)); + var right = new BinaryOperatorExpression("=", new Identifier(rightId.Name), new Identifier(tmpName)); return new Block([tmp, left, right]); } diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/VariableDeclarationListener.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/VariableDeclarationListener.cs index d0887666..76e533ae 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/VariableDeclarationListener.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/VariableDeclarationListener.cs @@ -13,7 +13,7 @@ public class VariableDeclarationListener : Listenertrue scc true - logo.png + icon.ico @@ -19,10 +19,10 @@ - + Always - + PreserveNewest diff --git a/NewSource/SocordiaC/hello.scs b/NewSource/SocordiaC/hello.scs index 2025de9c..3e3d8f64 100644 --- a/NewSource/SocordiaC/hello.scs +++ b/NewSource/SocordiaC/hello.scs @@ -1,8 +1,11 @@ func main() { - let x = 12; - let y = 5; + let mut x = 12; + let mut y = 5; x <-> y; + + print(x); + print(y); } \ No newline at end of file