diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-01-30 22:31:34 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-01-30 22:31:34 +0000 |
| commit | 34150385d8db82ab8de7eeba06c51a43ba59ec6e (patch) | |
| tree | 5ebdcf9aff9a029009999d5ed72e92727ebbdd6e /core | |
| parent | 0ca1b4612c35c649d16476aa67462835249145e8 (diff) | |
Change vector memory layout and operations; `for in` vector.
Diffstat (limited to 'core')
| -rw-r--r-- | core/_preload.odin | 4 | ||||
| -rw-r--r-- | core/fmt.odin | 35 |
2 files changed, 25 insertions, 14 deletions
diff --git a/core/_preload.odin b/core/_preload.odin index 76bea89ff..24c682c8d 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -70,6 +70,10 @@ Type_Info :: union { elem_size: int, count: int, }, + Dynamic_Array: struct #ordered { + elem: ^Type_Info, + elem_size: int, + }, Slice: struct #ordered { elem: ^Type_Info, elem_size: int, diff --git a/core/fmt.odin b/core/fmt.odin index 3d2b7ecc7..ac0e7caf1 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -173,6 +173,10 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) { fmt_int(^fi, cast(u64)info.count, false, 'd'); buffer_write_string(buf, "]"); buffer_write_type(buf, info.elem); + case Dynamic_Array: + buffer_write_string(buf, "[dynamic"); + buffer_write_string(buf, "]"); + buffer_write_type(buf, info.elem); case Slice: buffer_write_string(buf, "["); buffer_write_string(buf, "]"); @@ -792,6 +796,23 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { fmt_arg(fi, any{info.elem, cast(rawptr)data}, 'v'); } + case Dynamic_Array: + if verb != 'v' { + fmt_bad_verb(fi, verb); + return; + } + + buffer_write_byte(fi.buf, '['); + defer buffer_write_byte(fi.buf, ']'); + array := cast(^Raw_Dynamic_Array)v.data; + for i in 0..<array.count { + if i > 0 { + buffer_write_string(fi.buf, ", "); + } + data := cast(^byte)array.data + i*info.elem_size; + fmt_arg(fi, any{info.elem, cast(rawptr)data}, 'v'); + } + case Slice: if verb != 'v' { fmt_bad_verb(fi, verb); @@ -810,23 +831,9 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { } case Vector: - is_bool :: proc(type_info: ^Type_Info) -> bool { - match type info in type_info { - case Named: - return is_bool(info.base); - case Boolean: - return true; - } - return false; - } - buffer_write_byte(fi.buf, '<'); defer buffer_write_byte(fi.buf, '>'); - if is_bool(info.elem) { - return; - } - for i in 0..<info.count { if i > 0 { buffer_write_string(fi.buf, ", "); |