Skip to content

Commit

Permalink
Remove IterationScope
Browse files Browse the repository at this point in the history
Remove context from control nodes
Remove ByteCodeNodeFactory
  • Loading branch information
dain committed Apr 8, 2015
1 parent 8884aaa commit c906e7c
Show file tree
Hide file tree
Showing 26 changed files with 74 additions and 309 deletions.

This file was deleted.

Expand Up @@ -17,38 +17,14 @@ public final class ByteCodeNodes
{
private ByteCodeNodes() {}

public static Block buildBlock(CompilerContext context, ByteCodeNode node)
public static Block buildBlock(ByteCodeNode node, String description)
{
return buildBlock(context, node, null);
}

public static Block buildBlock(CompilerContext context, ByteCodeNode node, String description)
{
Block block;
if (node instanceof Block) {
block = (Block) node;
}
else {
block = new Block(context).append(node);
}
block.setDescription(description);
return block;
}

public static Block buildBlock(CompilerContext context, ByteCodeNodeFactory factory, ExpectedType expectedType)
{
return buildBlock(context, factory, expectedType, null);
}

public static Block buildBlock(CompilerContext context, ByteCodeNodeFactory factory, ExpectedType expectedType, String description)
{
ByteCodeNode node = factory.build(context, expectedType);
Block block;
if (node instanceof Block) {
block = (Block) node;
}
else {
block = new Block(context).append(node);
block = new Block().append(node);
}
block.setDescription(description);
return block;
Expand Down
Expand Up @@ -15,12 +15,9 @@

import com.facebook.presto.byteCode.instruction.LabelNode;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
import org.objectweb.asm.Type;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -35,8 +32,6 @@ public class CompilerContext

private int nextSlot;

private final Deque<IterationScope> iterationScopes = new ArrayDeque<>();

private final LabelNode variableStartLabel = new LabelNode("VariableStart");
private final LabelNode variableEndLabel = new LabelNode("VariableEnd");

Expand Down Expand Up @@ -101,22 +96,6 @@ public Variable declareVariable(ParameterizedType type, String variableName)
return variable;
}

public void pushIterationScope(LabelNode begin, LabelNode end)
{
iterationScopes.push(new IterationScope(begin, end));
}

public void popIterationScope()
{
iterationScopes.pop();
}

// level 1 is the top of the stack
public IterationScope peekIterationScope(int level)
{
return Iterators.get(iterationScopes.iterator(), level - 1, null);
}

public LabelNode getVariableStartLabel()
{
return variableStartLabel;
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -15,9 +15,7 @@

import com.facebook.presto.byteCode.Block;
import com.facebook.presto.byteCode.ByteCodeNode;
import com.facebook.presto.byteCode.ByteCodeNodeFactory;
import com.facebook.presto.byteCode.ByteCodeVisitor;
import com.facebook.presto.byteCode.CompilerContext;
import com.facebook.presto.byteCode.MethodGenerationContext;
import com.facebook.presto.byteCode.instruction.LabelNode;
import com.google.common.collect.ImmutableList;
Expand All @@ -26,61 +24,49 @@
import java.util.List;

import static com.facebook.presto.byteCode.ByteCodeNodes.buildBlock;
import static com.facebook.presto.byteCode.ExpectedType.BOOLEAN;
import static com.facebook.presto.byteCode.ExpectedType.VOID;

public class DoWhileLoop
implements FlowControl
{
public static DoWhileLoopBuilder doWhileLoopBuilder(CompilerContext context)
public static DoWhileLoopBuilder doWhileLoopBuilder()
{
return new DoWhileLoopBuilder(context);
return new DoWhileLoopBuilder();
}

public static class DoWhileLoopBuilder
{
private final CompilerContext context;

private final LabelNode continueLabel = new LabelNode("continue");
private final LabelNode endLabel = new LabelNode("end");

private String comment;
private Block body;
private Block condition;

public DoWhileLoopBuilder(CompilerContext context)
{
this.context = context;
context.pushIterationScope(continueLabel, endLabel);
}

public DoWhileLoopBuilder comment(String format, Object... args)
{
this.comment = String.format(format, args);
return this;
}

public DoWhileLoopBuilder body(ByteCodeNodeFactory body)
public DoWhileLoopBuilder body(ByteCodeNode body)
{
this.body = buildBlock(context, body, VOID, "body");
this.body = buildBlock(body, "body");
return this;
}

public DoWhileLoopBuilder condition(ByteCodeNodeFactory condition)
public DoWhileLoopBuilder condition(ByteCodeNode condition)
{
this.condition = buildBlock(context, condition, BOOLEAN, "condition");
this.condition = buildBlock(condition, "condition");
return this;
}

public DoWhileLoop build()
{
DoWhileLoop doWhileLoop = new DoWhileLoop(context, comment, body, condition, continueLabel, endLabel);
context.popIterationScope();
DoWhileLoop doWhileLoop = new DoWhileLoop(comment, body, condition, continueLabel, endLabel);
return doWhileLoop;
}
}

private final CompilerContext context;
private final String comment;
private final Block body;
private final Block condition;
Expand All @@ -89,9 +75,8 @@ public DoWhileLoop build()
private final LabelNode continueLabel;
private final LabelNode endLabel;

private DoWhileLoop(CompilerContext context, String comment, Block body, Block condition, LabelNode continueLabel, LabelNode endLabel)
private DoWhileLoop(String comment, Block body, Block condition, LabelNode continueLabel, LabelNode endLabel)
{
this.context = context;
this.comment = comment;
this.body = body;
this.condition = condition;
Expand All @@ -109,7 +94,7 @@ public String getComment()
@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext)
{
Block block = new Block(context)
Block block = new Block()
.visitLabel(beginLabel)
.append(body)
.visitLabel(continueLabel)
Expand Down

0 comments on commit c906e7c

Please sign in to comment.