Skip to content

Commit

Permalink
rename addtarget
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed Aug 25, 2024
1 parent e9484ee commit 94b1e80
Show file tree
Hide file tree
Showing 32 changed files with 219 additions and 238 deletions.
3 changes: 1 addition & 2 deletions src/Neo.Compiler.CSharp/MethodConvert/ConstructorConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private void ProcessStaticFields(SemanticModel model)
InvokeMethod(model, method);
}
}
_instructionsBuilder.Push(virtualMethods.Length);
_instructionsBuilder.Pack();
_instructionsBuilder.Pack(virtualMethods.Length);
_instructionsBuilder.StSFld(fieldIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ private void ConvertElementAccessCoalesceAssignment(SemanticModel model, Element
CallMethodWithConvention(model, property.GetMethod!, CallingConvention.StdCall);
_instructionsBuilder.Dup();
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.Nip();
_instructionsBuilder.Nip();
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Drop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.Drop().AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.Reverse4();
Expand All @@ -101,14 +101,14 @@ private void ConvertElementAccessCoalesceAssignment(SemanticModel model, Element
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.PickItem();
_instructionsBuilder.JmpL(endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.Reverse4();
_instructionsBuilder.Reverse3();
_instructionsBuilder.SetItem();
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertIdentifierNameCoalesceAssignment(SemanticModel model, IdentifierNameSyntax left, ExpressionSyntax right)
Expand Down Expand Up @@ -161,7 +161,7 @@ private void ConvertFieldIdentifierNameCoalesceAssignment(SemanticModel model, I
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.LdSFld(index);
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.StSFld(index);
Expand All @@ -175,17 +175,17 @@ private void ConvertFieldIdentifierNameCoalesceAssignment(SemanticModel model, I
_instructionsBuilder.Over();
_instructionsBuilder.PickItem();
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.PickItem();
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.Reverse4();
_instructionsBuilder.Reverse3();
_instructionsBuilder.SetItem();
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertLocalIdentifierNameCoalesceAssignment(SemanticModel model, ILocalSymbol left, ExpressionSyntax right)
Expand All @@ -194,14 +194,14 @@ private void ConvertLocalIdentifierNameCoalesceAssignment(SemanticModel model, I
JumpTarget endTarget = new();
LdLocSlot(left);
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
LdLocSlot(left);
_instructionsBuilder.JmpL(endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
StLocSlot(left);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertParameterIdentifierNameCoalesceAssignment(SemanticModel model, IParameterSymbol left, ExpressionSyntax right)
Expand All @@ -210,14 +210,14 @@ private void ConvertParameterIdentifierNameCoalesceAssignment(SemanticModel mode
JumpTarget endTarget = new();
LdArgSlot(left);
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
LdArgSlot(left);
_instructionsBuilder.JmpL(endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
StArgSlot(left);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertPropertyIdentifierNameCoalesceAssignment(SemanticModel model, IPropertySymbol left, ExpressionSyntax right)
Expand Down Expand Up @@ -247,7 +247,7 @@ private void ConvertPropertyIdentifierNameCoalesceAssignment(SemanticModel model
_instructionsBuilder.Tuck();
CallMethodWithConvention(model, left.SetMethod!, CallingConvention.StdCall);
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertFieldMemberAccessCoalesceAssignment(SemanticModel model, MemberAccessExpressionSyntax left, ExpressionSyntax right, IFieldSymbol field)
Expand All @@ -259,10 +259,10 @@ private void ConvertFieldMemberAccessCoalesceAssignment(SemanticModel model, Mem
byte index = Context.AddStaticField(field);
_instructionsBuilder.LdSFld(index);
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.LdSFld(index);
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.StSFld(index);
Expand All @@ -276,17 +276,17 @@ private void ConvertFieldMemberAccessCoalesceAssignment(SemanticModel model, Mem
_instructionsBuilder.Over();
_instructionsBuilder.PickItem();
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.PickItem();
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Dup();
_instructionsBuilder.Reverse4();
_instructionsBuilder.Reverse3();
_instructionsBuilder.SetItem();
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertPropertyMemberAccessCoalesceAssignment(SemanticModel model, MemberAccessExpressionSyntax left, ExpressionSyntax right, IPropertySymbol property)
Expand All @@ -311,14 +311,14 @@ private void ConvertPropertyMemberAccessCoalesceAssignment(SemanticModel model,
CallMethodWithConvention(model, property.GetMethod!);
_instructionsBuilder.Dup();
_instructionsBuilder.IsNull();
_instructionsBuilder.Jump(OpCode.JMPIF_L, assignmentTarget);
_instructionsBuilder.JmpIfL(assignmentTarget);
_instructionsBuilder.Nip();
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
assignmentTarget.Instruction = _instructionsBuilder.Drop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.Drop().AddTarget(assignmentTarget);
ConvertExpression(model, right);
_instructionsBuilder.Tuck();
CallMethodWithConvention(model, property.SetMethod!, CallingConvention.StdCall);
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ private void ConvertLogicalOrExpression(SemanticModel model, ExpressionSyntax le
_instructionsBuilder.JmpIfNotL(rightTarget);
_instructionsBuilder.Push(true);
_instructionsBuilder.JmpL(endTarget);
rightTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(rightTarget);
ConvertExpression(model, right);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertLogicalAndExpression(SemanticModel model, ExpressionSyntax left, ExpressionSyntax right)
Expand All @@ -119,9 +119,9 @@ private void ConvertLogicalAndExpression(SemanticModel model, ExpressionSyntax l
_instructionsBuilder.JmpIfL(rightTarget);
_instructionsBuilder.Push(false);
_instructionsBuilder.JmpL(endTarget);
rightTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(rightTarget);
ConvertExpression(model, right);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertIsExpression(SemanticModel model, ExpressionSyntax left, ExpressionSyntax right)
Expand All @@ -141,7 +141,7 @@ private void ConvertAsExpression(SemanticModel model, ExpressionSyntax left, Exp
_instructionsBuilder.JmpIfL(endTarget);
_instructionsBuilder.Drop();
_instructionsBuilder.Push((object?)null);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

private void ConvertCoalesceExpression(SemanticModel model, ExpressionSyntax left, ExpressionSyntax right)
Expand All @@ -153,6 +153,6 @@ private void ConvertCoalesceExpression(SemanticModel model, ExpressionSyntax lef
_instructionsBuilder.JmpIfNotL(endTarget);
_instructionsBuilder.Drop();
ConvertExpression(model, right);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void ConvertCastExpression(SemanticModel model, CastExpressionSyntax exp
_instructionsBuilder.Push(33);
_instructionsBuilder.JmpEqL(endTarget);
_instructionsBuilder.Throw();
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
break;
case ("ByteString", "UInt160"):
Expand All @@ -79,7 +79,7 @@ private void ConvertCastExpression(SemanticModel model, CastExpressionSyntax exp
_instructionsBuilder.Push(20);
_instructionsBuilder.JmpEqL(endTarget);
_instructionsBuilder.Throw();
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
break;
case ("ByteString", "UInt256"):
Expand All @@ -93,7 +93,7 @@ private void ConvertCastExpression(SemanticModel model, CastExpressionSyntax exp
_instructionsBuilder.Push(32);
_instructionsBuilder.JmpEqL(endTarget);
_instructionsBuilder.Throw();
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
break;
case ("SByte", "Byte"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private void ConvertGenericCollectionExpression(SemanticModel model, CollectionE
{
ConvertElement(model, expression.Elements[i]);
}
_instructionsBuilder.Push(expression.Elements.Count);
_instructionsBuilder.Pack();
_instructionsBuilder.Pack(expression.Elements.Count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ private void ConvertConditionalAccessExpression(SemanticModel model, Conditional
{
JumpTarget endTarget = new();
_instructionsBuilder.JmpL(endTarget);
nullTarget.Instruction = _instructionsBuilder.Drop();
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.Drop().AddTarget(nullTarget);
_instructionsBuilder.AddTarget(endTarget);
}
else
{
nullTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(nullTarget);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ private void ConvertConditionalExpression(SemanticModel model, ConditionalExpres
_instructionsBuilder.JmpIfNotL(falseTarget);
ConvertExpression(model, expression.WhenTrue);
_instructionsBuilder.JmpL(endTarget);
falseTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(falseTarget);
ConvertExpression(model, expression.WhenFalse);
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}
}
20 changes: 10 additions & 10 deletions src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ private void EnsureIntegerInRange(ITypeSymbol type)
JumpTarget checkUpperBoundTarget = new(), adjustTarget = new(), endTarget = new();
_instructionsBuilder.Dup();
_instructionsBuilder.Push(minValue);
_instructionsBuilder.Jump(OpCode.JMPGE_L, checkUpperBoundTarget);
_instructionsBuilder.JmpGeL(checkUpperBoundTarget);
if (_checkedStack.Peek())
_instructionsBuilder.Throw();
else
_instructionsBuilder.Jump(OpCode.JMP_L, adjustTarget);
checkUpperBoundTarget.Instruction = _instructionsBuilder.Dup();
_instructionsBuilder.JmpL(adjustTarget);
_instructionsBuilder.Dup().AddTarget(checkUpperBoundTarget);
_instructionsBuilder.Push(maxValue);
_instructionsBuilder.Jump(OpCode.JMPLE_L, endTarget);
_instructionsBuilder.JmpLeL(endTarget);
if (_checkedStack.Peek())
{
_instructionsBuilder.Throw();
Expand All @@ -287,12 +287,12 @@ private void EnsureIntegerInRange(ITypeSymbol type)
{
_instructionsBuilder.Dup();
_instructionsBuilder.Push(maxValue);
_instructionsBuilder.Jump(OpCode.JMPLE_L, endTarget);
_instructionsBuilder.JmpLeL(endTarget);
_instructionsBuilder.Push(mask + 1);
_instructionsBuilder.Sub();
}
}
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(endTarget);
}

/// <summary>
Expand Down Expand Up @@ -337,12 +337,12 @@ private void ConvertObjectToString(SemanticModel model, ExpressionSyntax express
{
ConvertExpression(model, expression);
JumpTarget falseTarget = new();
_instructionsBuilder.Jump(OpCode.JMPIFNOT_L, falseTarget);
_instructionsBuilder.JmpIfNotL(falseTarget);
_instructionsBuilder.Push("True");
JumpTarget endTarget = new();
_instructionsBuilder.Jump(OpCode.JMP_L, endTarget);
falseTarget.Instruction = _instructionsBuilder.Push("False");
endTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.JmpL(endTarget);
_instructionsBuilder.Push("False").AddTarget(falseTarget);
_instructionsBuilder.AddTarget(endTarget);
break;
}
case "byte[]":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ private void ConvertInitializerExpression(SemanticModel model, IArrayTypeSymbol
{
for (int i = expression.Expressions.Count - 1; i >= 0; i--)
ConvertExpression(model, expression.Expressions[i]);
_instructionsBuilder.Push(expression.Expressions.Count);
_instructionsBuilder.Pack();
_instructionsBuilder.Pack(expression.Expressions.Count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ private void ConvertSwitchExpression(SemanticModel model, SwitchExpressionSyntax
}
ConvertExpression(model, arm.Expression);
_instructionsBuilder.JmpL(breakTarget);
nextTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(nextTarget);
}
_instructionsBuilder.LdLoc(anonymousIndex);
_instructionsBuilder.Throw();
breakTarget.Instruction = _instructionsBuilder.Nop();
_instructionsBuilder.AddTarget(breakTarget);
RemoveAnonymousVariable(anonymousIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void EmitCall(MethodConvert target)
if (target._inline && !Context.Options.NoInline)
EmitInlineInstructions(target);
else
_instructionsBuilder.Jump(OpCode.CALL_L, target._startTarget);
_instructionsBuilder.Jump(OpCode.CALL_L, target._startTarget);
}

// Helper method to emit inline instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ private void CreateObject(SemanticModel model, ITypeSymbol type, InitializerExpr
{
for (int i = fields.Length - 1; i >= 0; i--)
InitializeFieldForObject(model, fields[i], initializer);
_instructionsBuilder.Push(fields.Length);
_instructionsBuilder.Pack();
_instructionsBuilder.Pack(fields.Length);
}
var virtualMethods = members.OfType<IMethodSymbol>().Where(p => p.IsVirtualMethod()).ToArray();
if (type.IsRecord || virtualMethods.Length <= 0) return;
Expand Down
3 changes: 1 addition & 2 deletions src/Neo.Compiler.CSharp/MethodConvert/Helpers/SlotHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ private void ProcessMultipleParamsArguments(SemanticModel model, IReadOnlyList<S
var expression = ExtractExpression(arguments[i]);
ConvertExpression(model, expression);
}
_instructionsBuilder.Push(arguments.Count - parameter.Ordinal);
_instructionsBuilder.Pack();
_instructionsBuilder.Pack(arguments.Count - parameter.Ordinal);
}

private void ProcessOutArgument(SemanticModel model, IMethodSymbol methodSymbol, IReadOnlyList<SyntaxNode> arguments, IParameterSymbol parameter)
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Compiler.CSharp/MethodConvert/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static Instruction()
}
}

internal Instruction SetTarget(JumpTarget target)
internal Instruction AddTarget(JumpTarget target)
{
target.Instruction = this;
return this;
Expand Down
Loading

0 comments on commit 94b1e80

Please sign in to comment.