Skip to content

Commit

Permalink
I get output again
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Apr 19, 2024
1 parent 7af8aa8 commit 1b5d604
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 13 deletions.
1 change: 1 addition & 0 deletions tools/ArduinoCsCompiler/ArduinoCsCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="NanoGenerator\FieldWrapper.cs" />
<Compile Include="NanoGenerator\MethodWrapper.cs" />
<Compile Include="NanoGenerator\ParameterWrapper.cs" />
<Compile Include="NanoGenerator\VoidParameterWrapper.cs" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions tools/ArduinoCsCompiler/ClassMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ClassMember(string name, VariableKind variableType, int token, int sizeOf
BaseTokens = null;
SizeOfField = sizeOfField;
Name = name;
FieldName = name;
OriginalName = name;
}

public ClassMember(FieldInfo field, VariableKind variableType, int token, int sizeOfField, int offset, int staticFieldSize)
Expand All @@ -28,7 +28,7 @@ public ClassMember(FieldInfo field, VariableKind variableType, int token, int si
Field = field;
StaticFieldSize = staticFieldSize;
Name = $"Field: {field.MemberInfoSignature()}";
FieldName = field.Name;
OriginalName = field.Name;
}

public ClassMember(MethodBase method, VariableKind variableType, int token, List<int> baseTokens)
Expand All @@ -39,7 +39,7 @@ public ClassMember(MethodBase method, VariableKind variableType, int token, List
SizeOfField = 0;
Method = method;
Name = $"Method: {method.MethodSignature()}";
FieldName = "(not a field)";
OriginalName = method.IsConstructor ? method.DeclaringType.Name : method.Name;
}

public string Name
Expand All @@ -57,7 +57,7 @@ public FieldInfo? Field
get;
}

public string FieldName
public string OriginalName
{
get;
}
Expand Down
31 changes: 27 additions & 4 deletions tools/ArduinoCsCompiler/ExecutionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,17 @@ internal List<ClassDeclaration> GetArgumentTypes(EquatableMethod methodInfo)
{
cls = GetClass(p1.GetElementType()) ?? throw new InvalidOperationException($"Could not find original type of array {p1}");
}
else if (p1.IsByRef)
else if (p1.IsByRef || p1.IsPointer)
{
var elem = p1.GetElementType();
cls = GetClass(elem) ?? throw new InvalidOperationException($"Could not find real type of ref argument {p1}");
if (elem == typeof(void))
{
cls = null; // Special type
}
else
{
cls = GetClass(elem) ?? throw new InvalidOperationException($"Could not find real type of ref argument {p1}");
}
}
else
{
Expand Down Expand Up @@ -1768,9 +1775,25 @@ public void AddReverseFieldLookupTable()
/// </summary>
/// <param name="type">The type to search</param>
/// <returns>The class or null</returns>
public ClassDeclaration? GetClass(Type? type)
public ClassDeclaration? GetClass(Type type)
{
return Classes.FirstOrDefault(x => x.TheType == type);
if (type.IsEnum)
{
// TODO: We probably need to regenerate the real enums, as otherwise we might get method overload ambiguities
return Classes.FirstOrDefault(x => x.TheType == typeof(int));
}

var ret = Classes.FirstOrDefault(x => x.TheType == type);
if (ret == null)
{
var t2 = GetReplacement(type);
if (t2 != null)
{
ret = Classes.FirstOrDefault(x => x.TheType == t2);
}
}

return ret;
}
}
}
42 changes: 37 additions & 5 deletions tools/ArduinoCsCompiler/NanoGenerator/MethodWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MethodWrapper(ClassDeclaration owner, ClassMember memberField, ExecutionS
_memberField = memberField;
_executionSet = executionSet;
_declaringType = new ClassWrapper(owner, executionSet);
_name = $"Method_{memberField.Token:X8}";
_name = memberField.OriginalName;
_arduinoMethod = executionSet.GetMethod(memberField.Method, false);
}

Expand Down Expand Up @@ -53,6 +53,12 @@ public SymbolKind SymbolKind
return SymbolKind.Method;
}

if (_memberField.Method is ConstructorInfo cf)
{
// Static cctors do not have the IsConstructor flag set
return SymbolKind.Constructor;
}

