{"commit":"c8a7656a3f5661a7aa41d5058ccbe19b8b926300","old_file":"src\/BooJs.Compiler\/Steps\/ProcessGoto.boo","new_file":"src\/BooJs.Compiler\/Steps\/ProcessGoto.boo","old_contents":"namespace BooJs.Compiler.Steps\n\nimport Boo.Lang.Compiler.Ast\nimport Boo.Lang.Compiler.Steps\n\nclass ProcessGoto(AbstractTransformerCompilerStep):\n\"\"\"\n Process labels and goto statements\n\n The supported uses are very limited. It's only possible to jump to a label\n previously defined in the same function. No jumps to forward labels are\n allowed.\n\n Even if fully supporting goto statements with forward jumping is theoretically\n possible (similarly on how generators are transformed for example), it would be\n difficult to implement for the benefits it provides.\n\n TODO: Check implementation constraints. Referenced label can only\n be present in the same method and above the goto statement\n\"\"\"\n override def Run():\n if len(Errors) > 0:\n return\n Visit CompileUnit\n\n def OnLabelStatement(node as LabelStatement):\n parent = node.ParentNode as Block\n index = parent.Statements.IndexOf(node)\n\n loop = [| \n while true: pass \n |]\n loop.Block.Statements = parent.Statements.PopRange(index+1)\n # We need to break out of the loop when we reach the end :)\n loop.Block.Statements.Add(BreakStatement())\n\n parent.Statements.Add(loop)\n\n\n\n","new_contents":"namespace BooJs.Compiler.Steps\n\nimport Boo.Lang.Compiler.Ast\nimport Boo.Lang.Compiler.Steps\n\nclass ProcessGoto(AbstractTransformerCompilerStep):\n\"\"\"\n Process labels and goto statements\n\n The supported uses are very limited. It's only possible to jump to a label\n previously defined in the same function. No jumps to forward labels are\n allowed.\n\n Even if fully supporting goto statements with forward jumping is theoretically\n possible (similarly on how generators are transformed for example), it would be\n difficult to implement for the benefits it provides.\n\n TODO: Check implementation constraints. Referenced label can only\n be present in the same method and above the goto statement\n\"\"\"\n override def Run():\n if len(Errors) > 0:\n return\n Visit CompileUnit\n\n def OnLabelStatement(node as LabelStatement):\n # Make sure we only process the statement once\n if node.ContainsAnnotation(self):\n return\n\n node.Annotate(self)\n\n parent = node.ParentNode as Block\n index = parent.Statements.IndexOf(node)\n\n loop = [| \n while true: pass \n |]\n loop.Block.Statements = parent.Statements.PopRange(index+1)\n # We need to break out of the loop when we reach the end :)\n loop.Block.Statements.Add(BreakStatement())\n\n parent.Statements.Add(loop)\n","subject":"Make sure Goto is only processed once","message":"Make sure Goto is only processed once\n","lang":"Boo","license":"mit","repos":"drslump\/BooJS,drslump\/BooJS,drslump\/BooJS,drslump\/BooJS"} {"commit":"be262a94a54dc130cac5d7e2710a5ab284a5b9d1","old_file":"src\/BooJs.Compiler\/Steps\/NormalizeGeneratorExpression.boo","new_file":"src\/BooJs.Compiler\/Steps\/NormalizeGeneratorExpression.boo","old_contents":"namespace BooJs.Compiler.Steps\n\nimport Boo.Lang.Compiler.Ast\nimport Boo.Lang.Compiler.Steps\n\nclass NormalizeGeneratorExpression(AbstractTransformerCompilerStep):\n\"\"\"\n Converts generator expressions to a simpler format:\n\n ( i*2 for i in range(3) )\n ---\n { __gen = []; for i in range(3): __gen.push(i*2); return __gen }()\n\"\"\"\n def LeaveGeneratorExpression(node as GeneratorExpression):\n # ( i*2 for i as int in range(3) ) => ( expression for declarations in iterator if filter )\n\n # Build a loop statement with the details from the generator\n loop = ForStatement()\n loop.Declarations = node.Declarations\n loop.Iterator = node.Iterator\n if not node.Filter:\n loop.Block = [|\n block:\n _gen.push($(node.Expression))\n |].Body\n else:\n loop.Block = [|\n block:\n _gen.push($(node.Expression)) if $(node.Filter.Condition)\n |].Body\n\n # Build the body of the anonymous function\n body = [|\n block:\n $loop\n return _gen\n |].Body\n\n # Replace the generator expression with the result of executing the anonymous function\n ReplaceCurrentNode([| {_gen as (object)| $(body) }([]) |])\n","new_contents":"namespace BooJs.Compiler.Steps\n\nimport Boo.Lang.Compiler.Ast\nimport Boo.Lang.Compiler.Steps\n\nclass NormalizeGeneratorExpression(AbstractTransformerCompilerStep):\n\"\"\"\n Converts generator expressions to a simpler format:\n\n ( i*2 for i in range(3) )\n ---\n { __gen = []; for i in range(3): __gen.push(i*2); return __gen }()\n\"\"\"\n\n # Keep track of last visited method\n _method as Method\n def OnMethod(node as Method):\n last = _method\n _method = node\n super(node)\n _method = last\n\n def OnListLiteralExpression(node as ListLiteralExpression):\n \"\"\" If generator is contained in a list literal, remove the list literal\n \"\"\"\n if len(node.Items) == 1 and node.Items.First.NodeType == NodeType.GeneratorExpression:\n result = Visit(node.Items.First)\n ReplaceCurrentNode result\n return\n\n super(node)\n\n def LeaveGeneratorExpression(node as GeneratorExpression):\n \"\"\" Convert generator expressions to a sequence:\n\n ( i*2 for i in range(3) ) => @(__gen = [], Boo.each(range(3), { i | __gen.push(i*2) }), __gen)\n\n \"\"\"\n # Make sure the __gen variable is declared\n _method.Locals.Add(Local(node.LexicalInfo, '__gen'))\n\n if node.Filter:\n lambda = [| { $(node.Filter.Condition) and __gen.push( $(node.Expression) ) } |]\n else:\n lambda = [| { __gen.push( $(node.Expression) ) } |]\n\n lambda.LexicalInfo = node.LexicalInfo\n for decl in node.Declarations:\n lambda.Parameters.Add(ParameterDeclaration(node.LexicalInfo, Name: decl.Name))\n\n result = [| @(__gen = [], Boo.each($(node.Iterator), $lambda), __gen) |]\n ReplaceCurrentNode result\n\n","subject":"Use sequence instead of self execution functions","message":"Use sequence instead of self execution functions\n","lang":"Boo","license":"mit","repos":"drslump\/BooJS,drslump\/BooJS,drslump\/BooJS,drslump\/BooJS"}