Skip to content
← Back

src/ir/emitter/cil_assembly_attributes.ghul

1
@@IF.dotnet()
2
3
namespace IR.Emitter is
4
use Collections.LIST
5
6
use Semantic.Types.Type
7
8
// The custom attributes the assembly itself carries.
9
class CIL_ASSEMBLY_ATTRIBUTES is
10
init() is si
11
12
// Each attribute requested for the assembly that matched a
13
// constructor taking only strings.
14
gen_requested(emitter: SRM_ASSEMBLY_EMITTER, info: Semantic.DotNet.ASSEMBLY_INFO) static is
15
let string_type = IoC.CONTAINER.instance.innate_symbol_lookup.get_string_type()
16
17
for attribute in info.resolved do
18
let argument_types = LIST[Type]()
19
20
for _ in attribute.arguments do
21
argument_types.add(string_type)
22
od
23
24
emitter.add_named_attribute(
25
emitter.assembly_handle,
26
attribute.assembly_name,
27
attribute.name,
28
argument_types,
29
SRM_ATTRIBUTE_BLOB_ENCODER.encode_string_arguments(attribute.arguments))
30
od
31
si
32
33
// What a REPL cell's assembly carries so the session hangs
34
// together: the marker that makes it recognisable as a cell to the
35
// cells after it, and, for each earlier cell it references, the
36
// attribute that lets the runtime give it the access the compiler
37
// already allows.
38
gen_session_cell(
39
emitter: SRM_ASSEMBLY_EMITTER,
40
submission_name: string?,
41
assemblies: Semantic.DotNet.ASSEMBLIES
42
) static is
43
let string_type = IoC.CONTAINER.instance.innate_symbol_lookup.get_string_type()
44
45
if let name = submission_name then
46
emitter.add_named_attribute(
47
emitter.assembly_handle,
48
"System.Runtime",
49
Semantic.DotNet.SESSION_CELL_MARKER.ATTRIBUTE_NAME,
50
LIST[Type]([string_type, string_type]),
51
SRM_ATTRIBUTE_BLOB_ENCODER.encode_string_arguments(
52
LIST[string]([Semantic.DotNet.SESSION_CELL_MARKER.KEY, name])))
53
fi
54
55
let cells = assemblies.session_cell_names
56
57
if cells.count == 0 then
58
return
59
fi
60
61
let access_attribute_name = Semantic.DotNet.SESSION_CELL_ATTRIBUTES.ACCESS_ATTRIBUTE_NAME
62
63
// Declared by the runtime; one too old to declare it leaves
64
// the cells to what the runtime allows without it.
65
let access_type = assemblies.find_type(access_attribute_name)
66
67
if !access_type? then
68
return
69
fi
70
71
let access_assembly = access_type.assembly.get_name().name ?? "ghul-runtime"
72
73
for cell in cells do
74
emitter.add_named_attribute(
75
emitter.assembly_handle,
76
access_assembly,
77
access_attribute_name,
78
LIST[Type]([string_type]),
79
SRM_ATTRIBUTE_BLOB_ENCODER.encode_string_arguments(LIST[string]([cell])))
80
od
81
si
82
si
83
si