Appearance
| 1 | namespace IR.Values.Literal is | |
| 2 | use TypeTyped = Semantic.Types.Typed; | |
| 3 | use Semantic.Types.Type; | |
| 4 | ||
| 5 | class STRING: Value, TypeTyped is | |
| 6 | value: string; | |
| 7 | type: Type; | |
| 8 | ||
| 9 | init(value: string, type: Type) is | |
| 10 | super.init(); | |
| 11 | ||
| 12 | self.value = value; | |
| 13 | self.type = type; | |
| 14 | si | |
| 15 | ||
| 16 | gen(context: IR.CONTEXT) is | |
| 17 | context.write_line("ldstr bytearray ({get_hex_bytes(value)})"); | |
| 18 | si | |
| 19 | ||
| 20 | get_hex_bytes(value: string) -> string static is | |
| 21 | let result = System.Text.StringBuilder(value.length * 8); | |
| 22 | ||
| 23 | for c in value do | |
| 24 | let uc = cast uint(c); | |
| 25 | ||
| 26 | let high = uc / cast uint(256); | |
| 27 | let low = uc - (high * cast uint(256)); | |
| 28 | ||
| 29 | result | |
| 30 | .append(low.to_string("X02")) | |
| 31 | .append(" ") | |
| 32 | .append(high.to_string("X02")) | |
| 33 | .append(" "); | |
| 34 | od | |
| 35 | ||
| 36 | return result.to_string(); | |
| 37 | si | |
| 38 | ||
| 39 | to_string() -> string => | |
| 40 | "literal:[{type}](\"{value}\")"; | |
| 41 | si | |
| 42 | si |