CLI tool
- Preemptive support for binary file execution
This commit is contained in:
parent
ae16966edf
commit
4d77edf65e
9 changed files with 121 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -542,5 +542,3 @@ 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)
|
||||
|
||||
*.glyph
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
global using Glyph;
|
||||
global using CliFx;
|
||||
global using CliFx.Attributes;
|
||||
global using CliFx.Infrastructure;
|
||||
global using System.IO;
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AssemblyName>glyph</AssemblyName>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.1.100</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliFx" Version="2.3.5" />
|
||||
<PackageReference Include="DynamicExpresso.Core" Version="2.19.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
14
Program.cs
14
Program.cs
|
@ -1,10 +1,4 @@
|
|||
string[] code = new[]
|
||||
{
|
||||
"# Skip this line",
|
||||
"set x 5",
|
||||
"mul x 2",
|
||||
"say x",
|
||||
"end"
|
||||
};
|
||||
|
||||
Runner.Interpret(code);
|
||||
await new CliApplicationBuilder()
|
||||
.AddCommand<RunCommand>()
|
||||
.Build()
|
||||
.RunAsync();
|
||||
|
|
32
README.md
32
README.md
|
@ -44,6 +44,36 @@ verb subject object [modifier]
|
|||
| `mod` | modulo | `mod x 5` |
|
||||
| `end` | stop execution | `end` |
|
||||
|
||||
## 📜 License
|
||||
## 🧩 Tech Stack
|
||||
|
||||
- .NET 8.0
|
||||
- Dynamic Expresso for interpreter
|
||||
|
||||
## 🗓️ Update Cycle
|
||||
|
||||
| Type | Frequency | Notes |
|
||||
| ------------ | ---------------- | ---------------------------------------- |
|
||||
| Minor Update | Every 3–6 months | Small enhancements, non-breaking changes |
|
||||
| Patch Update | As needed | Bug fixes, security updates |
|
||||
| Major Update | As needed | Framework upgrades, major refactors |
|
||||
|
||||
- Reserve months: June (Mid-Year Chill) & December (End-Year Freeze)
|
||||
|
||||
## 🛡️ Status
|
||||
|
||||
- [x] Active Support
|
||||
- [ ] Limited Support (Security patches only)
|
||||
- [ ] Maintenance Mode (Dependency-only updates)
|
||||
- [ ] Archived (No active work planned)
|
||||
|
||||
## 🎮 Relaxation Practices
|
||||
|
||||
- 20% creative/recovery space built into development
|
||||
- Mandatory cooldowns after major launches (minimum 1 week)
|
||||
- Crisis Mode Activates if:
|
||||
- Critical vulnerabilities
|
||||
- Framework-breaking issues
|
||||
|
||||
## 🗒️ License
|
||||
|
||||
I license this project under the GPL v3 license - see [LICENSE](LICENSE) for details.
|
||||
|
|
51
RunCommand.cs
Normal file
51
RunCommand.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
namespace Glyph;
|
||||
|
||||
[Command("run", Description = "Run a Glyph program.")]
|
||||
public class RunCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")]
|
||||
public string FilePath { get; set; }
|
||||
|
||||
[CommandOption("input", 'i', Description = "Path to optional input file.")]
|
||||
public string InputPath { get; set; }
|
||||
|
||||
[CommandOption("binary", 'b', Description = "Run binary file")]
|
||||
public bool Binary { get; set; }
|
||||
|
||||
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
|
||||
public bool Verbose { get; set; }
|
||||
|
||||
public async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
var lines = new string[] { };
|
||||
|
||||
if (!System.IO.File.Exists(FilePath))
|
||||
{
|
||||
await console.Error.WriteLineAsync($"Error: File not found: {FilePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Binary)
|
||||
{
|
||||
// TODO: Implement binary file execution
|
||||
await console.Error.WriteLineAsync($"Error: Binary file execution not implemented");
|
||||
return;
|
||||
}
|
||||
|
||||
lines = await System.IO.File.ReadAllLinesAsync(FilePath);
|
||||
|
||||
if (!string.IsNullOrEmpty(InputPath))
|
||||
{
|
||||
// You could inject input to the interpreter here
|
||||
string input = await File.ReadAllTextAsync(InputPath);
|
||||
// TODO: Attach to interpreter input stream
|
||||
}
|
||||
|
||||
if (Verbose)
|
||||
{
|
||||
await console.Output.WriteLineAsync($"Executing: {FilePath}");
|
||||
}
|
||||
|
||||
Runner.Interpret(lines);
|
||||
}
|
||||
}
|
14
Runner.cs
14
Runner.cs
|
@ -8,8 +8,8 @@ public static class Runner
|
|||
{
|
||||
var env = new Dictionary<string, object>();
|
||||
var labels = new Dictionary<string, int>();
|
||||
var callStack = new Stack<int>();
|
||||
var interpreter = new Interpreter();
|
||||
var stack = new Stack<int>();
|
||||
var exp = new Interpreter();
|
||||
int pc = 0;
|
||||
|
||||
// First pass: record labels
|
||||
|
@ -40,8 +40,8 @@ public static class Runner
|
|||
object Eval(string expr)
|
||||
{
|
||||
foreach (var (k, v) in env)
|
||||
interpreter.SetVariable(k, v);
|
||||
return interpreter.Eval(expr);
|
||||
exp.SetVariable(k, v);
|
||||
return exp.Eval(expr);
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
|
@ -101,7 +101,7 @@ public static class Runner
|
|||
case "call":
|
||||
if (arg1 != null && labels.TryGetValue(arg1, out var fnStart))
|
||||
{
|
||||
callStack.Push(pc);
|
||||
stack.Push(pc);
|
||||
pc = fnStart + 1;
|
||||
if (arg2 != null)
|
||||
env["x"] = Eval(arg2);
|
||||
|
@ -109,8 +109,8 @@ public static class Runner
|
|||
break;
|
||||
|
||||
case "ret":
|
||||
if (callStack.Count > 0)
|
||||
pc = callStack.Pop();
|
||||
if (stack.Count > 0)
|
||||
pc = stack.Pop();
|
||||
else
|
||||
return;
|
||||
break;
|
||||
|
|
18
ScriptHelper.cs
Normal file
18
ScriptHelper.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace Glyph;
|
||||
|
||||
public static class ScriptHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Encodes a string to Base64.
|
||||
/// </summary>
|
||||
/// <param name="toEncode">The string to encode.</param>
|
||||
/// <returns>The Base64 encoded string.</returns>
|
||||
// https://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/
|
||||
static public string EncodeTo64(string toEncode)
|
||||
{
|
||||
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
|
||||
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
|
||||
return returnValue;
|
||||
|
||||
}
|
||||
}
|
4
sample.glif
Normal file
4
sample.glif
Normal file
|
@ -0,0 +1,4 @@
|
|||
set x 5
|
||||
mul x 2
|
||||
say x
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue