init: repo

This commit is contained in:
2024-03-09 20:11:27 +08:00
commit 01cbcac8ef
79 changed files with 3898 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Canon.Core\Canon.Core.csproj" />
</ItemGroup>
</Project>

35
Canon.Console/Program.cs Normal file
View File

@@ -0,0 +1,35 @@
using Canon.Core;
if (args.Length < 2)
{
Console.WriteLine("Please provide pascal file name with option '-i' at least!");
return;
}
Dictionary<string, string> options = new();
for (int i = 0; i < args.Length; i += 2)
{
options.Add(args[i], args[i + 1]);
}
if (!options.TryGetValue("-i", out string? value))
{
Console.WriteLine("Please provide pascal file name with option '-i' at least!");
return;
}
FileInfo sourceFile = new(value);
if (!sourceFile.Exists)
{
Console.WriteLine("Target source file doesn't exist!");
return;
}
Compiler compiler = new();
using StreamReader source = sourceFile.OpenText();
FileInfo outputFile = new(Path.Combine(sourceFile.DirectoryName!,
Path.GetFileNameWithoutExtension(sourceFile.Name)) + ".c");
await using StreamWriter writer = outputFile.CreateText();
await writer.WriteAsync(compiler.Compile(await source.ReadToEndAsync()));