Appearance
| 1 | namespace Semantic.DotNet is | |
| 2 | use Collections.LIST | |
| 3 | ||
| 4 | // What a REPL cell's assembly carries so the session hangs together: | |
| 5 | // the marker that makes it recognisable as a cell to the cells after | |
| 6 | // it, and, for each earlier cell it references, the attribute that | |
| 7 | // lets the runtime give it the access the compiler already allows. | |
| 8 | class SESSION_CELL_ATTRIBUTES is | |
| 9 | ACCESS_ATTRIBUTE_NAME: string static => "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute" | |
| 10 | ||
| 11 | gen(emitter: IR.Emitter.SRM_ASSEMBLY_EMITTER, submission_name: string?, assemblies: ASSEMBLIES) static is | |
| 12 | let string_type = IoC.CONTAINER.instance.innate_symbol_lookup.get_string_type() | |
| 13 | ||
| 14 | if let name = submission_name then | |
| 15 | emitter.add_named_attribute( | |
| 16 | emitter.assembly_handle, | |
| 17 | "System.Runtime", | |
| 18 | SESSION_CELL_MARKER.ATTRIBUTE_NAME, | |
| 19 | LIST[Types.Type]([string_type, string_type]), | |
| 20 | IR.Emitter.SRM_ATTRIBUTE_BLOB_ENCODER.encode_string_arguments( | |
| 21 | LIST[string]([SESSION_CELL_MARKER.KEY, name]))) | |
| 22 | fi | |
| 23 | ||
| 24 | let cells = assemblies.session_cell_names | |
| 25 | ||
| 26 | if cells.count == 0 then | |
| 27 | return | |
| 28 | fi | |
| 29 | ||
| 30 | // Declared by the runtime; one too old to declare it leaves | |
| 31 | // the cells to what the runtime allows without it. | |
| 32 | let access_type = assemblies.find_type(ACCESS_ATTRIBUTE_NAME) | |
| 33 | ||
| 34 | if !access_type? then | |
| 35 | return | |
| 36 | fi | |
| 37 | ||
| 38 | let access_assembly = access_type.assembly.get_name().name ?? "ghul-runtime" | |
| 39 | ||
| 40 | for cell in cells do | |
| 41 | emitter.add_named_attribute( | |
| 42 | emitter.assembly_handle, | |
| 43 | access_assembly, | |
| 44 | ACCESS_ATTRIBUTE_NAME, | |
| 45 | LIST[Types.Type]([string_type]), | |
| 46 | IR.Emitter.SRM_ATTRIBUTE_BLOB_ENCODER.encode_string_arguments(LIST[string]([cell]))) | |
| 47 | od | |
| 48 | si | |
| 49 | si | |
| 50 | si |