Skip to content

Instantly share code, notes, and snippets.

@stdray
Created November 20, 2013 21:02
Show Gist options
  • Save stdray/7570962 to your computer and use it in GitHub Desktop.
Save stdray/7570962 to your computer and use it in GitHub Desktop.
using Nemerle.Collections;
using Nemerle.Extensions;
using Nemerle.Compiler;
using System.Console;
using Nemerle.Text;
using Nemerle.Utility;
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
module Program
{
Main() : void
{
def file = FileInfo(@"C:\temp\HelloWorld.n");
def options = CompilationOptions() <- {
IgnoreConfusion = true;
CompileToMemory = true;
};
options.Sources = [FileSource(file.FullName, options.Warnings)];
def manager = ManagerClass(options) <- {
InitOutput(Console.Out);
MessageOccured += (_, msg) => Console.WriteLine(msg);
ErrorOccured += (_, msg) => Console.WriteLine(msg);
};
def compile()
{
try
manager.Run();
catch
{
| _ is Recovery => ()
| e => Console.WriteLine(e);
}
}
_ = Task.Run(compile).ContinueWith(_ => {
def assembly = manager.GeneratedAssembly;
def entryPoint = assembly.GetTypes()
.Select(t => t.GetMethod("Main", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
.FirstOrDefault(_ != null);
def parms = match (entryPoint.GetParameters().Length)
{
| 0 => array(0)
| 1 => array[array(0) : array[string]]
| i => throw ArgumentException($"Invalid Main args count $i");
}
_ = entryPoint.Invoke(null, parms);
});
_ = ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment