diff options
| author | gingerBill <bill@gingerbill.org> | 2018-02-28 11:20:11 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-02-28 11:20:11 +0000 |
| commit | d3ea334e7ab2897bbc948acc57aa9ba073304215 (patch) | |
| tree | 8f6016ab7bd62c0320c893e0cb7fa6337054420f /core/_preload.odin | |
| parent | 223c473cf64845f0c0824375fa98ca51bad66fc1 (diff) | |
`cstring`
Diffstat (limited to 'core/_preload.odin')
| -rw-r--r-- | core/_preload.odin | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/core/_preload.odin b/core/_preload.odin index 03a29b5b7..2e29ecaa8 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -41,15 +41,15 @@ Type_Info_Enum_Value :: union { }; // Variant Types -Type_Info_Named :: struct {name: string, base: ^Type_Info}; -Type_Info_Integer :: struct {signed: bool}; -Type_Info_Rune :: struct{}; -Type_Info_Float :: struct{}; -Type_Info_Complex :: struct{}; -Type_Info_String :: struct{}; -Type_Info_Boolean :: struct{}; -Type_Info_Any :: struct{}; -Type_Info_Pointer :: struct { +Type_Info_Named :: struct {name: string, base: ^Type_Info}; +Type_Info_Integer :: struct {signed: bool}; +Type_Info_Rune :: struct {}; +Type_Info_Float :: struct {}; +Type_Info_Complex :: struct {}; +Type_Info_String :: struct {is_cstring: bool}; +Type_Info_Boolean :: struct {}; +Type_Info_Any :: struct {}; +Type_Info_Pointer :: struct { elem: ^Type_Info // nil -> rawptr }; Type_Info_Procedure :: struct { @@ -863,6 +863,20 @@ __string_gt :: inline proc "contextless" (a, b: string) -> bool { return __strin __string_le :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) <= 0; } __string_ge :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) >= 0; } +__cstring_len :: proc "contextless" (s: cstring) -> int { + n := 0; + for p := (^byte)(s); p != nil && p^ != 0; p += 1 { + n += 1; + } + return n; +} + +__cstring_to_string :: proc "contextless" (s: cstring) -> string { + ptr := (^byte)(s); + n := __cstring_len(s); + return transmute(string)raw.String{ptr, n}; +} + __complex64_eq :: inline proc "contextless" (a, b: complex64) -> bool { return real(a) == real(b) && imag(a) == imag(b); } __complex64_ne :: inline proc "contextless" (a, b: complex64) -> bool { return real(a) != real(b) || imag(a) != imag(b); } |