public void Accept(BinaryOperationNode node) { switch (node.BinaryOperation) { case BinaryOperation.Assignment: node.Right.Visit(this); // var = val if (node.Left is IdentifierNode) { string identifier = ((IdentifierNode)node.Left).Identifier; // Locals are lowercase HassiumWarning.EnforceCasing(module, node.Left.SourceLocation, identifier, HassiumCasingType.Lower); if (table.Scopes.Count == 2) { table.AddGlobalSymbol(identifier); } if (table.ContainsGlobalSymbol(identifier)) { emit(node.SourceLocation, InstructionType.StoreGlobal, identifier); emit(node.SourceLocation, InstructionType.LoadGlobal, identifier); } else { table.HandleSymbol(identifier); emit(node.SourceLocation, InstructionType.StoreLocal, table.GetSymbol(identifier)); emit(node.SourceLocation, InstructionType.LoadLocal, table.GetSymbol(identifier)); } } // var.attrib = val else if (node.Left is AttributeAccessNode) { AttributeAccessNode accessor = node.Left as AttributeAccessNode; accessor.Left.Visit(this); emit(node.SourceLocation, InstructionType.StoreAttribute, accessor.Right); accessor.Left.Visit(this); } // var [index] = val else if (node.Left is IterableAccessNode) { IterableAccessNode access = node.Left as IterableAccessNode; access.Index.Visit(this); access.Target.Visit(this); emit(node.SourceLocation, InstructionType.StoreIterableElement); } break; case BinaryOperation.Swap: emit(node.SourceLocation, InstructionType.Push, table.GetSymbol(((IdentifierNode)node.Left).Identifier)); emit(node.SourceLocation, InstructionType.Swap, table.GetSymbol(((IdentifierNode)node.Right).Identifier)); break; default: node.VisitChildren(this); emit(node.SourceLocation, InstructionType.BinaryOperation, (int)node.BinaryOperation); break; } }
public void Accept(IterableAccessNode node) { node.Index.Visit(this); node.Target.Visit(this); emit(node.SourceLocation, InstructionType.LoadIterableElement); }