Skip to content
← Back

src/semantic/intrinsics_namespace.ghul

1
namespace Semantic is
2
use Source.LOCATION
3
4
// Materialises `Ghul.Intrinsics` before any pass runs, so the
5
// ambient `use` every namespace block carries resolves against a
6
// namespace that already exists rather than one something else has
7
// to create in time. Where the reference set or the compilation's
8
// own sources provide it, this changes nothing; only a compilation
9
// where nothing else does — no assemblies, or none carrying the
10
// namespace — gets one here. On .NET the assembly import adds to it
11
// rather than creating it; under a target that loads no assemblies,
12
// the built-in types are declared into it directly. Runs again
13
// after clear_symbols, which drops the namespace symbols with
14
// everything else.
15
class INTRINSICS_NAMESPACE is
16
materialise(symbol_table: SYMBOL_TABLE, namespaces: NAMESPACES) static is
17
let global =
18
cast Symbols.NAMESPACE?(symbol_table.global_scope)
19
20
if !global? then
21
return
22
fi
23
24
let ghul = namespaces.find_or_add_namespace("Ghul", ".Ghul", false)
25
26
if global.find_direct("Ghul") == null then
27
global.declare_namespace(LOCATION.internal, "Ghul", ghul, null)
28
fi
29
30
// Enter Ghul while creating Intrinsics, so the nested
31
// namespace's enclosing scope is its parent — the chain a
32
// name resolved inside it walks up is Ghul.Intrinsics ->
33
// Ghul -> global, the same chain a source declaration of
34
// the pair produces.
35
let mark = symbol_table.mark_scope_stack()
36
37
symbol_table.enter_scope(ghul)
38
39
let intrinsics = namespaces.find_or_add_namespace("Intrinsics", ".Ghul.Intrinsics", false)
40
41
if ghul.find_direct("Intrinsics") == null then
42
ghul.declare_namespace(LOCATION.internal, "Intrinsics", intrinsics, null)
43
fi
44
45
symbol_table.release_scope_stack(mark)
46
47
intrinsics.mark_implicitly_imported()
48
si
49
si
50
si