throw new NotSupportedException("Invalid type detected");
}
}
Expand Down Expand Up @@ -87,8 +93,8 @@ public IMethod Specialize(TypeParameterSubstitution substitution)
public bool ReturnTypeIsRefReadOnly { get; }
public bool IsInitOnly { get; }
public bool ThisIsRefReadOnly { get; }
public IReadOnlyList<ITypeParameter> TypeParameters { get; }
public IReadOnlyList<IType> TypeArguments { get; }
public IReadOnlyList<ITypeParameter> TypeParameters => new List<ITypeParameter>();
public IReadOnlyList<IType> TypeArguments => new List<IType>();
public bool IsExtensionMethod { get; }
public bool IsLocalFunction { get; }
public bool IsConstructor => _memberField.Method.IsConstructor;
Expand All @@ -111,7 +117,26 @@ public bool Equals(IMember? obj, TypeVisitor typeNormalization)
}

public IMember MemberDefinition { get; }
public IType ReturnType { get; }

public IType ReturnType
{
get
{
if (_arduinoMethod == null || _arduinoMethod.Flags.HasFlag(MethodFlags.Ctor))
{
return SpecialType.NoType;
}

Type returnType = _arduinoMethod.MethodInfo.ReturnType;

if (returnType == typeof(void))
{
return SpecialType.NoType; // TODO: Why don't we have a "void" type here?
}

return new ClassWrapper(_executionSet.GetClass(returnType), _executionSet);
}
}

IType? IEntity.DeclaringType => _declaringType;

Expand Down Expand Up @@ -157,7 +182,14 @@ public IReadOnlyList<IParameter> Parameters
var input = _executionSet.GetArgumentTypes(_arduinoMethod.MethodBase);
for (int i = 0; i < input.Count; i++)
{
ret.Add(new ParameterWrapper(input[i], i, _executionSet));
if (input[i] == null)
{
ret.Add(new VoidParameterWrapper());
}
else
{
ret.Add(new ParameterWrapper(input[i], i, _executionSet));
}
}
}

Expand Down
50 changes: 50 additions & 0 deletions tools/ArduinoCsCompiler/NanoGenerator/VoidParameterWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;

namespace ArduinoCsCompiler.NanoGenerator
{
internal class VoidParameterWrapper : IParameter
{
private string _name;

public VoidParameterWrapper()
{
_name = "void";
}

public SymbolKind SymbolKind => SymbolKind.Parameter;
public object? GetConstantValue(bool throwOnInvalidMetadata = false)
{
throw new NotImplementedException();
}

string IVariable.Name => _name;

public IType Type => SpecialType.NoType;
public bool IsConst => false;

string ISymbol.Name => _name;

public IEnumerable<IAttribute> GetAttributes()
{
throw new NotImplementedException();
}

public ReferenceKind ReferenceKind => ReferenceKind.None;
public LifetimeAnnotation Lifetime { get; }
public bool IsRef { get; }
public bool IsOut { get; }
public bool IsIn { get; }
public bool IsParams { get; }
public bool IsOptional { get; }
public bool HasConstantValueInSignature { get; }
public IParameterizedMember? Owner { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>6062496b-4074-4ca3-b254-1bd0eebcd965</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>BlinkingLedNano</RootNamespace>
<AssemblyName>BlinkingLedNano</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="generated.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34526.213
MinimumVisualStudioVersion = 10.0.40219.1
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "BlinkingLedNano", "BlinkingLedNano.nfproj", "{6062496B-4074-4CA3-B254-1BD0EEBCD965}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Release|Any CPU.Build.0 = Release|Any CPU
{6062496B-4074-4CA3-B254-1BD0EEBCD965}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {68D16744-1FD5-4F6D-9EE4-54B829590BDD}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions tools/ArduinoCsCompiler/samples/BlinkingLedNano/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Diagnostics;
using System.Threading;

namespace BlinkingLedNano
{
public class Program
{
public static void OldMain()
{
Debug.WriteLine("Hello from nanoFramework!");

Thread.Sleep(Timeout.Infinite);

// Browse our samples repository: https://github.com/nanoframework/samples
// Check our documentation online: https://docs.nanoframework.net/
// Join our lively Discord community: https://discord.gg/gCyBu8T
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CSharp.BlankApplication")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CSharp.BlankApplication")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.14.2" targetFramework="netnano1.0" />
</packages>

0 comments on commit 1b5d604

Please sign in to comment.