Working on print
This commit is contained in:
@@ -63,55 +63,3 @@ Time :: (): F64
|
||||
Assert(err != 0)
|
||||
result := query->F64 / PerformanceFrequency
|
||||
return result
|
||||
|
||||
/**
|
||||
* C++ version 0.4 char* style "itoa":
|
||||
* Written by Lukás Chmela
|
||||
* Released under GPLv3.
|
||||
*/
|
||||
Itoa :: (value: S64, result: *U8, base: S64): *U8
|
||||
// check that the base if valid
|
||||
if (base < 2) || (base > 36)
|
||||
*result = 0 // '
|
||||
return result
|
||||
|
||||
ptr := result
|
||||
ptr1 := result
|
||||
tmp_char: U8
|
||||
tmp_value: S64
|
||||
|
||||
for value != 0
|
||||
tmp_value = value
|
||||
value /= base
|
||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]
|
||||
|
||||
// Apply negative sign
|
||||
if tmp_value < 0
|
||||
*ptr++ = '-'
|
||||
*ptr-- = 0
|
||||
for ptr1 < ptr
|
||||
tmp_char = *ptr
|
||||
*ptr-- = *ptr1
|
||||
*ptr1++ = tmp_char
|
||||
return result
|
||||
|
||||
|
||||
Print :: (string: String, args: ..)
|
||||
buffer: [1024]U8
|
||||
buffer_len: S64
|
||||
|
||||
arg_counter := 0
|
||||
for i := 0, i < Len(string), i+=1
|
||||
if string[i] == '%'
|
||||
Assert(arg_counter < Len(args), "Passing too many [%] to a print lambda")
|
||||
arg := args[arg_counter++]
|
||||
|
||||
if arg.type == S64
|
||||
value := *(arg.data->*S64)
|
||||
itoa_buff: [64]U8
|
||||
p := itoa(value, &itoa_buff[0], 10)
|
||||
for *p != 0
|
||||
buffer[buffer_len++] = *p++
|
||||
else;; Assert(false)
|
||||
else
|
||||
buffer[buffer_len++] = string[i]
|
||||
Reference in New Issue
Block a user