Appearance
| 1 | namespace IR.Program is | |
| 2 | use Semantic.Lookups.RuntimeException | |
| 3 | ||
| 4 | /// The classes a whole-program backend constructs or reads on the | |
| 5 | /// program's behalf, found through the innate symbol lookup, so each is | |
| 6 | /// the class the target's core library declares for it. | |
| 7 | class CORE_LIBRARY is | |
| 8 | /// The class of the exception compiled code throws for the failure | |
| 9 | /// `kind`, or null where the core library declares none. | |
| 10 | /// | |
| 11 | /// - kind: which failure | |
| 12 | exception_class(kind: RuntimeException) -> Semantic.Symbols.Classy? static => | |
| 13 | _classy(IoC.CONTAINER.instance.innate_symbol_lookup.find_runtime_exception_type(kind)) | |
| 14 | ||
| 15 | /// The root exception class, or null where the core library | |
| 16 | /// declares none. | |
| 17 | root_exception_class() -> Semantic.Symbols.Classy? static => | |
| 18 | _classy(IoC.CONTAINER.instance.innate_symbol_lookup.find_exception_type()) | |
| 19 | ||
| 20 | /// The type object class, or null where the core library declares | |
| 21 | /// none. | |
| 22 | type_class() -> Semantic.Symbols.Classy? static => | |
| 23 | _classy(IoC.CONTAINER.instance.innate_symbol_lookup.find_type_type()) | |
| 24 | ||
| 25 | /// The class the runtime's environment is, or null where the core | |
| 26 | /// library declares none. | |
| 27 | environment_class() -> Semantic.Symbols.Classy? static => | |
| 28 | _classy(IoC.CONTAINER.instance.innate_symbol_lookup.find_environment_type()) | |
| 29 | ||
| 30 | /// The constructor of `type` taking `arity` arguments, or null where | |
| 31 | /// it declares none. | |
| 32 | /// | |
| 33 | /// - type: the class, or null | |
| 34 | /// - arity: how many arguments the constructor takes | |
| 35 | constructor(type: Semantic.Symbols.Classy?, arity: int) -> Semantic.Symbols.Function? static is | |
| 36 | if let group = cast Semantic.Symbols.FUNCTION_GROUP?(type?.find_direct("init")) then | |
| 37 | for constructor in group.functions do | |
| 38 | if constructor.arguments.count == arity then | |
| 39 | return constructor | |
| 40 | fi | |
| 41 | od | |
| 42 | fi | |
| 43 | ||
| 44 | return null | |
| 45 | si | |
| 46 | ||
| 47 | /// The getter of the property `name` that `type` declares, or null | |
| 48 | /// where it declares no readable property of that name. | |
| 49 | find_getter(type: Semantic.Symbols.Classy, name: string) -> Semantic.Symbols.Function? static is | |
| 50 | if let property: Semantic.Symbols.Property = type.find_direct(name) then | |
| 51 | return property.read_function | |
| 52 | fi | |
| 53 | ||
| 54 | return null | |
| 55 | si | |
| 56 | ||
| 57 | _classy(type: Semantic.Types.Type?) -> Semantic.Symbols.Classy? static => | |
| 58 | cast Semantic.Symbols.Classy?(type?.symbol) | |
| 59 | si | |
| 60 | si |