Build to Base64-based bytecode
BBBB
This commit is contained in:
parent
4d77edf65e
commit
7ccd4a14ac
5 changed files with 45 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -542,3 +542,5 @@ FodyWeavers.xsd
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/rider,visualbasic,visualstudio
|
# 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)
|
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
||||||
|
|
||||||
|
*.glb
|
||||||
|
|
32
CompileCommand.cs
Normal file
32
CompileCommand.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
await new CliApplicationBuilder()
|
await new CliApplicationBuilder()
|
||||||
.AddCommand<RunCommand>()
|
.AddCommand<RunCommand>()
|
||||||
|
.AddCommand<CompileCommand>()
|
||||||
.Build()
|
.Build()
|
||||||
.RunAsync();
|
.RunAsync();
|
||||||
|
|
|
@ -6,7 +6,7 @@ Glyph is a human-readable esoteric programming language that is designed to fit
|
||||||
|
|
||||||
- [x] Parser
|
- [x] Parser
|
||||||
|
|
||||||
- [ ] CLI tool
|
- [x] CLI tool
|
||||||
|
|
||||||
- [ ] Unicode support
|
- [ ] Unicode support
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ Glyph is a human-readable esoteric programming language that is designed to fit
|
||||||
|
|
||||||
- [ ] QR Code
|
- [ ] QR Code
|
||||||
|
|
||||||
- [ ] Base64
|
- [x] Base64
|
||||||
|
|
||||||
## 🧾 Program Structure
|
## 🧾 Program Structure
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,12 @@ public static class ScriptHelper
|
||||||
return returnValue;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue