Repository navigation
Expand file tree
/
Copy pathConsoleHost.fu
More file actions
106 lines (98 loc) · 3.04 KB
/
Copy pathConsoleHost.fu
File metadata and controls
106 lines (98 loc) · 3.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ConsoleHost.fu - Fusion transpiler CLI
//
// Copyright (C) 2023-2026 Piotr Fusik
//
// This file is part of Fusion Transpiler,
// see https://github.com/fusionlanguage/fut
//
// Fusion Transpiler is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Fusion Transpiler is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Fusion Transpiler. If not, see http://www.gnu.org/licenses/
public abstract class FuConsoleHost : GenHost
{
public const string Version = "3.3.9";
public static void Usage(string app)
{
Console.WriteLine($"Usage: {app} [OPTIONS] -o FILE INPUT.fu");
Console.WriteLine("Options:");
Console.WriteLine("-o FILE Write to the specified file, extension determines language");
Console.WriteLine("-n NAME Specify C++/C# namespace, Java package or C name prefix");
Console.WriteLine("-D NAME Define conditional compilation symbol");
Console.WriteLine("-r FILE.fu Read the specified source file but don't emit code for it");
Console.WriteLine("-I DIR Add directory to resource search path");
Console.WriteLine("-l LANG Set target language explicitly:");
Console.WriteLine(" c, cpp, cs, d, java, js, py, swift, ts, d.ts, cl");
Console.WriteLine("--help Display this information");
Console.WriteLine("--version Display version information");
}
bool Errors = false;
public bool HasErrors() => this.Errors;
public void SetErrors!(bool value)
{
this.Errors = value;
}
public override void ReportError!(string filename, int line, int startUtf16Column, int endUtf16Column, string message)
{
this.Errors = true;
Console.Error.WriteLine($"{filename}({line + 1}): ERROR: {message}");
}
protected abstract string ToDirectory!(string path);
public void Emit!(FuProgram program, string lang, string namespace_, string outputFile)
{
GenBase# gen;
switch (lang) {
case "c":
gen = new GenC();
break;
case "cpp":
gen = new GenCpp();
break;
case "cs":
gen = new GenCs();
break;
case "d":
gen = new GenD();
break;
case "java":
gen = new GenJava();
outputFile = ToDirectory(outputFile);
break;
case "js":
case "mjs":
gen = new GenJs();
break;
case "py":
gen = new GenPy();
break;
case "swift":
gen = new GenSwift();
break;
case "ts":
GenTs# genTs = new GenTs();
genTs.WithGenFullCode();
gen = genTs;
break;
case "d.ts":
gen = new GenTs();
break;
case "cl":
gen = new GenCl();
break;
default:
Console.Error.WriteLine($"fut: ERROR: Unknown language: {lang}");
SetErrors(true);
return;
}
gen.SetHost(this);
gen.WriteProgram(program, outputFile, namespace_);
}
}