Appearance
| 1 | namespace IR.Values is | |
| 2 | use Semantic.Types.Type; | |
| 3 | ||
| 4 | // Wrap a value-type T in its value-type optional form NULLABLE[T] (= | |
| 5 | // System.Nullable[T]). Emits the Nullable<T>::.ctor(T) call IL. | |
| 6 | // Counterpart to BOX (T → object) at value-meets-slot boundaries — | |
| 7 | // used by VALUE_BOXER.wrap_if_needed when an implicit conversion | |
| 8 | // from T to T? is required. | |
| 9 | class WRAP_OPTIONAL: Value is | |
| 10 | value: Value; | |
| 11 | _optional_type: Type; | |
| 12 | type: Type => _optional_type; | |
| 13 | is_value_type: bool => true; | |
| 14 | ||
| 15 | init( | |
| 16 | optional_type: Type, | |
| 17 | value: Value | |
| 18 | ) is | |
| 19 | super.init(); | |
| 20 | ||
| 21 | self._optional_type = optional_type; | |
| 22 | self.value = value; | |
| 23 | si | |
| 24 | ||
| 25 | gen(context: IR.CONTEXT) is | |
| 26 | gen(value, context); | |
| 27 | ||
| 28 | let buffer = System.Text.StringBuilder(); | |
| 29 | buffer.append("newobj instance void "); | |
| 30 | _optional_type.gen_type(buffer); | |
| 31 | buffer.append("::.ctor(!0)"); | |
| 32 | ||
| 33 | context.write_line(buffer.to_string()); | |
| 34 | si | |
| 35 | ||
| 36 | to_string() -> string => | |
| 37 | "wrap-optional:[{_optional_type}]({value})"; | |
| 38 | si | |
| 39 | si |