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 | let body = context.current_srm_body_emitter! | |
| 18 | body.ldstr(context.srm_assembly_emitter, value) | |
| 19 | si | |
| 20 | ||
| 21 | get_hex_bytes(value: string) -> string static is | |
| 22 | let result = System.Text.StringBuilder(value.length * 8) | |
| 23 | ||
| 24 | for c in value do | |
| 25 | let uc = cast uint(c) | |
| 26 | ||
| 27 | let high = uc / cast uint(256) | |
| 28 | let low = uc - (high * cast uint(256)) | |
| 29 | ||
| 30 | result | |
| 31 | .append(low.to_string("X02")) | |
| 32 | .append(" ") | |
| 33 | .append(high.to_string("X02")) | |
| 34 | .append(" ") | |
| 35 | od | |
| 36 | ||
| 37 | return result.to_string() | |
| 38 | si | |
| 39 | ||
| 40 | to_string() -> string => | |
| 41 | "literal:[{type}](\"{value}\")" | |
| 42 | si | |
| 43 | si |