Build to Base64-based bytecode

BBBB
This commit is contained in:
Tony Bark 2025-05-06 23:08:42 -04:00
parent 4d77edf65e
commit 7ccd4a14ac
5 changed files with 45 additions and 2 deletions

2
.gitignore vendored
View file

@ -542,3 +542,5 @@ FodyWeavers.xsd
# End of https://www.toptal.com/developers/gitignore/api/rider,visualbasic,visualstudio
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
*.glb

32
CompileCommand.cs Normal file
View file

@ -0,0 +1,32 @@
namespace Glyph;
[Command("build", Description = "Build Glyph program.")]
public class CompileCommand : ICommand
{
[CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")]
public string FilePath { get; set; }
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
public bool Verbose { get; set; }
public async ValueTask ExecuteAsync(IConsole console)
{
if (!System.IO.File.Exists(FilePath))
{
await console.Error.WriteLineAsync($"Error: File not found: {FilePath}");
return;
}
var lines = await System.IO.File.ReadAllLinesAsync(FilePath);
var source = ScriptHelper.LinesToString(lines);
if (Verbose)
{
await console.Output.WriteLineAsync($"Compiling: {FilePath}");
}
var binary = ScriptHelper.EncodeTo64(source);
File.WriteAllText(Path.Combine(Path.GetDirectoryName(FilePath), "output.glb"), binary);
}
}

View file

@ -1,4 +1,5 @@
await new CliApplicationBuilder()
.AddCommand<RunCommand>()
.AddCommand<CompileCommand>()
.Build()
.RunAsync();

View file

@ -6,7 +6,7 @@ Glyph is a human-readable esoteric programming language that is designed to fit
- [x] Parser
- [ ] CLI tool
- [x] CLI tool
- [ ] Unicode support
@ -14,7 +14,7 @@ Glyph is a human-readable esoteric programming language that is designed to fit
- [ ] QR Code
- [ ] Base64
- [x] Base64
## 🧾 Program Structure

View file

@ -15,4 +15,12 @@ public static class ScriptHelper
return returnValue;
}
/// <summary>
/// Converts an array of strings to a single string with each element separated by a newline.
/// </summary>
/// <param name="lines">The array of strings to convert.</param>
/// <returns>The resulting string.</returns>
static public string LinesToString(string[] lines) => string.Join(Environment.NewLine, lines);
}