Skip to content
← Back

src/ir/boilerplate_generator.ghul

1
namespace IR is
2
use IO.File;
3
4
class BOILERPLATE_GENERATOR(_context: CONTEXT, _paths: Driver.PATH_CONFIG) is
5
_snippets: Collections.MAP[string,string];
6
7
init(..) is
8
_snippets = Collections.MAP[string,string]();
9
si
10
11
gen(name: string) is
12
gen(name, null);
13
si
14
15
gen(name: string, args: Collections.Iterable[string]?) is
16
let snippet: string mut;
17
18
if !_snippets.contains_key(name) then
19
// FIXME use path concatenation
20
snippet = File.read_all_text("{_paths.library_prefix}dotnet/il//{name}.il");
21
22
_snippets[name] = snippet;
23
else
24
snippet = _snippets[name];
25
fi
26
27
if args? then
28
let index mut = 0;
29
for a in args do
30
// this is e.g. replace('${0}') after the escapes and interpolation:
31
snippet = snippet.replace("${{{index}}}", a);
32
33
index = index + 1;
34
od
35
fi
36
37
_context.write_line(snippet);
38
si
39
si
40
si