@@ -14,7 +14,7 @@ import std.ops (
1414 ShiftRight, Subtract, UnsignedShiftRight,
1515)
1616import std.range (ExclusiveRange, InclusiveRange)
17- import std.string (ToString)
17+ import std.string (PrimitiveString, ToString)
1818
1919fn extern inko_int_checked_pow(left: Int, right: Int) -> CheckedIntResult
2020
@@ -74,6 +74,74 @@ type pub copy enum Format {
7474 }
7575}
7676
77+ type extern Buffer {
78+ let @0: Uint8
79+ let @1: Uint8
80+ let @2: Uint8
81+ let @3: Uint8
82+ let @4: Uint8
83+ let @5: Uint8
84+ let @6: Uint8
85+ let @7: Uint8
86+ let @8: Uint8
87+ let @9: Uint8
88+ let @10: Uint8
89+ let @11: Uint8
90+ let @12: Uint8
91+ let @13: Uint8
92+ let @14: Uint8
93+ let @15: Uint8
94+ let @16: Uint8
95+ let @17: Uint8
96+ let @18: Uint8
97+ let @19: Uint8
98+ let @20: Uint8
99+ let @21: Uint8
100+ let @22: Uint8
101+ let @23: Uint8
102+ let @24: Uint8
103+ let @25: Uint8
104+ let @26: Uint8
105+ let @27: Uint8
106+ let @28: Uint8
107+ let @29: Uint8
108+ let @30: Uint8
109+ let @31: Uint8
110+ let @32: Uint8
111+ let @33: Uint8
112+ let @34: Uint8
113+ let @35: Uint8
114+ let @36: Uint8
115+ let @37: Uint8
116+ let @38: Uint8
117+ let @39: Uint8
118+ let @40: Uint8
119+ let @41: Uint8
120+ let @42: Uint8
121+ let @43: Uint8
122+ let @44: Uint8
123+ let @45: Uint8
124+ let @46: Uint8
125+ let @47: Uint8
126+ let @48: Uint8
127+ let @49: Uint8
128+ let @50: Uint8
129+ let @51: Uint8
130+ let @52: Uint8
131+ let @53: Uint8
132+ let @54: Uint8
133+ let @55: Uint8
134+ let @56: Uint8
135+ let @57: Uint8
136+ let @58: Uint8
137+ let @59: Uint8
138+ let @60: Uint8
139+ let @61: Uint8
140+ let @62: Uint8
141+ let @63: Uint8
142+ let @64: Uint8
143+ }
144+
77145# A 64-bits signed integer type.
78146#
79147# `Int` values can represent values in the range
@@ -266,6 +334,50 @@ type builtin Int {
266334 bytes.into_string
267335 }
268336
337+ # TODO
338+ fn pub format_fast(format: Format) -> String {
339+ let base = format.to_base
340+
341+ match self {
342+ case 0 -> return '0'
343+ # MIN can't be turned positive using absolute(), so we have to handle
344+ # these cases explicitly.
345+ case MIN if base == 2 -> {
346+ return '-1000000000000000000000000000000000000000000000000000000000000000'
347+ }
348+ case MIN if base == 10 -> return '-9223372036854775808'
349+ case MIN if base == 16 -> return '-8000000000000000'
350+ case _ -> {}
351+ }
352+
353+ let alphabet = '0123456789abcdef'
354+ let bytes = Buffer()
355+ let mut int = absolute
356+ let mut idx = 64
357+ let mut len = 1
358+
359+ while int > 0 {
360+ let ptr = (mut bytes) as Int + idx as Pointer[Uint8]
361+
362+ ptr.0 = alphabet.get(int % base).or_panic as Uint8
363+ int /= base
364+ len += 1
365+ idx -= 1
366+ }
367+
368+ if self < 0 {
369+ len += 1
370+ ((mut bytes) as Int + idx as Pointer[Uint8]).0 = 0x2D as Uint8
371+ }
372+
373+ String.from_borrowed_primitive(
374+ PrimitiveString(
375+ bytes: (mut bytes) as Int + idx as Pointer[Uint8],
376+ size: len,
377+ ),
378+ )
379+ }
380+
269381 # Calls the supplied closure `self` times.
270382 #
271383 # # Examples
0 commit comments