Begin to add support for header file generation
This commit is contained in:
@@ -5,10 +5,78 @@ using NubLang.Generation;
|
|||||||
using NubLang.Modules;
|
using NubLang.Modules;
|
||||||
using NubLang.Syntax;
|
using NubLang.Syntax;
|
||||||
|
|
||||||
var diagnostics = new List<Diagnostic>();
|
List<string> files = [];
|
||||||
|
List<string> headerFiles = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
if (args[i] == "-h")
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
if (i > args.Length - 1)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("Expected argument after -h");
|
||||||
|
}
|
||||||
|
|
||||||
|
headerFiles.Add(args[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
files.Add(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diagnostics = new List<Diagnostic>();
|
||||||
var syntaxTrees = new List<SyntaxTree>();
|
var syntaxTrees = new List<SyntaxTree>();
|
||||||
foreach (var file in args)
|
|
||||||
|
foreach (var headerFile in headerFiles)
|
||||||
|
{
|
||||||
|
using var bindingsGenerateProc = new Process();
|
||||||
|
// todo(nub31): Embed python file to remove absolute path
|
||||||
|
bindingsGenerateProc.StartInfo = new ProcessStartInfo("python3", ["/home/oliste/repos/nub-lang/bindings/generate.py", headerFile])
|
||||||
|
{
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
bindingsGenerateProc.Start();
|
||||||
|
|
||||||
|
var output = await bindingsGenerateProc.StandardOutput.ReadToEndAsync();
|
||||||
|
var error = await bindingsGenerateProc.StandardError.ReadToEndAsync();
|
||||||
|
|
||||||
|
await bindingsGenerateProc.WaitForExitAsync();
|
||||||
|
|
||||||
|
if (bindingsGenerateProc.ExitCode != 0)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Failed to automatically generate bindings for header file {headerFile}\n{error}");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tokenizer = new Tokenizer(headerFile, output);
|
||||||
|
tokenizer.Tokenize();
|
||||||
|
diagnostics.AddRange(tokenizer.Diagnostics);
|
||||||
|
|
||||||
|
if (tokenizer.Diagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Binding generator produced invalid syntax for header file {headerFile}");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parser = new Parser();
|
||||||
|
var syntaxTree = parser.Parse(tokenizer.Tokens);
|
||||||
|
|
||||||
|
if (parser.Diagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Binding generator produced invalid syntax tree for header file {headerFile}");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
syntaxTrees.Add(syntaxTree);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
var tokenizer = new Tokenizer(file, File.ReadAllText(file));
|
var tokenizer = new Tokenizer(file, File.ReadAllText(file));
|
||||||
tokenizer.Tokenize();
|
tokenizer.Tokenize();
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ NUBC = ../../compiler/NubLang.CLI/bin/Debug/net9.0/nubc
|
|||||||
out: .build/out.o
|
out: .build/out.o
|
||||||
gcc -nostartfiles -lm -o out x86_64.s .build/out.o raylib-5.5_linux_amd64/lib/libraylib.a
|
gcc -nostartfiles -lm -o out x86_64.s .build/out.o raylib-5.5_linux_amd64/lib/libraylib.a
|
||||||
|
|
||||||
.build/out.o: $(NUBC) main.nub raylib.nub
|
# .build/out.o: $(NUBC) main.nub raylib.nub
|
||||||
$(NUBC) main.nub raylib.nub
|
# $(NUBC) main.nub raylib.nub
|
||||||
|
|
||||||
|
.build/out.o: $(NUBC) main.nub
|
||||||
|
$(NUBC) main.nub -h raylib-5.5_linux_amd64/include/raylib.h
|
||||||
|
|
||||||
.PHONY: $(NUBC)
|
.PHONY: $(NUBC)
|
||||||
$(NUBC):
|
$(NUBC):
|
||||||
|
|||||||
Reference in New Issue
Block a user