-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.cs
executable file
·53 lines (48 loc) · 1.77 KB
/
Console.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Expresso.Ast.Analysis;
using Expresso.CodeGen;
namespace Expresso.Terminal
{
class ExpressoMain
{
public static void Main(string[] args)
{
if(args.Length == 0){
Console.WriteLine(
@"Welcome to the Expresso Console!
I can read Expresso source files and compile them into assembly files that mono can execute.
But to run the executable, currently you have to first copy the runtime assemblies(Expresso.dll and ExpressoRuntime.dll).
Usage: mono exsc.exe source_file_name -o target_path -e executable_name
To execute the resulting binary: mono the_name_of_the_executable"
);
return;
}
var file_name = args[0];
var output_path = args[2];
var executable_name = args[4];
try{
var parser = new Parser(new Scanner(file_name));
parser.DoPostParseProcessing = true;
parser.Parse();
var ast = parser.TopmostAst;
var options = new ExpressoCompilerOptions{
OutputPath = output_path,
BuildType = BuildType.Debug | BuildType.Executable,
ExecutableName = executable_name
};
var generator = new CodeGenerator(parser, options);
ast.AcceptWalker(generator, null);
}
catch(ParserException){
// Ignore the exception because the parser already handled this case
//Console.Error.WriteLine(e);
}
catch(Exception e){
var prev_color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine(e.Message);
Console.ForegroundColor = prev_color;
}
}
}
}