@@ -34,6 +34,9 @@ namespace Neo.Compiler
3434{
3535 class MethodConvert
3636 {
37+
38+ #region Fields
39+
3740 private readonly CompilationContext context ;
3841 private CallingConvention _callingConvention = CallingConvention . Cdecl ;
3942 private bool _inline ;
@@ -55,6 +58,10 @@ class MethodConvert
5558 private readonly Stack < ( SwitchLabelSyntax , JumpTarget ) [ ] > _switchStack = new ( ) ;
5659 private readonly Stack < bool > _checkedStack = new ( ) ;
5760
61+ #endregion
62+
63+ #region Properties
64+
5865 public IMethodSymbol Symbol { get ; }
5966 public SyntaxNode ? SyntaxNode { get ; private set ; }
6067 public IReadOnlyList < Instruction > Instructions => _instructions ;
@@ -63,13 +70,21 @@ class MethodConvert
6370 || ( _instructions . Count == 1 && _instructions [ ^ 1 ] . OpCode == OpCode . RET )
6471 || ( _instructions . Count == 2 && _instructions [ ^ 1 ] . OpCode == OpCode . RET && _instructions [ 0 ] . OpCode == OpCode . INITSLOT ) ;
6572
73+ #endregion
74+
75+ #region Constructors
76+
6677 public MethodConvert ( CompilationContext context , IMethodSymbol symbol )
6778 {
6879 this . Symbol = symbol ;
6980 this . context = context ;
7081 this . _checkedStack . Push ( context . Options . Checked ) ;
7182 }
7283
84+ #endregion
85+
86+ #region Variables
87+
7388 private byte AddLocalVariable ( ILocalSymbol symbol )
7489 {
7590 byte index = ( byte ) ( _localVariables . Count + _anonymousVariables . Count ) ;
@@ -102,6 +117,10 @@ private void RemoveLocalVariable(ILocalSymbol symbol)
102117 _localVariables . Remove ( symbol ) ;
103118 }
104119
120+ #endregion
121+
122+ #region Instructions
123+
105124 private Instruction AddInstruction ( Instruction instruction )
106125 {
107126 _instructions . Add ( instruction ) ;
@@ -121,6 +140,10 @@ private SequencePointInserter InsertSequencePoint(SyntaxNodeOrToken syntax)
121140 return new SequencePointInserter ( _instructions , syntax ) ;
122141 }
123142
143+ #endregion
144+
145+ #region Convert
146+
124147 public void Convert ( SemanticModel model )
125148 {
126149 if ( Symbol . IsExtern || Symbol . ContainingType . DeclaringSyntaxReferences . IsEmpty )
@@ -547,7 +570,9 @@ private void ConvertSource(SemanticModel model)
547570 }
548571 _initslot = ! _inline ;
549572 }
573+ #endregion
550574
575+ #region ConvertStatement
551576 private void ConvertStatement ( SemanticModel model , StatementSyntax statement )
552577 {
553578 switch ( statement )
@@ -1229,6 +1254,10 @@ private void ConvertWhileStatement(SemanticModel model, WhileStatementSyntax syn
12291254 PopBreakTarget ( ) ;
12301255 }
12311256
1257+ #endregion
1258+
1259+ #region ConvertExpression
1260+
12321261 private void ConvertExpression ( SemanticModel model , ExpressionSyntax syntax )
12331262 {
12341263 Optional < object ? > constant = model . GetConstantValue ( syntax ) ;
@@ -3243,6 +3272,21 @@ private void ConvertSwitchExpression(SemanticModel model, SwitchExpressionSyntax
32433272 RemoveAnonymousVariable ( anonymousIndex ) ;
32443273 }
32453274
3275+ private void ConvertTupleExpression ( SemanticModel model , TupleExpressionSyntax expression )
3276+ {
3277+ AddInstruction ( OpCode . NEWSTRUCT0 ) ;
3278+ foreach ( ArgumentSyntax argument in expression . Arguments )
3279+ {
3280+ AddInstruction ( OpCode . DUP ) ;
3281+ ConvertExpression ( model , argument . Expression ) ;
3282+ AddInstruction ( OpCode . APPEND ) ;
3283+ }
3284+ }
3285+
3286+ #endregion
3287+
3288+ #region ConvertPattern
3289+
32463290 private void ConvertPattern ( SemanticModel model , PatternSyntax pattern , byte localIndex )
32473291 {
32483292 switch ( pattern )
@@ -3368,16 +3412,11 @@ private void ConvertNotPattern(SemanticModel model, UnaryPatternSyntax pattern,
33683412 AddInstruction ( OpCode . NOT ) ;
33693413 }
33703414
3371- private void ConvertTupleExpression ( SemanticModel model , TupleExpressionSyntax expression )
3372- {
3373- AddInstruction ( OpCode . NEWSTRUCT0 ) ;
3374- foreach ( ArgumentSyntax argument in expression . Arguments )
3375- {
3376- AddInstruction ( OpCode . DUP ) ;
3377- ConvertExpression ( model , argument . Expression ) ;
3378- AddInstruction ( OpCode . APPEND ) ;
3379- }
3380- }
3415+ #endregion
3416+
3417+
3418+
3419+ #region StackHelpers
33813420
33823421 private void Push ( bool value )
33833422 {
@@ -3510,6 +3549,8 @@ private Instruction PushDefault(ITypeSymbol type)
35103549 } ) ;
35113550 }
35123551
3552+ #region LabelsAndTargets
3553+
35133554 private JumpTarget AddLabel ( ILabelSymbol symbol , bool checkTryStack )
35143555 {
35153556 if ( ! _labels . TryGetValue ( symbol , out JumpTarget ? target ) )
@@ -3524,6 +3565,8 @@ private JumpTarget AddLabel(ILabelSymbol symbol, bool checkTryStack)
35243565 return target ;
35253566 }
35263567
3568+ #endregion
3569+
35273570 private void PushSwitchLabels ( ( SwitchLabelSyntax , JumpTarget ) [ ] labels )
35283571 {
35293572 _switchStack . Push ( labels ) ;
@@ -3565,13 +3608,17 @@ private void PopBreakTarget()
35653608 if ( _tryStack . TryPeek ( out ExceptionHandling ? result ) )
35663609 result . BreakTargetCount -- ;
35673610 }
3611+ #endregion
3612+
3613+ #region SlotHelpers
35683614
35693615 private Instruction AccessSlot ( OpCode opcode , byte index )
35703616 {
35713617 return index >= 7
35723618 ? AddInstruction ( new Instruction { OpCode = opcode , Operand = new [ ] { index } } )
35733619 : AddInstruction ( opcode - 7 + index ) ;
35743620 }
3621+ #endregion
35753622
35763623 private Instruction IsType ( VM . Types . StackItemType type )
35773624 {
@@ -3690,6 +3737,8 @@ private void Throw(SemanticModel model, ExpressionSyntax? exception)
36903737 AddInstruction ( OpCode . THROW ) ;
36913738 }
36923739
3740+ #region CallHelpers
3741+
36933742 private Instruction Call ( InteropDescriptor descriptor )
36943743 {
36953744 return AddInstruction ( new Instruction
@@ -4405,6 +4454,7 @@ private void CallVirtual(IMethodSymbol symbol)
44054454 AddInstruction ( OpCode . PICKITEM ) ;
44064455 AddInstruction ( OpCode . CALLA ) ;
44074456 }
4457+ #endregion
44084458 }
44094459
44104460 class MethodConvertCollection : KeyedCollection < IMethodSymbol , MethodConvert >
0 commit comments