Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SysCall] add support to enum methods, #1169

Merged
merged 15 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Neo.Compiler.CSharp/Diagnostic/DiagnosticId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ static class DiagnosticId
public const string InvalidInitialValue = "NC3005";
public const string IncorrectNEPStandard = "NC3006";
public const string CapturedStaticFieldNotFound = "NC3007";
public const string InvalidType = "NC3008";
public const string InvalidArgument = "NC3009";
}
}
16 changes: 16 additions & 0 deletions src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

if (typeSymbol != null)
{
value = ConvertComplexConstantTypes(typeSymbol, value, syntax);

Check warning on line 59 in src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs

View workflow job for this annotation

GitHub Actions / Test

Possible null reference argument for parameter 'value' in 'object MethodConvert.ConvertComplexConstantTypes(ITypeSymbol typeSymbol, object value, ExpressionSyntax syntax)'.
}

Push(value);
Expand Down Expand Up @@ -192,11 +192,27 @@
// Example: 42 or "Hello"
ConvertLiteralExpression(model, expression);
break;
case TypeOfExpressionSyntax expression:
// Example: typeof(int)
// Note: Neo currently does not support the Type type of C#. The typeof operator here
// will only return the string name of the class/type. This support is added
// to ensure we can process enum parse methods.
ConvertTypeOfExpression(model, expression);
break;
default:
throw new CompilationException(syntax, DiagnosticId.SyntaxNotSupported, $"Unsupported syntax: {syntax}");
}
}

private void ConvertTypeOfExpression(SemanticModel model, TypeOfExpressionSyntax expression)
{
var typeInfo = model.GetTypeInfo(expression.Type);
if (typeInfo.Type == null)
throw new CompilationException(expression, DiagnosticId.InvalidType, $"Invalid type in typeof expression: {expression.Type}");

Push(typeInfo.Type.Name);
}

private static ITypeSymbol? GetTypeSymbol(SyntaxNode? syntaxNode, SemanticModel model)
{
return syntaxNode switch
Expand Down
2 changes: 2 additions & 0 deletions src/Neo.Compiler.CSharp/MethodConvert/Helpers/StackHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private void Push(bool value)
AddInstruction(value ? OpCode.PUSHT : OpCode.PUSHF);
}

private Instruction Ret() => AddInstruction(OpCode.RET);

private Instruction Push(BigInteger number)
{
if (number >= -1 && number <= 16) return AddInstruction(number == -1 ? OpCode.PUSHM1 : OpCode.PUSH0 + (byte)(int)number);
Expand Down
11 changes: 11 additions & 0 deletions src/Neo.Compiler.CSharp/MethodConvert/StackHelpers.OpCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,5 +541,16 @@ private Instruction Assertmsg()
{
return AddInstruction(OpCode.ASSERTMSG);
}

private Instruction JumpIfNot(JumpTarget target)
{
return Jump(OpCode.JMPIFNOT, target);
}

private Instruction Jump(JumpTarget target)
{
return Jump(OpCode.JMP, target);
}

#endregion
}
Loading
Loading