forked from neo-project/neo-devpack-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTupleExpression.cs
46 lines (42 loc) · 1.76 KB
/
TupleExpression.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2015-2023 The Neo Project.
//
// The Neo.Compiler.CSharp is free software distributed under the MIT
// software license, see the accompanying file LICENSE in the main directory
// of the project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
extern alias scfx;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Neo.VM;
namespace Neo.Compiler;
partial class MethodConvert
{
/// <summary>
/// Converts the code for tuple type into a sequence of instructions.
/// </summary>
/// <param name="model">The semantic model providing context and information about the tuple type.</param>
/// <param name="expression">The syntax representation of the tuple type statement being converted.</param>
/// <example>
/// The tuples feature provides concise syntax to group multiple data elements in a lightweight data structure.
/// The following example shows how you can declare a tuple variable, initialize it, and access its data members:
/// <code>
/// (string, int) t1 = ("chris", 3);
/// Runtime.Log($"Tuple with elements {t1.Item1} and {t1.Item2}.");
/// (string Name, int Count) t2 = ("chris", 3);
/// Runtime.Log($"Sum of {t2.Name} elements is {t2.Count}.");
/// </code>
/// </example>
private void ConvertTupleExpression(SemanticModel model, TupleExpressionSyntax expression)
{
AddInstruction(OpCode.NEWSTRUCT0);
foreach (ArgumentSyntax argument in expression.Arguments)
{
AddInstruction(OpCode.DUP);
ConvertExpression(model, argument.Expression);
AddInstruction(OpCode.APPEND);
}
}
}