static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: kecaknoah <input file>");
return;
}
var txt = File.ReadAllText(args[0]);
var lexer = new KecaknoahLexer();
var parser = new KecaknoahParser();
var lr = lexer.AnalyzeFromSource(txt);
if (!lr.Success)
{
Console.WriteLine($"字句解析エラー ({lr.Error.Column}, {lr.Error.Line}): {lr.Error.Message}");
Console.ReadLine();
return;
}
var ast = parser.Parse(lr);
if (!ast.Success)
{
Console.WriteLine($"構文解析エラー ({ast.Error.Column}, {ast.Error.Line}): {ast.Error.Message}");
Console.ReadLine();
}
var prc = new KecaknoahPrecompiler();
var src = prc.PrecompileAll(ast);
var environment = new KecaknoahEnvironment();
var module = environment.CreateModule("Main");
module.RegisterSource(src);
var ctx = module.CreateContext();
var il = module["main"];
var kargs = new List<KecaknoahString>();
if (args.Length > 2)
{
kargs.AddRange(args.Skip(1).Select(p => p.AsKecaknoahString()));
}
if (il != KecaknoahNil.Instance) ctx.Execute(il, kargs.ToArray());
/*
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 10; i++)
{
ctx.Execute(il);
}
sw.Stop();
Console.WriteLine($"{sw.ElapsedMilliseconds}");
*/
var asm = AssembleSource(src);
File.WriteAllLines(args[0] + ".asm", asm);
Console.ReadLine();
}