restructure

This commit is contained in:
nub31
2025-06-12 23:37:28 +02:00
parent 7f6a825c01
commit bf4db69f86
73 changed files with 43 additions and 40 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
src/tools/syntax-highlighting/out
tools/syntax-highlighting/out
bin
bin-int

View File

@@ -1,2 +1,2 @@
#!/bin/bash
dotnet run --project src/lang/Nub.Lang.CLI/ example
dotnet run --project src/Nub.Lang.CLI/ example

View File

@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -13,4 +13,12 @@
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Runtime\entry.s" />
<EmbeddedResource Include="Runtime\nub_memcpy.s" />
<EmbeddedResource Include="Runtime\nub_memset.s" />
<EmbeddedResource Include="Runtime\nub_panic.s" />
<EmbeddedResource Include="Runtime\nub_strcmp.s" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Reflection;
using Nub.Lang;
using Nub.Lang.Frontend;
using Nub.Lang.Frontend.Generation;
@@ -105,40 +106,44 @@ foreach (var compilationUnit in compilationUnits)
catch (Exception ex)
{
Console.Error.WriteLine($"Error processing {sourceTexts[compilationUnit].Path}: {ex.Message}");
error = true;
return 1;
}
}
if (error)
{
return 1;
}
var assembly = Assembly.GetExecutingAssembly();
var runtimeResources = assembly.GetManifestResourceNames().Where(name => name.EndsWith(".s", StringComparison.OrdinalIgnoreCase));
const string RUNTIME_DIR = "src/runtime";
if (Directory.Exists(RUNTIME_DIR))
foreach (var resourceName in runtimeResources)
{
foreach (var runtimeFile in Directory.EnumerateFiles(RUNTIME_DIR, "*.s", SearchOption.AllDirectories))
{
try
{
var runtimeFileName = Path.GetFileNameWithoutExtension(runtimeFile);
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{runtimeFileName}.o");
await using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null)
{
Console.Error.WriteLine($"Warning: Could not load embedded resource {resourceName}");
continue;
}
await InvokeAssembler(runtimeFile, objPath);
using var reader = new StreamReader(stream);
var assemblyCode = await reader.ReadToEndAsync();
var fileName = resourceName.Split('.').Reverse().Skip(1).First();
var asmPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.s");
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.o");
await File.WriteAllTextAsync(asmPath, assemblyCode);
await InvokeAssembler(asmPath, objPath);
objectFiles.Add(objPath);
Console.Out.WriteLine($"Runtime assembled: {objPath}");
File.Delete(asmPath);
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error assembling runtime file {runtimeFile}: {ex.Message}");
error = true;
}
}
}
if (error)
{
Console.Error.WriteLine($"Error processing runtime resource {resourceName}: {ex.Message}");
return 1;
}
}
try
@@ -206,7 +211,7 @@ static async Task InvokeAssembler(string asmPath, string objPath)
if (asProcess.ExitCode != 0)
{
throw new Exception($"Assembler failed for {asmPath}:\n{asErrors}");
throw new Exception($"Assembler errors:\n{asErrors}");
}
}
@@ -230,6 +235,6 @@ static async Task InvokeLinker(List<string> objectFiles, string outputPath)
if (gccProcess.ExitCode != 0)
{
throw new Exception($"Linker failed:\n{gccErrors}");
throw new Exception($"Linker errors:\n{gccErrors}");
}
}

View File

@@ -1,11 +0,0 @@
.intel_syntax noprefix
.global core_syscall
.section .text
core_syscall:
mov rax, rdi
mov rdi, rsi
mov rsi, rdx
mov r10, rcx
syscall
ret